From 16ca041b4bcf2d1f98a36b22f545c82c25156ef9 Mon Sep 17 00:00:00 2001 From: night0721 Date: Thu, 14 Jul 2022 13:02:45 +0100 Subject: [PATCH] final fix for new player(hope so) --- .../java/com/night/nullvalkyrie/Main.java | 23 --------------- .../nullvalkyrie/Rank/NameTagManager.java | 6 ++-- .../night/nullvalkyrie/Rank/RankManager.java | 6 ++-- .../nullvalkyrie/Rank/ScoreboardListener.java | 28 +++++++++++-------- .../nullvalkyrie/commands/RankCommand.java | 4 ++- 5 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/night/nullvalkyrie/Main.java b/src/main/java/com/night/nullvalkyrie/Main.java index e885e16..e28b043 100644 --- a/src/main/java/com/night/nullvalkyrie/Main.java +++ b/src/main/java/com/night/nullvalkyrie/Main.java @@ -23,27 +23,8 @@ import java.io.File; public final class Main extends JavaPlugin implements Listener { private BossBar bossbar; - private RankManager rankManager; - private NameTagManager nameTagManager; - private SideBarManager sideBarManager; - private BelowNameManager belowNameManager; private CustomItemManager customItemManager; - public RankManager getRankManager() { - return rankManager; - } - - public NameTagManager getNameTagManager() { - return nameTagManager; - } - - public SideBarManager getSideBarManager() { - return sideBarManager; - } - - public BelowNameManager getBelowNameManager() { - return belowNameManager; - } public CustomItemManager getCustomItemManager() { return customItemManager; } @@ -70,10 +51,6 @@ public final class Main extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); Bukkit.getPluginManager().registerEvents(new CustomItemEvents(), this); Bukkit.getPluginManager().registerEvents(new SpawnCommand(this), this); - nameTagManager = new NameTagManager(this); - rankManager = new RankManager(this); - sideBarManager = new SideBarManager(); - belowNameManager = new BelowNameManager(); new EnchantmentManager(); customItemManager = new CustomItemManager(this); } diff --git a/src/main/java/com/night/nullvalkyrie/Rank/NameTagManager.java b/src/main/java/com/night/nullvalkyrie/Rank/NameTagManager.java index 8d93d2d..3b65e45 100644 --- a/src/main/java/com/night/nullvalkyrie/Rank/NameTagManager.java +++ b/src/main/java/com/night/nullvalkyrie/Rank/NameTagManager.java @@ -8,6 +8,8 @@ import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; +import static com.night.nullvalkyrie.Rank.ScoreboardListener.rankManager; + public class NameTagManager { private Main main; @@ -26,13 +28,13 @@ public class NameTagManager { } for (Player target : Bukkit.getOnlinePlayers()) { if (player.getUniqueId() != target.getUniqueId()) { - Rank rank = main.getRankManager().getRank(target.getUniqueId()); + Rank rank = rankManager.getRank(target.getUniqueId()); player.getScoreboard().getTeam(rank.name()).addEntry(target.getName()); } } } public void newTag(Player player) { - Rank rank = main.getRankManager().getRank(player.getUniqueId()); + Rank rank = rankManager.getRank(player.getUniqueId()); for(Player target : Bukkit.getOnlinePlayers()) { target.getScoreboard().getTeam(rank.name()).addEntry(player.getName()); } diff --git a/src/main/java/com/night/nullvalkyrie/Rank/RankManager.java b/src/main/java/com/night/nullvalkyrie/Rank/RankManager.java index 65001d4..a633a2c 100644 --- a/src/main/java/com/night/nullvalkyrie/Rank/RankManager.java +++ b/src/main/java/com/night/nullvalkyrie/Rank/RankManager.java @@ -9,6 +9,8 @@ import java.io.File; import java.io.IOException; import java.util.UUID; +import static com.night.nullvalkyrie.Rank.ScoreboardListener.nameTagManager; + public class RankManager { private File file; private YamlConfiguration config; @@ -39,8 +41,8 @@ public class RankManager { } for(Player player : Bukkit.getOnlinePlayers()) { if(player.hasPlayedBefore()) { - main.getNameTagManager().removeTag(player); - main.getNameTagManager().newTag(player); + nameTagManager.removeTag(player); + nameTagManager.newTag(player); } } } diff --git a/src/main/java/com/night/nullvalkyrie/Rank/ScoreboardListener.java b/src/main/java/com/night/nullvalkyrie/Rank/ScoreboardListener.java index fe8be67..669aa90 100644 --- a/src/main/java/com/night/nullvalkyrie/Rank/ScoreboardListener.java +++ b/src/main/java/com/night/nullvalkyrie/Rank/ScoreboardListener.java @@ -13,9 +13,15 @@ import org.bukkit.event.player.PlayerQuitEvent; public class ScoreboardListener implements Listener { - private Main main; + public static RankManager rankManager; + public static NameTagManager nameTagManager; + private SideBarManager sideBarManager; + private BelowNameManager belowNameManager; public ScoreboardListener(Main main) { - this.main = main; + nameTagManager = new NameTagManager(main); + rankManager = new RankManager(main); + sideBarManager = new SideBarManager(); + belowNameManager = new BelowNameManager(); } @EventHandler @@ -23,20 +29,20 @@ public class ScoreboardListener implements Listener { Player player = e.getPlayer(); if(!player.hasPlayedBefore()) { e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Matrix!", ChatColor.GREEN + "LOL", 20, 100, 20); - main.getRankManager().setRank(player.getUniqueId(), Rank.ROOKIE); + rankManager.setRank(player.getUniqueId(), Rank.ROOKIE); } e.getPlayer().setPlayerListHeaderFooter(ChatColor.AQUA + "You are playing on " + ChatColor.GREEN + "127.0.0.1", ChatColor.GOLD + "Ranks, boosters, & more!" + ChatColor.AQUA + "127.0.0.1"); - main.getNameTagManager().setNametags(player); - main.getNameTagManager().newTag(player); - main.getSideBarManager().setSideBar(player); - main.getBelowNameManager().setBelowName(player); - e.setJoinMessage(main.getRankManager().getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!"); + nameTagManager.setNametags(player); + nameTagManager.newTag(player); + sideBarManager.setSideBar(player); + belowNameManager.setBelowName(player); + e.setJoinMessage(rankManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!"); } @EventHandler public void onQuit(PlayerQuitEvent e) { e.setQuitMessage(ChatColor.RED + "bozo " + e.getPlayer().getName() + " has left."); - main.getNameTagManager().removeTag(e.getPlayer()); + nameTagManager.removeTag(e.getPlayer()); e.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); } @@ -44,12 +50,12 @@ public class ScoreboardListener implements Listener { public void onChat(AsyncPlayerChatEvent e) { e.setCancelled(true); Player player = e.getPlayer(); - Bukkit.broadcastMessage(main.getRankManager().getRank(player.getUniqueId()).getDisplay() + " " + player.getName() + ChatColor.WHITE + ": " + e.getMessage()); + Bukkit.broadcastMessage(rankManager.getRank(player.getUniqueId()).getDisplay() + " " + player.getName() + ChatColor.WHITE + ": " + e.getMessage()); } //Death changing in sidebar @EventHandler public void onDeath(PlayerDeathEvent e) { - main.getSideBarManager().changeOnDeath(e.getEntity().getPlayer()); + sideBarManager.changeOnDeath(e.getEntity().getPlayer()); } } diff --git a/src/main/java/com/night/nullvalkyrie/commands/RankCommand.java b/src/main/java/com/night/nullvalkyrie/commands/RankCommand.java index 25a93ea..730ea0e 100644 --- a/src/main/java/com/night/nullvalkyrie/commands/RankCommand.java +++ b/src/main/java/com/night/nullvalkyrie/commands/RankCommand.java @@ -16,6 +16,8 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; +import static com.night.nullvalkyrie.Rank.ScoreboardListener.rankManager; + //92.0.69.141:25565 public class RankCommand extends Command { private Main main; @@ -42,7 +44,7 @@ public class RankCommand extends Command { OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); for(Rank rank : Rank.values()) { if(rank.name().equalsIgnoreCase(args[1])) { - main.getRankManager().setRank(target.getUniqueId(), rank); + rankManager.setRank(target.getUniqueId(), rank); player.sendMessage(ChatColor.GREEN + "You changed " + target.getName() + "'s rank to " + rank.getDisplay()); if(target.isOnline()) { target.getPlayer().sendMessage(ChatColor.GREEN + player.getName() + " set your rank to " + rank.getDisplay());