From 3257e870d5f9458e15e404a41d4bb943aeee6395 Mon Sep 17 00:00:00 2001 From: Auracle Date: Sun, 1 Aug 2021 15:59:34 -0400 Subject: [PATCH] Update v2, now actively remove the name tag when enabled --- NoNameTag/src/ca/fastis/NoNameTag.java | 44 ----------------------- src/auracle/NoNameTag.java | 49 ++++++++++++++++++++++++++ {NoNameTag => src}/plugin.yml | 8 ++--- 3 files changed, 53 insertions(+), 48 deletions(-) delete mode 100644 NoNameTag/src/ca/fastis/NoNameTag.java create mode 100644 src/auracle/NoNameTag.java rename {NoNameTag => src}/plugin.yml (53%) diff --git a/NoNameTag/src/ca/fastis/NoNameTag.java b/NoNameTag/src/ca/fastis/NoNameTag.java deleted file mode 100644 index 67e615c..0000000 --- a/NoNameTag/src/ca/fastis/NoNameTag.java +++ /dev/null @@ -1,44 +0,0 @@ -package ca.fastis; - - -import org.bukkit.ChatColor; -import org.bukkit.Server; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scoreboard.NameTagVisibility; -import org.bukkit.scoreboard.ScoreboardManager; -import org.bukkit.scoreboard.Team; - -@SuppressWarnings("deprecation") -public class NoNameTag extends JavaPlugin implements Listener { - static Server server; - static ConsoleCommandSender console; - static Plugin plugin; - Team NoNameTagTeam; - - public void onEnable() { - plugin = this; - server = this.getServer(); - console = server.getConsoleSender(); - server.getPluginManager().registerEvents(this, this); - ScoreboardManager sbm = server.getScoreboardManager(); - if (sbm.getMainScoreboard().getTeam("NoNameTagTeam") == null) sbm.getMainScoreboard().registerNewTeam("NoNameTagTeam"); - NoNameTagTeam = sbm.getMainScoreboard().getTeam("NoNameTagTeam"); - NoNameTagTeam.setNameTagVisibility(NameTagVisibility.NEVER); - console.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "NoNameTag Loaded"); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - NoNameTagTeam.addPlayer(event.getPlayer()); - } - - @Override - public void onDisable() { - console.sendMessage(ChatColor.RED + "NoNameTag Disabled"); - } -} \ No newline at end of file diff --git a/src/auracle/NoNameTag.java b/src/auracle/NoNameTag.java new file mode 100644 index 0000000..e95e83c --- /dev/null +++ b/src/auracle/NoNameTag.java @@ -0,0 +1,49 @@ +package auracle; + + +import org.bukkit.ChatColor; +import org.bukkit.Server; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scoreboard.ScoreboardManager; +import org.bukkit.scoreboard.Team; + +public class NoNameTag extends JavaPlugin implements Listener { + static Server server; + static ConsoleCommandSender console; + ScoreboardManager sbm; + Team NoNameTagTeam; + + public void onEnable() { + server = this.getServer(); + server.getPluginManager().registerEvents(this, this); + sbm = server.getScoreboardManager(); + console = server.getConsoleSender(); + console.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "NoNameTag Loaded"); + for(Player player : server.getOnlinePlayers()) + removeNameTag(player.getDisplayName()); + } + + public void onDisable() { console.sendMessage(ChatColor.RED + "NoNameTag Disabled"); } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { removeNameTag(event.getPlayer().getDisplayName()); } + + private void removeNameTag(String PlayerName) { + if (!teamExists()) makeTeam(); + NoNameTagTeam.addEntry(PlayerName); + } + + public boolean teamExists() { return sbm.getMainScoreboard().getTeam("NoNameTagTeam") != null; } + + public void makeTeam() { + sbm.getMainScoreboard().registerNewTeam("NoNameTagTeam"); + NoNameTagTeam = sbm.getMainScoreboard().getTeam("NoNameTagTeam"); + NoNameTagTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + } +} \ No newline at end of file diff --git a/NoNameTag/plugin.yml b/src/plugin.yml similarity index 53% rename from NoNameTag/plugin.yml rename to src/plugin.yml index de81a12..02c00d5 100644 --- a/NoNameTag/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ -name: NoNameTag -main: ca.fastis.NoNameTag -version: 1.0 -author: Auracle +name: NoNameTag +main: auracle.NoNameTag +version: 2.0 +author: Auracle api-version: 1.14 \ No newline at end of file