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

View file

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

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.ui;
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 org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -20,6 +20,7 @@ public class ScoreboardListener implements Listener {
public static NameTagManager nameTagManager;
private final SideBarManager sideBarManager;
private final BelowNameManager belowNameManager;
public ScoreboardListener(Main main) {
nameTagManager = new NameTagManager();
sideBarManager = new SideBarManager(main);
@ -29,9 +30,9 @@ public class ScoreboardListener implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
if(!player.hasPlayedBefore()) {
e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Matrix!", ChatColor.GREEN + "LOL", 20, 100, 20);
RankManager.setRank(player.getUniqueId(), Rank.ROOKIE);
if (!player.hasPlayedBefore()) {
e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Vanadium!", ChatColor.GREEN + "LOL", 20, 100, 20);
RankDataManager.setRank(player.getUniqueId(), Rank.ROOKIE);
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");
@ -40,33 +41,32 @@ public class ScoreboardListener implements Listener {
sideBarManager.setSideBar(player);
sideBarManager.start(player);
belowNameManager.setBelowName(player);
e.setJoinMessage(RankManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!");
if(NPCManager.getNPCs() == null) return;
if(NPCManager.getNPCs().isEmpty()) return;
e.setJoinMessage(RankDataManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!");
if (NPCManager.getNPCs() == null) return;
if (NPCManager.getNPCs().isEmpty()) return;
NPCManager.addJoinPacket(e.getPlayer());
}
@EventHandler
public void onQuit(PlayerQuitEvent e) {
e.setQuitMessage(ChatColor.RED + "bozo " + e.getPlayer().getName() + " has left.");
e.setQuitMessage(null);
nameTagManager.removeTag(e.getPlayer());
e.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
AnimatedSideBar board = new AnimatedSideBar(e.getPlayer().getUniqueId());
if(board.hasID()) {
board.stop();
}
AnimatedSideBar board = sideBarManager.board;
if (board.hasID()) board.stop();
}
@EventHandler
public void onChat(AsyncPlayerChatEvent e) {
e.setCancelled(true);
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
@EventHandler
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 int taskID;
private final Main main;
public AnimatedSideBar board = null;
public SideBarManager(Main main) {
this.main = main;
@ -23,11 +24,8 @@ public class SideBarManager {
public void setSideBar(Player player) {
Scoreboard board = player.getScoreboard();
Objective obj;
if (board.getObjective("Vanadium") != null) {
obj = board.getObjective("Vanadium");
} else {
obj = board.registerNewObjective("Vanadium", Criteria.DUMMY, ChatColor.AQUA.toString() + ChatColor.BOLD + ">> Vanadium <<");
}
if (board.getObjective("Vanadium") != null) obj = board.getObjective("Vanadium");
else obj = board.registerNewObjective("Vanadium", Criteria.DUMMY, ChatColor.AQUA.toString() + ChatColor.BOLD + ">> Vanadium <<");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
Score hypens = obj.getScore(ChatColor.GOLD + "=-=-=-=-=-=-=-=");
hypens.setScore(9);
@ -46,9 +44,8 @@ public class SideBarManager {
Score website = obj.getScore(ChatColor.YELLOW + "cath.js.org");
website.setScore(1);
Team playersOnline;
if (board.getTeam("deathsTotal") != null) {
playersOnline = board.getTeam("deathsTotal");
} else playersOnline = board.registerNewTeam("deathsTotal");
if (board.getTeam("deathsTotal") != null) playersOnline = board.getTeam("deathsTotal");
else playersOnline = board.registerNewTeam("deathsTotal");
playersOnline.addEntry(ChatColor.BOLD.toString());
playersOnline.setPrefix(ChatColor.BLUE + "Deaths: ");
playersOnline.setSuffix(ChatColor.YELLOW + "0");
@ -58,22 +55,22 @@ public class SideBarManager {
}
public void start(Player player) {
board = new AnimatedSideBar(player.getUniqueId());
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(main, new Runnable() {
int count = 0;
final AnimatedSideBar board = new AnimatedSideBar(player.getUniqueId());
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.setDisplayName(Util.color(str));
}
@Override
public void run() {
if (!board.hasID())
board.setID(taskID);
if (count == 13)
count = 0;
if (!board.hasID()) board.setID(taskID);
if (count == 13) count = 0;
switch (count) {
case 0 -> animate("&1&l>> &e&lVanadium&1&l <<");
case 1 -> animate("&b&l>&1&l> &e&lVanadium &1&l<<");