From 95db3dc0e38143ca17df8654c13e19472269e98b Mon Sep 17 00:00:00 2001 From: NK Date: Sat, 3 Dec 2022 10:47:07 +0000 Subject: [PATCH] Revert "Revert "formatting"" This reverts commit 42fb26475c78b9a0d99e32bb3dcd5e7ab9064ec8. --- src/main/java/me/night/nullvalkyrie/Main.java | 2 ++ .../nullvalkyrie/commands/AnvilCommand.java | 26 +++++-------------- .../nullvalkyrie/commands/ArmorCommand.java | 10 ++----- .../nullvalkyrie/commands/BetaCommand.java | 3 ++- .../night/nullvalkyrie/commands/Command.java | 3 ++- .../nullvalkyrie/commands/CraftCommand.java | 10 ++----- .../commands/EnchantingCommand.java | 10 ++----- .../commands/HologramCommand.java | 16 +++--------- .../nullvalkyrie/commands/MessageCommand.java | 10 ++----- .../nullvalkyrie/commands/MinerCommand.java | 7 +---- .../nullvalkyrie/commands/RankCommand.java | 7 +---- .../nullvalkyrie/commands/TestCommand.java | 7 +---- .../nullvalkyrie/commands/VanishCommand.java | 10 ++----- .../discord/DiscordClientManager.java | 3 +++ .../enchantments/CustomEnchantment.java | 1 + .../enchantments/EnchantmentManager.java | 5 ++-- .../nullvalkyrie/ui/AnimatedSideBar.java | 4 +++ .../java/me/night/nullvalkyrie/ui/Rank.java | 5 +--- .../night/nullvalkyrie/ui/SideBarManager.java | 7 +++-- src/main/resources/plugin.yml | 2 +- 20 files changed, 47 insertions(+), 101 deletions(-) diff --git a/src/main/java/me/night/nullvalkyrie/Main.java b/src/main/java/me/night/nullvalkyrie/Main.java index 2f1a081..ac91bef 100644 --- a/src/main/java/me/night/nullvalkyrie/Main.java +++ b/src/main/java/me/night/nullvalkyrie/Main.java @@ -14,9 +14,11 @@ import me.night.nullvalkyrie.commands.*; import me.night.nullvalkyrie.database.DatabaseManager; import org.bukkit.*; import org.bukkit.plugin.java.JavaPlugin; + public final class Main extends JavaPlugin { public static Dotenv env; public static MongoDatabase database; + @Override public void onEnable() { EnchantmentManager.register(); diff --git a/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java b/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java index 750697b..5c41c42 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java @@ -1,37 +1,25 @@ package me.night.nullvalkyrie.commands; -import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow; -import net.minecraft.server.level.EntityPlayer; -import net.minecraft.world.inventory.Containers; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; import java.util.List; public class AnvilCommand extends Command { public AnvilCommand() { - super( - "anvil", - new String[]{"av"}, - "Open anvil", - "" - ); + super("anvil", new String[]{"av"}, "Open anvil", ""); } @Override public void onCommand(CommandSender sender, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - CraftPlayer craftPlayer = (CraftPlayer) player; -// EntityPlayer entityPlayer = craftPlayer.getHandle(); -// int id = 0; -// PacketPlayOutOpenWindow OpenWindow = new PacketPlayOutOpenWindow(id, Containers.h, CraftChatMessage.fromStringOrNull("Test")); -// PlayerConnection playerConnection = entityPlayer.b; -// playerConnection.a(OpenWindow); + if (sender instanceof Player player) { + Inventory av = Bukkit.createInventory(null, InventoryType.ANVIL, "AV"); + player.openInventory(av); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java b/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java index afb3fa6..220d625 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java @@ -15,18 +15,12 @@ import java.util.List; public class ArmorCommand extends Command { public ArmorCommand() { - super( - "armor", - new String[]{}, - "Give you a set of armor", - "" - ); + super("armor", new String[]{}, "Give you a set of armor", ""); } @Override public void onCommand(CommandSender sender, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; + if (sender instanceof Player player) { ItemStack helmet = new ItemStack(Material.LEATHER_HELMET); LeatherArmorMeta helmetdata = (LeatherArmorMeta) helmet.getItemMeta(); helmetdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Angeles Helmet"); diff --git a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java index 48423d6..453ec37 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java @@ -13,9 +13,10 @@ public class BetaCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { - if (sender instanceof Player) { + if (sender instanceof Player player) { } } + @Override public List onTabComplete(CommandSender sender, String[] args) { return null; diff --git a/src/main/java/me/night/nullvalkyrie/commands/Command.java b/src/main/java/me/night/nullvalkyrie/commands/Command.java index 00c225c..328a61d 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/Command.java +++ b/src/main/java/me/night/nullvalkyrie/commands/Command.java @@ -1,7 +1,6 @@ package me.night.nullvalkyrie.commands; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; @@ -39,6 +38,8 @@ public abstract class Command extends BukkitCommand { public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { return onTabComplete(sender, args); } + public abstract void onCommand(CommandSender sender, String[] args); + public abstract List onTabComplete(CommandSender sender, String[] args); } diff --git a/src/main/java/me/night/nullvalkyrie/commands/CraftCommand.java b/src/main/java/me/night/nullvalkyrie/commands/CraftCommand.java index 3bbddca..1d5dbfc 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/CraftCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/CraftCommand.java @@ -8,18 +8,12 @@ import java.util.List; public class CraftCommand extends Command { public CraftCommand() { - super( - "craft", - new String[]{"ct", "crafting", "craftingtable"}, - "Open crafting table", - "" - ); + super("craft", new String[]{"ct", "crafting", "craftingtable"}, "Open crafting table", ""); } @Override public void onCommand(CommandSender sender, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; + if (sender instanceof Player player) { player.openWorkbench(null, true); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/EnchantingCommand.java b/src/main/java/me/night/nullvalkyrie/commands/EnchantingCommand.java index c9d65ac..7d7d24b 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/EnchantingCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/EnchantingCommand.java @@ -7,18 +7,12 @@ import java.util.List; public class EnchantingCommand extends Command { public EnchantingCommand() { - super( - "enchant", - new String[]{"et", "enchanting", "enchantingtable"}, - "Open enchanting table", - "" - ); + super("enchant", new String[]{"et", "enchanting", "enchantingtable"}, "Open enchanting table", ""); } @Override public void onCommand(CommandSender sender, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; + if (sender instanceof Player player) { player.openEnchanting(player.getLocation(), true); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java b/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java index 8269af5..3b4ace8 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java @@ -10,23 +10,13 @@ import java.util.List; public class HologramCommand extends Command { public HologramCommand() { - super( - "hologram", - new String[]{}, - "Spawn a hologram", - "" - ); + super("hologram", new String[]{}, "Spawn a hologram", ""); } @Override public void onCommand(CommandSender sender, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - String[] ar = new String[]{ - ChatColor.AQUA + "Hi", - ChatColor.DARK_PURPLE + "What", - ChatColor.GOLD + "Hello World" - }; + if (sender instanceof Player player) { + String[] ar = new String[]{ChatColor.AQUA + "Hi", ChatColor.DARK_PURPLE + "What", ChatColor.GOLD + "Hello World"}; Location location = player.getLocation(); for (String line : ar) { ArmorStand stand = location.getWorld().spawn(location.subtract(0, 0.3, 0), ArmorStand.class, armorStand -> { diff --git a/src/main/java/me/night/nullvalkyrie/commands/MessageCommand.java b/src/main/java/me/night/nullvalkyrie/commands/MessageCommand.java index 8801e47..9344559 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/MessageCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/MessageCommand.java @@ -11,18 +11,12 @@ import java.util.List; public class MessageCommand extends Command { public MessageCommand() { - super( - "message", - new String[]{"msg"}, - "Send message to someone", - "" - ); + super("message", new String[]{"msg"}, "Send message to someone", ""); } @Override public void onCommand(CommandSender sender, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; + if (sender instanceof Player player) { if (args.length >= 2) { if (Bukkit.getPlayerExact(args[0]) != null) { Player target = Bukkit.getPlayerExact(args[0]); diff --git a/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java b/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java index 419051b..36cfd58 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java @@ -14,12 +14,7 @@ import static me.night.nullvalkyrie.miners.CryptoMiner.generate; public class MinerCommand extends Command { public MinerCommand() { - super( - "miner", - new String[]{"m", "miners"}, - "Miner list", - "" - ); + super("miner", new String[]{"m", "miners"}, "Miner list", ""); } @Override diff --git a/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java b/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java index 1920075..2805337 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java @@ -15,12 +15,7 @@ import java.util.List; public class RankCommand extends Command { public RankCommand() { - super( - "rank", - new String[]{}, - "Set rank of players", - "nv.rank.add" - ); + super("rank", new String[]{}, "Set rank of players", "nv.rank.add"); } diff --git a/src/main/java/me/night/nullvalkyrie/commands/TestCommand.java b/src/main/java/me/night/nullvalkyrie/commands/TestCommand.java index ad0b693..8665dc0 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/TestCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/TestCommand.java @@ -7,12 +7,7 @@ import java.util.List; public class TestCommand extends Command { public TestCommand() { - super( - "test", - new String[]{}, - "Test", - "" - ); + super("test", new String[]{}, "Test", ""); } @Override diff --git a/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java b/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java index 9e8b852..c0fb3ce 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java @@ -13,18 +13,12 @@ public class VanishCommand extends Command { private final List vanished = new ArrayList<>(); public VanishCommand() { - super( - "vanish", - new String[]{}, - "Turn yourself into invisible", - "" - ); + super("vanish", new String[]{}, "Turn yourself into invisible", ""); } @Override public void onCommand(CommandSender sender, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; + if (sender instanceof Player player) { if (vanished.contains(player.getUniqueId())) { vanished.remove(player.getUniqueId()); for (Player target : Bukkit.getOnlinePlayers()) { diff --git a/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java b/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java index 41b2de6..0916bc7 100644 --- a/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java +++ b/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java @@ -1,4 +1,5 @@ package me.night.nullvalkyrie.discord; + import me.night.nullvalkyrie.Main; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; @@ -9,9 +10,11 @@ import javax.security.auth.login.LoginException; public class DiscordClientManager { private JDA jda; + public DiscordClientManager() { register(); } + public void register() { JDABuilder builder = JDABuilder.createDefault(Main.env.get("DISCORD_TOKEN")); builder.setActivity(Activity.streaming("cath.exe", "https://www.youtube.com/watch?v=YSKDu1gKntY")); diff --git a/src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java b/src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java index ca60e8f..45333d0 100644 --- a/src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java +++ b/src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull; public class CustomEnchantment extends Enchantment { private final String name; private final int max; + public CustomEnchantment(String namespace, String name, int lvl) { super(NamespacedKey.minecraft(namespace)); this.name = name; diff --git a/src/main/java/me/night/nullvalkyrie/enchantments/EnchantmentManager.java b/src/main/java/me/night/nullvalkyrie/enchantments/EnchantmentManager.java index 7199c99..28164b1 100644 --- a/src/main/java/me/night/nullvalkyrie/enchantments/EnchantmentManager.java +++ b/src/main/java/me/night/nullvalkyrie/enchantments/EnchantmentManager.java @@ -6,24 +6,25 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; public class EnchantmentManager { public static final Enchantment ThunderBolt = new CustomEnchantment("thunderbolt", "ThunderBolt", 5); public static final Enchantment SmeltingTouch = new CustomEnchantment("smelting-touch", "Smelting Touch", 1); + public static void register() { List enchants = new ArrayList<>(); enchants.add(ThunderBolt); enchants.add(SmeltingTouch); List registeredList = new ArrayList<>(); for (Enchantment enchant : enchants) { - registeredList.add(Arrays.stream(Enchantment.values()).collect(Collectors.toList()).contains(enchant)); + registeredList.add(Arrays.stream(Enchantment.values()).toList().contains(enchant)); } for (int counter = 0; counter < registeredList.size(); counter++) { if (!registeredList.get(counter)) registerEnchantment(enchants.get(counter)); } } + public static void registerEnchantment(Enchantment en) { try { try { diff --git a/src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java b/src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java index 0e99fca..6379036 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java +++ b/src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java @@ -9,15 +9,19 @@ import java.util.UUID; public class AnimatedSideBar { private static final Map Tasks = new HashMap<>(); private final UUID uuid; + public AnimatedSideBar(UUID uuid) { this.uuid = uuid; } + public void setID(int id) { Tasks.put(uuid, id); } + public boolean hasID() { return Tasks.containsKey(uuid); } + public void stop() { Bukkit.getScheduler().cancelTask(Tasks.get(uuid)); } diff --git a/src/main/java/me/night/nullvalkyrie/ui/Rank.java b/src/main/java/me/night/nullvalkyrie/ui/Rank.java index 4faba34..2b8eca4 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/Rank.java +++ b/src/main/java/me/night/nullvalkyrie/ui/Rank.java @@ -3,10 +3,7 @@ package me.night.nullvalkyrie.ui; import org.bukkit.ChatColor; public enum Rank { - OWNER(ChatColor.DARK_RED + ""), - ADMIN(ChatColor.RED + ""), - SPECIAL(ChatColor.GOLD + ""), - ROOKIE(ChatColor.DARK_GREEN + ""); + OWNER(ChatColor.DARK_RED + ""), ADMIN(ChatColor.RED + ""), SPECIAL(ChatColor.GOLD + ""), ROOKIE(ChatColor.DARK_GREEN + ""); private final String display; diff --git a/src/main/java/me/night/nullvalkyrie/ui/SideBarManager.java b/src/main/java/me/night/nullvalkyrie/ui/SideBarManager.java index 0fd74d8..3a8f27a 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/SideBarManager.java +++ b/src/main/java/me/night/nullvalkyrie/ui/SideBarManager.java @@ -25,7 +25,8 @@ public class SideBarManager { 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 <<"); + 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); @@ -58,11 +59,13 @@ public class SideBarManager { board = new AnimatedSideBar(player.getUniqueId()); taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(main, new Runnable() { int count = 0; + public void animate(String str) { 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 <<"); + else + objective = board.registerNewObjective("Vanadium", Criteria.DUMMY, ChatColor.AQUA.toString() + ChatColor.BOLD + ">> Vanadium <<"); objective.setDisplaySlot(DisplaySlot.SIDEBAR); objective.setDisplayName(Util.color(str)); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0c91cbd..b04de34 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,7 @@ api-version: 1.18 authors: [ NightKaly, Leocthl ] description: Null Valkyrie website: https://github.com/night0721/nullvalkyrie -depend: [ProtocolLib] +depend: [ ProtocolLib ] permissions: nv.command.use: default: true