From 8fefa1c0db0afbd0bb1a138ebb107f0d040783ab Mon Sep 17 00:00:00 2001 From: night0721 Date: Thu, 7 Jul 2022 09:30:14 +0100 Subject: [PATCH] Slight fix of hologram, fix on all scoreboard --- .../java/com/night/nullvalkyrie/Main.java | 13 +++--- .../nullvalkyrie/NameTag/NameTagManager.java | 3 +- .../nullvalkyrie/RankSys/RankManager.java | 1 + ...kListener.java => ScoreboardListener.java} | 16 +++++++- ...deBarListener.java => SideBarManager.java} | 40 +++++++++++-------- .../commands/HologramCommand.java | 5 ++- 6 files changed, 50 insertions(+), 28 deletions(-) rename src/main/java/com/night/nullvalkyrie/RankSys/{RankListener.java => ScoreboardListener.java} (71%) rename src/main/java/com/night/nullvalkyrie/SideBar/{SideBarListener.java => SideBarManager.java} (62%) diff --git a/src/main/java/com/night/nullvalkyrie/Main.java b/src/main/java/com/night/nullvalkyrie/Main.java index f93fa5b..d01715a 100644 --- a/src/main/java/com/night/nullvalkyrie/Main.java +++ b/src/main/java/com/night/nullvalkyrie/Main.java @@ -2,9 +2,9 @@ package com.night.nullvalkyrie; import com.night.nullvalkyrie.Chests.MenuListener; import com.night.nullvalkyrie.NameTag.NameTagManager; -import com.night.nullvalkyrie.RankSys.RankListener; +import com.night.nullvalkyrie.RankSys.ScoreboardListener; import com.night.nullvalkyrie.RankSys.RankManager; -import com.night.nullvalkyrie.SideBar.SideBarListener; +import com.night.nullvalkyrie.SideBar.SideBarManager; import com.night.nullvalkyrie.commands.*; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -21,7 +21,6 @@ import org.bukkit.entity.Snowball; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; -import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.server.ServerListPingEvent; @@ -36,11 +35,13 @@ public final class Main extends JavaPlugin implements Listener { private BossBar bossbar; private RankManager rankManager; private NameTagManager nameTagManager; + private SideBarManager sideBarManager; public RankManager getRankManager() { return rankManager; } public NameTagManager getNameTagManager() { return nameTagManager; } + public SideBarManager getSideBarManager() { return sideBarManager; } @Override public void onEnable() { // Plugin startup logic @@ -61,10 +62,10 @@ public final class Main extends JavaPlugin implements Listener { ); Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new MenuListener(), this); - Bukkit.getPluginManager().registerEvents(new RankListener(this), this); - Bukkit.getPluginManager().registerEvents(new SideBarListener(this), this); - rankManager = new RankManager(this); + Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); nameTagManager = new NameTagManager(this); + rankManager = new RankManager(this); + sideBarManager = new SideBarManager(this); ItemStack widow_sword = new ItemStack(Material.STICK); widow_sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20); diff --git a/src/main/java/com/night/nullvalkyrie/NameTag/NameTagManager.java b/src/main/java/com/night/nullvalkyrie/NameTag/NameTagManager.java index 339457d..86a9c7d 100644 --- a/src/main/java/com/night/nullvalkyrie/NameTag/NameTagManager.java +++ b/src/main/java/com/night/nullvalkyrie/NameTag/NameTagManager.java @@ -15,11 +15,12 @@ public class NameTagManager { public NameTagManager(Main main) { this.main = main; } + @SuppressWarnings("deprecation") public void setNametags(Player player) { Scoreboard newScoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); Objective obj = newScoreboard.registerNewObjective("TabList", "dummy"); obj.setDisplaySlot(DisplaySlot.PLAYER_LIST); - player.setScoreboard(obj.getScoreboard()); + player.setScoreboard(newScoreboard); for (Rank rank : Rank.values()) { Team team = player.getScoreboard().registerNewTeam(rank.name()); team.setPrefix(rank.getDisplay() + " "); diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java b/src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java index e51e4ed..fab35d6 100644 --- a/src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java +++ b/src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java @@ -2,6 +2,7 @@ package com.night.nullvalkyrie.RankSys; import com.night.nullvalkyrie.Main; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/RankListener.java b/src/main/java/com/night/nullvalkyrie/RankSys/ScoreboardListener.java similarity index 71% rename from src/main/java/com/night/nullvalkyrie/RankSys/RankListener.java rename to src/main/java/com/night/nullvalkyrie/RankSys/ScoreboardListener.java index b3b2257..1422f0e 100644 --- a/src/main/java/com/night/nullvalkyrie/RankSys/RankListener.java +++ b/src/main/java/com/night/nullvalkyrie/RankSys/ScoreboardListener.java @@ -6,14 +6,18 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -public class RankListener implements Listener { +import java.util.HashMap; +import java.util.UUID; + +public class ScoreboardListener implements Listener { private Main main; - public RankListener(Main main) { + public ScoreboardListener(Main main) { this.main = main; } @@ -25,12 +29,14 @@ public class RankListener implements Listener { } main.getNameTagManager().setNametags(player); main.getNameTagManager().newTag(player); + main.getSideBarManager().setSideBar(player); } @EventHandler public void onQuit(PlayerQuitEvent e) { e.setQuitMessage(ChatColor.RED + "bozo " + e.getPlayer().getName() + " has left."); main.getNameTagManager().removeTag(e.getPlayer()); + e.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); } @EventHandler @@ -39,4 +45,10 @@ public class RankListener implements Listener { Player player = e.getPlayer(); Bukkit.broadcastMessage(main.getRankManager().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()); + } } diff --git a/src/main/java/com/night/nullvalkyrie/SideBar/SideBarListener.java b/src/main/java/com/night/nullvalkyrie/SideBar/SideBarManager.java similarity index 62% rename from src/main/java/com/night/nullvalkyrie/SideBar/SideBarListener.java rename to src/main/java/com/night/nullvalkyrie/SideBar/SideBarManager.java index 73ff4b8..bf69c15 100644 --- a/src/main/java/com/night/nullvalkyrie/SideBar/SideBarListener.java +++ b/src/main/java/com/night/nullvalkyrie/SideBar/SideBarManager.java @@ -7,31 +7,42 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.scoreboard.*; +import org.bukkit.scoreboard.Scoreboard; import java.util.HashMap; import java.util.UUID; -public class SideBarListener implements Listener { +public class SideBarManager { private Main main; - public SideBarListener(Main main) { + public SideBarManager(Main main) { this.main = main; } private HashMap deaths = new HashMap<>(); - @EventHandler - public void onJoin(PlayerJoinEvent e) { - Player player = e.getPlayer(); - Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); + @SuppressWarnings("deprecation") + public void setSideBar(Player player) { + Scoreboard board = player.getScoreboard(); + if(board.getObjective("Pluto") != null) { + + } Objective obj = board.registerNewObjective("Pluto", "dummy"); obj.setDisplaySlot(DisplaySlot.SIDEBAR); obj.setDisplayName(ChatColor.AQUA.toString() + ChatColor.BOLD + "Pluto"); + Score name = obj.getScore(ChatColor.BLUE + "Player Name: "); + name.setScore(8); + Score name2 = obj.getScore(ChatColor.WHITE + player.getName()); + name2.setScore(7); + Score space1 = obj.getScore(" "); + space1.setScore(6); + Score players = obj.getScore(ChatColor.LIGHT_PURPLE + "Players Online:"); + players.setScore(5); + Score playercount = obj.getScore(ChatColor.YELLOW.toString() + Bukkit.getServer().getOnlinePlayers().size()); + playercount.setScore(4); + Score space2 = obj.getScore(" "); + space2.setScore(2); Score website = obj.getScore(ChatColor.YELLOW + "cath.js.org"); website.setScore(1); - Score space1 = obj.getScore(" "); - space1.setScore(2); - Score name = obj.getScore(ChatColor.BLUE + "Player Name: " + player.getName()); - name.setScore(4); + Team playersOnline = board.registerNewTeam("deathsTotal"); playersOnline.addEntry(ChatColor.BOLD.toString()); playersOnline.setPrefix(ChatColor.BLUE + "Deaths: "); @@ -41,15 +52,10 @@ public class SideBarListener implements Listener { deaths.put(player.getUniqueId(), 0); } - @EventHandler - public void onDeath(PlayerDeathEvent e) { - Player player = e.getEntity().getPlayer(); + public void changeOnDeath(Player player) { int amount = deaths.get(player.getUniqueId()); amount++; deaths.put(player.getUniqueId(), amount); player.getScoreboard().getTeam("deathsTotal").setSuffix(ChatColor.YELLOW.toString() + amount); } - - - } diff --git a/src/main/java/com/night/nullvalkyrie/commands/HologramCommand.java b/src/main/java/com/night/nullvalkyrie/commands/HologramCommand.java index 1b1490b..4437062 100644 --- a/src/main/java/com/night/nullvalkyrie/commands/HologramCommand.java +++ b/src/main/java/com/night/nullvalkyrie/commands/HologramCommand.java @@ -21,8 +21,9 @@ public class HologramCommand implements CommandExecutor { }; Location location = player.getLocation(); for(String line: ar) { - ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(location.subtract(0,0.3,0), EntityType.ARMOR_STAND); - stand.setInvisible(true); + ArmorStand stand = location.getWorld().spawn(location.subtract(0,0.3,0), ArmorStand.class, armorStand -> { + armorStand.setVisible(false); + }); stand.setGravity(false); stand.setInvulnerable(true); stand.setCustomNameVisible(true);