final fix for new player(hope so)

This commit is contained in:
night0721 2022-07-14 13:02:45 +01:00
parent 4dd88fd075
commit 16ca041b4b
5 changed files with 28 additions and 39 deletions

View file

@ -23,27 +23,8 @@ import java.io.File;
public final class Main extends JavaPlugin implements Listener { public final class Main extends JavaPlugin implements Listener {
private BossBar bossbar; private BossBar bossbar;
private RankManager rankManager;
private NameTagManager nameTagManager;
private SideBarManager sideBarManager;
private BelowNameManager belowNameManager;
private CustomItemManager customItemManager; 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() { public CustomItemManager getCustomItemManager() {
return customItemManager; 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 ScoreboardListener(this), this);
Bukkit.getPluginManager().registerEvents(new CustomItemEvents(), this); Bukkit.getPluginManager().registerEvents(new CustomItemEvents(), this);
Bukkit.getPluginManager().registerEvents(new SpawnCommand(this), this); Bukkit.getPluginManager().registerEvents(new SpawnCommand(this), this);
nameTagManager = new NameTagManager(this);
rankManager = new RankManager(this);
sideBarManager = new SideBarManager();
belowNameManager = new BelowNameManager();
new EnchantmentManager(); new EnchantmentManager();
customItemManager = new CustomItemManager(this); customItemManager = new CustomItemManager(this);
} }

View file

@ -8,6 +8,8 @@ import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import static com.night.nullvalkyrie.Rank.ScoreboardListener.rankManager;
public class NameTagManager { public class NameTagManager {
private Main main; private Main main;
@ -26,13 +28,13 @@ public class NameTagManager {
} }
for (Player target : Bukkit.getOnlinePlayers()) { for (Player target : Bukkit.getOnlinePlayers()) {
if (player.getUniqueId() != target.getUniqueId()) { 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()); player.getScoreboard().getTeam(rank.name()).addEntry(target.getName());
} }
} }
} }
public void newTag(Player player) { public void newTag(Player player) {
Rank rank = main.getRankManager().getRank(player.getUniqueId()); Rank rank = rankManager.getRank(player.getUniqueId());
for(Player target : Bukkit.getOnlinePlayers()) { for(Player target : Bukkit.getOnlinePlayers()) {
target.getScoreboard().getTeam(rank.name()).addEntry(player.getName()); target.getScoreboard().getTeam(rank.name()).addEntry(player.getName());
} }

View file

@ -9,6 +9,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.UUID; import java.util.UUID;
import static com.night.nullvalkyrie.Rank.ScoreboardListener.nameTagManager;
public class RankManager { public class RankManager {
private File file; private File file;
private YamlConfiguration config; private YamlConfiguration config;
@ -39,8 +41,8 @@ public class RankManager {
} }
for(Player player : Bukkit.getOnlinePlayers()) { for(Player player : Bukkit.getOnlinePlayers()) {
if(player.hasPlayedBefore()) { if(player.hasPlayedBefore()) {
main.getNameTagManager().removeTag(player); nameTagManager.removeTag(player);
main.getNameTagManager().newTag(player); nameTagManager.newTag(player);
} }
} }
} }

View file

@ -13,9 +13,15 @@ import org.bukkit.event.player.PlayerQuitEvent;
public class ScoreboardListener implements Listener { 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) { public ScoreboardListener(Main main) {
this.main = main; nameTagManager = new NameTagManager(main);
rankManager = new RankManager(main);
sideBarManager = new SideBarManager();
belowNameManager = new BelowNameManager();
} }
@EventHandler @EventHandler
@ -23,20 +29,20 @@ public class ScoreboardListener implements Listener {
Player player = e.getPlayer(); Player player = e.getPlayer();
if(!player.hasPlayedBefore()) { if(!player.hasPlayedBefore()) {
e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Matrix!", ChatColor.GREEN + "LOL", 20, 100, 20); 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"); 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); nameTagManager.setNametags(player);
main.getNameTagManager().newTag(player); nameTagManager.newTag(player);
main.getSideBarManager().setSideBar(player); sideBarManager.setSideBar(player);
main.getBelowNameManager().setBelowName(player); belowNameManager.setBelowName(player);
e.setJoinMessage(main.getRankManager().getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!"); e.setJoinMessage(rankManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!");
} }
@EventHandler @EventHandler
public void onQuit(PlayerQuitEvent e) { public void onQuit(PlayerQuitEvent e) {
e.setQuitMessage(ChatColor.RED + "bozo " + e.getPlayer().getName() + " has left."); 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()); e.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
} }
@ -44,12 +50,12 @@ public class ScoreboardListener implements Listener {
public void onChat(AsyncPlayerChatEvent e) { public void onChat(AsyncPlayerChatEvent e) {
e.setCancelled(true); e.setCancelled(true);
Player player = e.getPlayer(); 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 //Death changing in sidebar
@EventHandler @EventHandler
public void onDeath(PlayerDeathEvent e) { public void onDeath(PlayerDeathEvent e) {
main.getSideBarManager().changeOnDeath(e.getEntity().getPlayer()); sideBarManager.changeOnDeath(e.getEntity().getPlayer());
} }
} }

View file

@ -16,6 +16,8 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static com.night.nullvalkyrie.Rank.ScoreboardListener.rankManager;
//92.0.69.141:25565 //92.0.69.141:25565
public class RankCommand extends Command { public class RankCommand extends Command {
private Main main; private Main main;
@ -42,7 +44,7 @@ public class RankCommand extends Command {
OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
for(Rank rank : Rank.values()) { for(Rank rank : Rank.values()) {
if(rank.name().equalsIgnoreCase(args[1])) { 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()); player.sendMessage(ChatColor.GREEN + "You changed " + target.getName() + "'s rank to " + rank.getDisplay());
if(target.isOnline()) { if(target.isOnline()) {
target.getPlayer().sendMessage(ChatColor.GREEN + player.getName() + " set your rank to " + rank.getDisplay()); target.getPlayer().sendMessage(ChatColor.GREEN + player.getName() + " set your rank to " + rank.getDisplay());