Skip to content

Commit

Permalink
🐛 Refresh tags automatically when command is ran
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-MX committed Sep 29, 2024
1 parent 17083a3 commit 677c127
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,9 @@ tasks {
downloadPlugins {
hangar("ViaVersion", "5.0.1")
hangar("ViaBackwards", "5.0.1")
hangar("PlaceholderAPI", "2.11.6")

// For testing groups in config.yml
url("https://download.luckperms.net/1556/bukkit/loader/LuckPerms-Bukkit-5.4.141.jar")

// For testing TAB hook
github("NEZNAMY", "TAB", "4.1.8", "TAB.v4.1.8.jar")
}
}
}
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/com/mattmx/nametags/NameTagsCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.mattmx.nametags;

import com.mattmx.nametags.entity.NameTagEntity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public class NameTagsCommand implements CommandExecutor {
private final @NotNull NameTags plugin;

Expand All @@ -16,7 +22,24 @@ public NameTagsCommand(@NotNull NameTags plugin) {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
this.plugin.reloadConfig();
sender.sendMessage(Component.text("Reloaded!"));

for (final Player player : Bukkit.getOnlinePlayers()) {
final NameTagEntity tag = plugin.getEntityManager().removeEntity(player);

if (tag == null) continue;

tag.destroy();

final NameTagEntity newTag = plugin.getEntityManager().getOrCreateNameTagEntity(player);

for (final UUID viewer : tag.getPassenger().getViewers()) {
newTag.getPassenger().addViewer(viewer);
}

newTag.updateVisibility();
}

sender.sendMessage(Component.text("Reloaded!").color(NamedTextColor.GREEN));
return false;
}
}

0 comments on commit 677c127

Please sign in to comment.