Slight fix of hologram, fix on all scoreboard

This commit is contained in:
night0721 2022-07-07 09:30:14 +01:00
parent 0b464de40a
commit 8fefa1c0db
6 changed files with 50 additions and 28 deletions

View file

@ -2,9 +2,9 @@ package com.night.nullvalkyrie;
import com.night.nullvalkyrie.Chests.MenuListener; import com.night.nullvalkyrie.Chests.MenuListener;
import com.night.nullvalkyrie.NameTag.NameTagManager; 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.RankSys.RankManager;
import com.night.nullvalkyrie.SideBar.SideBarListener; import com.night.nullvalkyrie.SideBar.SideBarManager;
import com.night.nullvalkyrie.commands.*; import com.night.nullvalkyrie.commands.*;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent; 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.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.server.ServerListPingEvent;
@ -36,11 +35,13 @@ public final class Main extends JavaPlugin implements Listener {
private BossBar bossbar; private BossBar bossbar;
private RankManager rankManager; private RankManager rankManager;
private NameTagManager nameTagManager; private NameTagManager nameTagManager;
private SideBarManager sideBarManager;
public RankManager getRankManager() { public RankManager getRankManager() {
return rankManager; return rankManager;
} }
public NameTagManager getNameTagManager() { return nameTagManager; } public NameTagManager getNameTagManager() { return nameTagManager; }
public SideBarManager getSideBarManager() { return sideBarManager; }
@Override @Override
public void onEnable() { public void onEnable() {
// Plugin startup logic // Plugin startup logic
@ -61,10 +62,10 @@ public final class Main extends JavaPlugin implements Listener {
); );
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new MenuListener(), this); Bukkit.getPluginManager().registerEvents(new MenuListener(), this);
Bukkit.getPluginManager().registerEvents(new RankListener(this), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this);
Bukkit.getPluginManager().registerEvents(new SideBarListener(this), this);
rankManager = new RankManager(this);
nameTagManager = new NameTagManager(this); nameTagManager = new NameTagManager(this);
rankManager = new RankManager(this);
sideBarManager = new SideBarManager(this);
ItemStack widow_sword = new ItemStack(Material.STICK); ItemStack widow_sword = new ItemStack(Material.STICK);
widow_sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20); widow_sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20);

View file

@ -15,11 +15,12 @@ public class NameTagManager {
public NameTagManager(Main main) { public NameTagManager(Main main) {
this.main = main; this.main = main;
} }
@SuppressWarnings("deprecation")
public void setNametags(Player player) { public void setNametags(Player player) {
Scoreboard newScoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); Scoreboard newScoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
Objective obj = newScoreboard.registerNewObjective("TabList", "dummy"); Objective obj = newScoreboard.registerNewObjective("TabList", "dummy");
obj.setDisplaySlot(DisplaySlot.PLAYER_LIST); obj.setDisplaySlot(DisplaySlot.PLAYER_LIST);
player.setScoreboard(obj.getScoreboard()); player.setScoreboard(newScoreboard);
for (Rank rank : Rank.values()) { for (Rank rank : Rank.values()) {
Team team = player.getScoreboard().registerNewTeam(rank.name()); Team team = player.getScoreboard().registerNewTeam(rank.name());
team.setPrefix(rank.getDisplay() + " "); team.setPrefix(rank.getDisplay() + " ");

View file

@ -2,6 +2,7 @@ package com.night.nullvalkyrie.RankSys;
import com.night.nullvalkyrie.Main; import com.night.nullvalkyrie.Main;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View file

@ -6,14 +6,18 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; 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; private Main main;
public RankListener(Main main) { public ScoreboardListener(Main main) {
this.main = main; this.main = main;
} }
@ -25,12 +29,14 @@ public class RankListener implements Listener {
} }
main.getNameTagManager().setNametags(player); main.getNameTagManager().setNametags(player);
main.getNameTagManager().newTag(player); main.getNameTagManager().newTag(player);
main.getSideBarManager().setSideBar(player);
} }
@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()); main.getNameTagManager().removeTag(e.getPlayer());
e.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
} }
@EventHandler @EventHandler
@ -39,4 +45,10 @@ public class RankListener implements Listener {
Player player = e.getPlayer(); Player player = e.getPlayer();
Bukkit.broadcastMessage(main.getRankManager().getRank(player.getUniqueId()).getDisplay() + " " + player.getName() + ChatColor.WHITE + ": " + e.getMessage()); 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());
}
} }

View file

@ -7,31 +7,42 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scoreboard.*; import org.bukkit.scoreboard.*;
import org.bukkit.scoreboard.Scoreboard;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
public class SideBarListener implements Listener { public class SideBarManager {
private Main main; private Main main;
public SideBarListener(Main main) { public SideBarManager(Main main) {
this.main = main; this.main = main;
} }
private HashMap<UUID, Integer> deaths = new HashMap<>(); private HashMap<UUID, Integer> deaths = new HashMap<>();
@EventHandler @SuppressWarnings("deprecation")
public void onJoin(PlayerJoinEvent e) { public void setSideBar(Player player) {
Player player = e.getPlayer(); Scoreboard board = player.getScoreboard();
Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); if(board.getObjective("Pluto") != null) {
}
Objective obj = board.registerNewObjective("Pluto", "dummy"); Objective obj = board.registerNewObjective("Pluto", "dummy");
obj.setDisplaySlot(DisplaySlot.SIDEBAR); obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(ChatColor.AQUA.toString() + ChatColor.BOLD + "Pluto"); 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"); Score website = obj.getScore(ChatColor.YELLOW + "cath.js.org");
website.setScore(1); 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"); Team playersOnline = board.registerNewTeam("deathsTotal");
playersOnline.addEntry(ChatColor.BOLD.toString()); playersOnline.addEntry(ChatColor.BOLD.toString());
playersOnline.setPrefix(ChatColor.BLUE + "Deaths: "); playersOnline.setPrefix(ChatColor.BLUE + "Deaths: ");
@ -41,15 +52,10 @@ public class SideBarListener implements Listener {
deaths.put(player.getUniqueId(), 0); deaths.put(player.getUniqueId(), 0);
} }
@EventHandler public void changeOnDeath(Player player) {
public void onDeath(PlayerDeathEvent e) {
Player player = e.getEntity().getPlayer();
int amount = deaths.get(player.getUniqueId()); int amount = deaths.get(player.getUniqueId());
amount++; amount++;
deaths.put(player.getUniqueId(), amount); deaths.put(player.getUniqueId(), amount);
player.getScoreboard().getTeam("deathsTotal").setSuffix(ChatColor.YELLOW.toString() + amount); player.getScoreboard().getTeam("deathsTotal").setSuffix(ChatColor.YELLOW.toString() + amount);
} }
} }

View file

@ -21,8 +21,9 @@ public class HologramCommand implements CommandExecutor {
}; };
Location location = player.getLocation(); Location location = player.getLocation();
for(String line: ar) { for(String line: ar) {
ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(location.subtract(0,0.3,0), EntityType.ARMOR_STAND); ArmorStand stand = location.getWorld().spawn(location.subtract(0,0.3,0), ArmorStand.class, armorStand -> {
stand.setInvisible(true); armorStand.setVisible(false);
});
stand.setGravity(false); stand.setGravity(false);
stand.setInvulnerable(true); stand.setInvulnerable(true);
stand.setCustomNameVisible(true); stand.setCustomNameVisible(true);