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.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);

View file

@ -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() + " ");

View file

@ -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;

View file

@ -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());
}
}

View file

@ -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<UUID, Integer> 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);
}
}

View file

@ -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);