From 532bea2e0c5448b53e3c345892dc97a98fc83050 Mon Sep 17 00:00:00 2001 From: night0721 Date: Wed, 6 Jul 2022 14:08:53 +0100 Subject: [PATCH] Rank system, but need to remove sidebar to make tab list work... idk why --- .../{ => Chests}/MenuListener.java | 2 +- .../{ => Chests}/WitherChest.java | 2 +- .../java/com/night/nullvalkyrie/Main.java | 45 ++++++++++++++- .../nullvalkyrie/NameTag/NameTagManager.java | 46 +++++++++++++++ .../com/night/nullvalkyrie/RankSys/Rank.java | 20 +++++++ .../nullvalkyrie/RankSys/RankListener.java | 42 ++++++++++++++ .../nullvalkyrie/RankSys/RankManager.java | 49 ++++++++++++++++ .../nullvalkyrie/SideBar/SideBarListener.java | 57 +++++++++++++++++++ .../nullvalkyrie/commands/RankCommand.java | 49 ++++++++++++++++ src/main/resources/plugin.yml | 4 +- 10 files changed, 310 insertions(+), 6 deletions(-) rename src/main/java/com/night/nullvalkyrie/{ => Chests}/MenuListener.java (96%) rename src/main/java/com/night/nullvalkyrie/{ => Chests}/WitherChest.java (85%) create mode 100644 src/main/java/com/night/nullvalkyrie/NameTag/NameTagManager.java create mode 100644 src/main/java/com/night/nullvalkyrie/RankSys/Rank.java create mode 100644 src/main/java/com/night/nullvalkyrie/RankSys/RankListener.java create mode 100644 src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java create mode 100644 src/main/java/com/night/nullvalkyrie/SideBar/SideBarListener.java create mode 100644 src/main/java/com/night/nullvalkyrie/commands/RankCommand.java diff --git a/src/main/java/com/night/nullvalkyrie/MenuListener.java b/src/main/java/com/night/nullvalkyrie/Chests/MenuListener.java similarity index 96% rename from src/main/java/com/night/nullvalkyrie/MenuListener.java rename to src/main/java/com/night/nullvalkyrie/Chests/MenuListener.java index 398feb2..2c24c1c 100644 --- a/src/main/java/com/night/nullvalkyrie/MenuListener.java +++ b/src/main/java/com/night/nullvalkyrie/Chests/MenuListener.java @@ -1,4 +1,4 @@ -package com.night.nullvalkyrie; +package com.night.nullvalkyrie.Chests; import com.night.nullvalkyrie.commands.MenuCommand; import org.bukkit.ChatColor; diff --git a/src/main/java/com/night/nullvalkyrie/WitherChest.java b/src/main/java/com/night/nullvalkyrie/Chests/WitherChest.java similarity index 85% rename from src/main/java/com/night/nullvalkyrie/WitherChest.java rename to src/main/java/com/night/nullvalkyrie/Chests/WitherChest.java index 8039fc6..5889efc 100644 --- a/src/main/java/com/night/nullvalkyrie/WitherChest.java +++ b/src/main/java/com/night/nullvalkyrie/Chests/WitherChest.java @@ -1,4 +1,4 @@ -package com.night.nullvalkyrie; +package com.night.nullvalkyrie.Chests; import org.bukkit.Bukkit; import org.bukkit.ChatColor; diff --git a/src/main/java/com/night/nullvalkyrie/Main.java b/src/main/java/com/night/nullvalkyrie/Main.java index a0b5616..248c8ff 100644 --- a/src/main/java/com/night/nullvalkyrie/Main.java +++ b/src/main/java/com/night/nullvalkyrie/Main.java @@ -1,14 +1,21 @@ 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.RankManager; +import com.night.nullvalkyrie.SideBar.SideBarListener; import com.night.nullvalkyrie.commands.*; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.entity.Snowball; import org.bukkit.event.EventHandler; @@ -17,12 +24,22 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.server.ServerListPingEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; public final class Main extends JavaPlugin implements Listener { private BossBar bossbar; + private RankManager rankManager; + private NameTagManager nameTagManager; + + public RankManager getRankManager() { + return rankManager; + } + public NameTagManager getNameTagManager() { return nameTagManager; } @Override public void onEnable() { // Plugin startup logic @@ -34,6 +51,7 @@ public final class Main extends JavaPlugin implements Listener { getCommand("gun").setExecutor(new GunCommand()); getCommand("msg").setExecutor(new MessageCommand()); getCommand("menu").setExecutor(new MenuCommand()); + getCommand("rank").setExecutor(new RankCommand(this)); bossbar = Bukkit.createBossBar( ChatColor.GOLD + "Kuudra", BarColor.RED, @@ -41,6 +59,25 @@ 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); + nameTagManager = new NameTagManager(this); + + ItemStack widow_sword = new ItemStack(Material.STICK); + widow_sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20); + widow_sword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 10); + widow_sword.addUnsafeEnchantment(Enchantment.LUCK, 10); + widow_sword.addUnsafeEnchantment(Enchantment.DURABILITY, 10); + ItemMeta wsMeta = widow_sword.getItemMeta(); + wsMeta.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Fabled Widow Sword"); + wsMeta.setUnbreakable(true); + widow_sword.setItemMeta(wsMeta); + ShapedRecipe wither_sword_recipe = new ShapedRecipe(new NamespacedKey(this, "widow_sword"), widow_sword); + wither_sword_recipe.shape(" A ", " A "," B "); + wither_sword_recipe.setIngredient('A', Material.IRON_INGOT); + wither_sword_recipe.setIngredient('B', Material.STICK); + Bukkit.addRecipe(wither_sword_recipe); } @EventHandler @@ -59,7 +96,7 @@ public final class Main extends JavaPlugin implements Listener { @EventHandler public void onJoin(PlayerJoinEvent e) { - e.setJoinMessage(ChatColor.RED+"[ADMIN] " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!"); + e.setJoinMessage(rankManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!"); e.getPlayer().sendTitle(ChatColor.RED +"Welcome to Operation Valkyrie!", ChatColor.GREEN + "LOL", 20, 100, 20); e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("ยง1NOT ENOUGH MANNER")); @@ -83,9 +120,9 @@ public final class Main extends JavaPlugin implements Listener { @EventHandler public void onPing(ServerListPingEvent e) { e.setMaxPlayers(8964); - String s = centerText("Operation Valkyrie [1.18.1 & 1.8.9]\n", 45); + String s = centerText("Operation Valkyrie\n", 45); String s2 = centerText("Support 1.18 & 1.8.9",45); - e.setMotd(ChatColor.AQUA.toString() + ChatColor.BOLD + s + ChatColor.GOLD + ChatColor.BOLD + s2); + e.setMotd(ChatColor.AQUA.toString() + ChatColor.BOLD + s + ChatColor.GOLD + ChatColor.BOLD + s2); try { e.setServerIcon(Bukkit.loadServerIcon(new File("nuke.png"))); } catch (Exception ee) { @@ -93,4 +130,6 @@ public final class Main extends JavaPlugin implements Listener { } } + + } diff --git a/src/main/java/com/night/nullvalkyrie/NameTag/NameTagManager.java b/src/main/java/com/night/nullvalkyrie/NameTag/NameTagManager.java new file mode 100644 index 0000000..339457d --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/NameTag/NameTagManager.java @@ -0,0 +1,46 @@ +package com.night.nullvalkyrie.NameTag; + +import com.night.nullvalkyrie.Main; +import com.night.nullvalkyrie.RankSys.Rank; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; + +public class NameTagManager { + private Main main; + + public NameTagManager(Main main) { + this.main = main; + } + 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()); + for (Rank rank : Rank.values()) { + Team team = player.getScoreboard().registerNewTeam(rank.name()); + team.setPrefix(rank.getDisplay() + " "); + } + for (Player target : Bukkit.getOnlinePlayers()) { + if (player.getUniqueId() != target.getUniqueId()) { + Rank rank = main.getRankManager().getRank(target.getUniqueId()); + player.getScoreboard().getTeam(rank.name()).addEntry(target.getName()); + } + } + } + public void newTag(Player player) { + Rank rank = main.getRankManager().getRank(player.getUniqueId()); + for(Player target : Bukkit.getOnlinePlayers()) { + target.getScoreboard().getTeam(rank.name()).addEntry(player.getName()); + } + } + public void removeTag(Player player) { + Rank rank = main.getRankManager().getRank(player.getUniqueId()); + for(Player target : Bukkit.getOnlinePlayers()) { + target.getScoreboard().getEntryTeam(player.getName()).removeEntry(player.getName()); + } + } +} diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/Rank.java b/src/main/java/com/night/nullvalkyrie/RankSys/Rank.java new file mode 100644 index 0000000..efc0040 --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/RankSys/Rank.java @@ -0,0 +1,20 @@ +package com.night.nullvalkyrie.RankSys; + +import org.bukkit.ChatColor; + +public enum Rank { + OWNER(ChatColor.DARK_RED + "{OWNER}"), + ADMIN(ChatColor.RED + "{ADMIN}"), + SPECIAL(ChatColor.GOLD + "{SPECIAL}"), + ROOKIE(ChatColor.DARK_GREEN + "{ROOKIE}"); + + private String display; + + Rank(String display) { + this.display = display; + } + + public String getDisplay() { + return display; + } +} diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/RankListener.java b/src/main/java/com/night/nullvalkyrie/RankSys/RankListener.java new file mode 100644 index 0000000..b3b2257 --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/RankSys/RankListener.java @@ -0,0 +1,42 @@ +package com.night.nullvalkyrie.RankSys; + +import com.night.nullvalkyrie.Main; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class RankListener implements Listener { + + private Main main; + public RankListener(Main main) { + this.main = main; + } + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + Player player = e.getPlayer(); + if(!player.hasPlayedBefore()) { + main.getRankManager().setRank(player.getUniqueId(), Rank.ROOKIE); + } + main.getNameTagManager().setNametags(player); + main.getNameTagManager().newTag(player); + } + + @EventHandler + public void onQuit(PlayerQuitEvent e) { + e.setQuitMessage(ChatColor.RED + "bozo " + e.getPlayer().getName() + " has left."); + main.getNameTagManager().removeTag(e.getPlayer()); + } + + @EventHandler + public void onChat(AsyncPlayerChatEvent e) { + e.setCancelled(true); + Player player = e.getPlayer(); + Bukkit.broadcastMessage(main.getRankManager().getRank(player.getUniqueId()).getDisplay() + " " + player.getName() + ChatColor.WHITE + ": " + e.getMessage()); + } +} diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java b/src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java new file mode 100644 index 0000000..e51e4ed --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java @@ -0,0 +1,49 @@ +package com.night.nullvalkyrie.RankSys; + +import com.night.nullvalkyrie.Main; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +public class RankManager { + private File file; + private YamlConfiguration config; + + private Main main; + + public RankManager(Main main) { + this.main = main; + if(!main.getDataFolder().exists()) { + main.getDataFolder().mkdir(); + } + file = new File(main.getDataFolder(), "ranks.yml"); + if(!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + config = YamlConfiguration.loadConfiguration(file); + } + public void setRank(UUID uuid, Rank rank) { + config.set(uuid.toString(), rank.name()); + try { + config.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + if(Bukkit.getOfflinePlayer(uuid).isOnline()) { + Player player = Bukkit.getPlayer(uuid); + main.getNameTagManager().removeTag(player); + main.getNameTagManager().newTag(player); + } + } + public Rank getRank(UUID uuid) { + return Rank.valueOf(config.getString(uuid.toString())); + } +} diff --git a/src/main/java/com/night/nullvalkyrie/SideBar/SideBarListener.java b/src/main/java/com/night/nullvalkyrie/SideBar/SideBarListener.java new file mode 100644 index 0000000..a7bc5ea --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/SideBar/SideBarListener.java @@ -0,0 +1,57 @@ +package com.night.nullvalkyrie.SideBar; + +import com.night.nullvalkyrie.Main; +import org.bukkit.Bukkit; +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.PlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scoreboard.*; + +import java.util.HashMap; +import java.util.UUID; + +public class SideBarListener implements Listener { + private Main main; + public SideBarListener(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(); + Objective obj = board.registerNewObjective("Pluto", "dummy"); + obj.setDisplaySlot(DisplaySlot.SIDEBAR); + obj.setDisplayName(ChatColor.AQUA.toString() + ChatColor.BOLD + "Pluto"); + 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: "); + playersOnline.setSuffix(ChatColor.YELLOW + "0"); + obj.getScore(ChatColor.BOLD.toString()).setScore(3); + player.setScoreboard(board); + deaths.put(player.getUniqueId(), 0); + } + + @EventHandler + public void onDeath(PlayerDeathEvent e) { + Player player = e.getEntity().getPlayer(); + 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/RankCommand.java b/src/main/java/com/night/nullvalkyrie/commands/RankCommand.java new file mode 100644 index 0000000..7fdbc71 --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/commands/RankCommand.java @@ -0,0 +1,49 @@ +package com.night.nullvalkyrie.commands; + +import com.night.nullvalkyrie.Main; +import com.night.nullvalkyrie.RankSys.Rank; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +//92.0.69.141:25565 +public class RankCommand implements CommandExecutor { + private Main main; + public RankCommand(Main main) { + this.main = main; + } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(sender instanceof Player) { + Player player = (Player) sender; + if(player.isOp()) { + if(args.length == 2) { + if(Bukkit.getOfflinePlayer(args[0]).hasPlayedBefore()) { + OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); + for(Rank rank : Rank.values()) { + if(rank.name().equalsIgnoreCase(args[1])) { + main.getRankManager().setRank(target.getUniqueId(), rank); + player.sendMessage(ChatColor.GREEN + "You changed " + target.getName() + "'s rank to " + rank.getDisplay()); + if(target.isOnline()) { + target.getPlayer().sendMessage(ChatColor.GREEN + player.getName() + " set your rank to " + rank.getDisplay()); + } + return true; + } + } + player.sendMessage(ChatColor.RED + "Invalid Rank, please specify a valid rank, ROOKIE, SPECIAL, ADMIN, OWNER"); + } else { + player.sendMessage("This player has never played in this server before!"); + } + } else { + player.sendMessage(ChatColor.RED + "Invalid parameter, use /rank "); + } + } else { + player.sendMessage(ChatColor.RED + "You must be server operator to use this command"); + } + } + return false; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9ba9ffb..b69ed6c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -17,4 +17,6 @@ commands: msg: description: "Send message to someone" menu: - description: "Open the menu" \ No newline at end of file + description: "Open the menu" + rank: + description: "Set rank of players" \ No newline at end of file