fixing bugs in sidebar and scoreboard

This commit is contained in:
NK 2022-11-28 22:40:46 +00:00
parent f0a065dd74
commit b0d6a768ae
4 changed files with 36 additions and 38 deletions

View file

@ -1,8 +1,7 @@
package me.night.nullvalkyrie.database.ranks; package me.night.nullvalkyrie.database;
import com.mongodb.client.MongoCursor; import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.Filters; import com.mongodb.client.model.Filters;
import me.night.nullvalkyrie.database.DatabaseManager;
import me.night.nullvalkyrie.ui.Rank; import me.night.nullvalkyrie.ui.Rank;
import org.bson.Document; import org.bson.Document;
import org.bson.conversions.Bson; import org.bson.conversions.Bson;
@ -13,7 +12,7 @@ import java.util.UUID;
import static me.night.nullvalkyrie.ui.ScoreboardListener.nameTagManager; import static me.night.nullvalkyrie.ui.ScoreboardListener.nameTagManager;
public class RankManager { public class RankDataManager {
public static void setRank(UUID uuid, Rank rank) { public static void setRank(UUID uuid, Rank rank) {
Document document = DatabaseManager.ranks.find(new Document("UUID", uuid.toString())).first(); Document document = DatabaseManager.ranks.find(new Document("UUID", uuid.toString())).first();
if(document != null) { if(document != null) {

View file

@ -1,6 +1,6 @@
package me.night.nullvalkyrie.ui; package me.night.nullvalkyrie.ui;
import me.night.nullvalkyrie.database.ranks.RankManager; import me.night.nullvalkyrie.database.RankDataManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.*; import org.bukkit.scoreboard.*;
@ -17,20 +17,22 @@ 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 = RankManager.getRank(target.getUniqueId()); Rank rank = RankDataManager.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 = RankManager.getRank(player.getUniqueId()); Rank rank = RankDataManager.getRank(player.getUniqueId());
for(Player target : Bukkit.getOnlinePlayers()) { for (Player target : Bukkit.getOnlinePlayers()) {
if(rank == null) target.getScoreboard().getTeam(Rank.ROOKIE.name()).addEntry(player.getName()); if (rank == null) target.getScoreboard().getTeam(Rank.ROOKIE.name()).addEntry(player.getName());
else target.getScoreboard().getTeam(rank.name()).addEntry(player.getName()); else target.getScoreboard().getTeam(rank.name()).addEntry(player.getName());
} }
} }
public void removeTag(Player player) { public void removeTag(Player player) {
for(Player target : Bukkit.getOnlinePlayers()) { for (Player target : Bukkit.getOnlinePlayers()) {
target.getScoreboard().getEntryTeam(player.getName()).removeEntry(player.getName()); target.getScoreboard().getEntryTeam(player.getName()).removeEntry(player.getName());
} }
} }

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.ui; package me.night.nullvalkyrie.ui;
import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.database.ranks.RankManager; import me.night.nullvalkyrie.database.RankDataManager;
import me.night.nullvalkyrie.npc.NPCManager; import me.night.nullvalkyrie.npc.NPCManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -20,6 +20,7 @@ public class ScoreboardListener implements Listener {
public static NameTagManager nameTagManager; public static NameTagManager nameTagManager;
private final SideBarManager sideBarManager; private final SideBarManager sideBarManager;
private final BelowNameManager belowNameManager; private final BelowNameManager belowNameManager;
public ScoreboardListener(Main main) { public ScoreboardListener(Main main) {
nameTagManager = new NameTagManager(); nameTagManager = new NameTagManager();
sideBarManager = new SideBarManager(main); sideBarManager = new SideBarManager(main);
@ -29,9 +30,9 @@ public class ScoreboardListener implements Listener {
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent e) { public void onJoin(PlayerJoinEvent e) {
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 Vanadium!", ChatColor.GREEN + "LOL", 20, 100, 20);
RankManager.setRank(player.getUniqueId(), Rank.ROOKIE); RankDataManager.setRank(player.getUniqueId(), Rank.ROOKIE);
createUserSchema(e.getPlayer().getDisplayName()); createUserSchema(e.getPlayer().getDisplayName());
} }
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");
@ -40,33 +41,32 @@ public class ScoreboardListener implements Listener {
sideBarManager.setSideBar(player); sideBarManager.setSideBar(player);
sideBarManager.start(player); sideBarManager.start(player);
belowNameManager.setBelowName(player); belowNameManager.setBelowName(player);
e.setJoinMessage(RankManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!"); e.setJoinMessage(RankDataManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!");
if(NPCManager.getNPCs() == null) return; if (NPCManager.getNPCs() == null) return;
if(NPCManager.getNPCs().isEmpty()) return; if (NPCManager.getNPCs().isEmpty()) return;
NPCManager.addJoinPacket(e.getPlayer()); NPCManager.addJoinPacket(e.getPlayer());
} }
@EventHandler @EventHandler
public void onQuit(PlayerQuitEvent e) { public void onQuit(PlayerQuitEvent e) {
e.setQuitMessage(ChatColor.RED + "bozo " + e.getPlayer().getName() + " has left."); e.setQuitMessage(null);
nameTagManager.removeTag(e.getPlayer()); nameTagManager.removeTag(e.getPlayer());
e.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); e.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
AnimatedSideBar board = new AnimatedSideBar(e.getPlayer().getUniqueId()); AnimatedSideBar board = sideBarManager.board;
if(board.hasID()) { if (board.hasID()) board.stop();
board.stop();
}
} }
@EventHandler @EventHandler
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(me.night.nullvalkyrie.database.ranks.RankManager.getRank(player.getUniqueId()).getDisplay() + " " + player.getName() + ChatColor.WHITE + ": " + e.getMessage()); Bukkit.broadcastMessage(RankDataManager.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) {
if(e.getEntity().getPlayer() == null) sideBarManager.changeOnDeath(e.getEntity().getPlayer()); if (e.getEntity().getPlayer() == null) sideBarManager.changeOnDeath(e.getEntity().getPlayer());
} }
} }

View file

@ -15,6 +15,7 @@ public class SideBarManager {
private final HashMap<UUID, Integer> deaths = new HashMap<>(); private final HashMap<UUID, Integer> deaths = new HashMap<>();
private int taskID; private int taskID;
private final Main main; private final Main main;
public AnimatedSideBar board = null;
public SideBarManager(Main main) { public SideBarManager(Main main) {
this.main = main; this.main = main;
@ -23,11 +24,8 @@ public class SideBarManager {
public void setSideBar(Player player) { public void setSideBar(Player player) {
Scoreboard board = player.getScoreboard(); Scoreboard board = player.getScoreboard();
Objective obj; Objective obj;
if (board.getObjective("Vanadium") != null) { if (board.getObjective("Vanadium") != null) obj = board.getObjective("Vanadium");
obj = board.getObjective("Vanadium"); else obj = board.registerNewObjective("Vanadium", Criteria.DUMMY, ChatColor.AQUA.toString() + ChatColor.BOLD + ">> Vanadium <<");
} else {
obj = board.registerNewObjective("Vanadium", Criteria.DUMMY, ChatColor.AQUA.toString() + ChatColor.BOLD + ">> Vanadium <<");
}
obj.setDisplaySlot(DisplaySlot.SIDEBAR); obj.setDisplaySlot(DisplaySlot.SIDEBAR);
Score hypens = obj.getScore(ChatColor.GOLD + "=-=-=-=-=-=-=-="); Score hypens = obj.getScore(ChatColor.GOLD + "=-=-=-=-=-=-=-=");
hypens.setScore(9); hypens.setScore(9);
@ -46,9 +44,8 @@ public class SideBarManager {
Score website = obj.getScore(ChatColor.YELLOW + "cath.js.org"); Score website = obj.getScore(ChatColor.YELLOW + "cath.js.org");
website.setScore(1); website.setScore(1);
Team playersOnline; Team playersOnline;
if (board.getTeam("deathsTotal") != null) { if (board.getTeam("deathsTotal") != null) playersOnline = board.getTeam("deathsTotal");
playersOnline = board.getTeam("deathsTotal"); else playersOnline = board.registerNewTeam("deathsTotal");
} else playersOnline = board.registerNewTeam("deathsTotal");
playersOnline.addEntry(ChatColor.BOLD.toString()); playersOnline.addEntry(ChatColor.BOLD.toString());
playersOnline.setPrefix(ChatColor.BLUE + "Deaths: "); playersOnline.setPrefix(ChatColor.BLUE + "Deaths: ");
playersOnline.setSuffix(ChatColor.YELLOW + "0"); playersOnline.setSuffix(ChatColor.YELLOW + "0");
@ -58,22 +55,22 @@ public class SideBarManager {
} }
public void start(Player player) { public void start(Player player) {
board = new AnimatedSideBar(player.getUniqueId());
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(main, new Runnable() { taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(main, new Runnable() {
int count = 0; int count = 0;
final AnimatedSideBar board = new AnimatedSideBar(player.getUniqueId());
public void animate(String str) { public void animate(String str) {
Objective objective = player.getScoreboard().getObjective("Vanadium"); Scoreboard board = player.getScoreboard();
Objective objective;
if (board.getObjective("Vanadium") != null) objective = board.getObjective("Vanadium");
else objective = board.registerNewObjective("Vanadium", Criteria.DUMMY, ChatColor.AQUA.toString() + ChatColor.BOLD + ">> Vanadium <<");
objective.setDisplaySlot(DisplaySlot.SIDEBAR); objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName(Util.color(str)); objective.setDisplayName(Util.color(str));
} }
@Override @Override
public void run() { public void run() {
if (!board.hasID()) if (!board.hasID()) board.setID(taskID);
board.setID(taskID); if (count == 13) count = 0;
if (count == 13)
count = 0;
switch (count) { switch (count) {
case 0 -> animate("&1&l>> &e&lVanadium&1&l <<"); case 0 -> animate("&1&l>> &e&lVanadium&1&l <<");
case 1 -> animate("&b&l>&1&l> &e&lVanadium &1&l<<"); case 1 -> animate("&b&l>&1&l> &e&lVanadium &1&l<<");