From abbaff1d0aab9c0e09bcaa03e625dcf6d97fa402 Mon Sep 17 00:00:00 2001 From: NK Date: Thu, 17 Nov 2022 11:03:45 +0000 Subject: [PATCH] formatted code on commands --- .../nullvalkyrie/commands/AnvilCommand.java | 4 -- .../nullvalkyrie/commands/ArmorCommand.java | 22 +++---- .../nullvalkyrie/commands/CraftCommand.java | 3 +- .../commands/EnchantingCommand.java | 2 +- .../commands/HologramCommand.java | 6 +- .../nullvalkyrie/commands/MenuCommand.java | 7 +-- .../nullvalkyrie/commands/MessageCommand.java | 12 ++-- .../nullvalkyrie/commands/MinerCommand.java | 5 +- .../nullvalkyrie/commands/RankCommand.java | 59 +++++++++---------- .../nullvalkyrie/commands/ShopCommand.java | 6 +- .../nullvalkyrie/commands/TestCommand.java | 8 +-- .../nullvalkyrie/commands/UtilCommand.java | 22 +++---- .../nullvalkyrie/commands/VanishCommand.java | 10 ++-- 13 files changed, 82 insertions(+), 84 deletions(-) diff --git a/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java b/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java index 2723bff..fb125b1 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java @@ -1,15 +1,11 @@ package me.night.nullvalkyrie.commands; - import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow; import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.network.PlayerConnection; import net.minecraft.world.inventory.Containers; import org.bukkit.command.CommandSender; -//import org.bukkit.craftbukkit.v1_18_R1.entity.CraftHumanEntity; -//import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; -//import org.bukkit.craftbukkit.v1_18_R1.util.CraftChatMessage; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage; import org.bukkit.entity.Player; diff --git a/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java b/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java index 2d5cb16..afb3fa6 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/ArmorCommand.java @@ -25,36 +25,36 @@ public class ArmorCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { + if (sender instanceof Player) { Player player = (Player) sender; ItemStack helmet = new ItemStack(Material.LEATHER_HELMET); LeatherArmorMeta helmetdata = (LeatherArmorMeta) helmet.getItemMeta(); helmetdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Angeles Helmet"); - helmetdata.setColor(org.bukkit.Color.fromRGB(2,2,58)); + helmetdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); helmetdata.setUnbreakable(true); helmet.setItemMeta(helmetdata); player.getInventory().addItem(helmet); ItemStack cp = new ItemStack(Material.LEATHER_CHESTPLATE); - LeatherArmorMeta cpdata = (LeatherArmorMeta) cp.getItemMeta(); + LeatherArmorMeta cpdata = (LeatherArmorMeta) cp.getItemMeta(); cpdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Angeles Chestplate"); - cpdata.setColor(org.bukkit.Color.fromRGB(2,2,58)); + cpdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); cpdata.setUnbreakable(true); cp.setItemMeta(cpdata); player.getInventory().addItem(cp); ItemStack leg = new ItemStack(Material.LEATHER_LEGGINGS); - LeatherArmorMeta legdata = (LeatherArmorMeta) leg.getItemMeta(); + LeatherArmorMeta legdata = (LeatherArmorMeta) leg.getItemMeta(); legdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Angeles Leggings"); - legdata.setColor(org.bukkit.Color.fromRGB(2,2,58)); + legdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); legdata.setUnbreakable(true); leg.setItemMeta(legdata); player.getInventory().addItem(leg); ItemStack boot = new ItemStack(Material.LEATHER_BOOTS); - LeatherArmorMeta bootdata = (LeatherArmorMeta) boot.getItemMeta(); + LeatherArmorMeta bootdata = (LeatherArmorMeta) boot.getItemMeta(); bootdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Angeles Boots"); - bootdata.setColor(org.bukkit.Color.fromRGB(2,2,58)); + bootdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); bootdata.setUnbreakable(true); boot.setItemMeta(legdata); player.getInventory().addItem(boot); @@ -63,11 +63,11 @@ public class ArmorCommand extends Command { @Override public List onTabComplete(CommandSender sender, String[] args) { - if(args.length == 1) { + if (args.length == 1) { return StringUtil.copyPartialMatches(args[0], Arrays.asList("angeles", "widow"), new ArrayList<>()); - } else if(args.length == 2) { + } else if (args.length == 2) { List names = new ArrayList<>(); - for(Player player: Bukkit.getOnlinePlayers()) { + for (Player player : Bukkit.getOnlinePlayers()) { names.add(player.getName()); } return StringUtil.copyPartialMatches(args[1], names, new ArrayList<>()); diff --git a/src/main/java/me/night/nullvalkyrie/commands/CraftCommand.java b/src/main/java/me/night/nullvalkyrie/commands/CraftCommand.java index 338c43d..3bbddca 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/CraftCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/CraftCommand.java @@ -1,6 +1,5 @@ package me.night.nullvalkyrie.commands; - import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -19,7 +18,7 @@ public class CraftCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { + if (sender instanceof Player) { Player player = (Player) sender; 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 1bd3994..c9d65ac 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/EnchantingCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/EnchantingCommand.java @@ -17,7 +17,7 @@ public class EnchantingCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { + if (sender instanceof Player) { Player player = (Player) sender; 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 04f5b9e..8269af5 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java @@ -20,7 +20,7 @@ public class HologramCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { + if (sender instanceof Player) { Player player = (Player) sender; String[] ar = new String[]{ ChatColor.AQUA + "Hi", @@ -28,8 +28,8 @@ public class HologramCommand extends Command { 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 -> { + for (String line : ar) { + ArmorStand stand = location.getWorld().spawn(location.subtract(0, 0.3, 0), ArmorStand.class, armorStand -> { armorStand.setVisible(false); }); stand.setGravity(false); diff --git a/src/main/java/me/night/nullvalkyrie/commands/MenuCommand.java b/src/main/java/me/night/nullvalkyrie/commands/MenuCommand.java index 7705654..8c00eb2 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/MenuCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/MenuCommand.java @@ -26,9 +26,9 @@ public class MenuCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { + if (sender instanceof Player) { Player player = (Player) sender; - inv = Bukkit.createInventory(player,45, ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu"); + inv = Bukkit.createInventory(player, 45, ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu"); ItemStack KYS = new ItemStack(Material.WOODEN_SWORD); ItemMeta KYSmeta = KYS.getItemMeta(); @@ -59,10 +59,9 @@ public class MenuCommand extends Command { inv.setItem(0, close); ItemStack frame = new ItemStack(Material.BLUE_STAINED_GLASS_PANE); - for(int i : new int[]{1,2,3,4,5,6,7,8,9,17,18,26,27,35,36,37,38,39,40,41,42,43,44}) { + for (int i : new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44}) { inv.setItem(i, frame); } - player.openInventory(inv); } diff --git a/src/main/java/me/night/nullvalkyrie/commands/MessageCommand.java b/src/main/java/me/night/nullvalkyrie/commands/MessageCommand.java index b20fe3f..8801e47 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/MessageCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/MessageCommand.java @@ -21,14 +21,14 @@ public class MessageCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { + if (sender instanceof Player) { Player player = (Player) sender; if (args.length >= 2) { - if(Bukkit.getPlayerExact(args[0]) != null) { + if (Bukkit.getPlayerExact(args[0]) != null) { Player target = Bukkit.getPlayerExact(args[0]); - if(!target.equals(player)) { + if (!target.equals(player)) { StringBuilder builder = new StringBuilder(); - for(int i = 1; i < args.length; i++) { + for (int i = 1; i < args.length; i++) { builder.append(args[i]).append(" "); } player.sendMessage(ChatColor.DARK_AQUA + "TO " + ChatColor.RED + target.getName() + ChatColor.WHITE + " : " + builder); @@ -47,9 +47,9 @@ public class MessageCommand extends Command { @Override public List onTabComplete(CommandSender sender, String[] args) { - if(args.length == 1) { + if (args.length == 1) { List names = new ArrayList<>(); - for(Player player: Bukkit.getOnlinePlayers()) { + for (Player player : Bukkit.getOnlinePlayers()) { names.add(player.getName()); } return StringUtil.copyPartialMatches(args[0], names, new ArrayList<>()); diff --git a/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java b/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java index d9b2df4..c1874ea 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java @@ -13,6 +13,7 @@ import static me.night.nullvalkyrie.miners.CryptoMiner.getMiner; public class MinerCommand extends Command { private final Main main; + public MinerCommand(Main main) { super( "miner", @@ -25,10 +26,10 @@ public class MinerCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { + if (sender instanceof Player) { Player player = (Player) sender; new MinerGUI(main, player); - int seconds = Math.round((new Date().getTime() - (long) getMiner("1").get("lastclaim")) / 1000); + int seconds = (int) (new Date().getTime() - (long) getMiner("1").get("lastclaim")) / 1000; System.out.println("Seconds" + seconds); generate(50, seconds); } diff --git a/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java b/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java index 840b60a..706613c 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java @@ -18,53 +18,52 @@ import java.util.concurrent.TimeUnit; import static me.night.nullvalkyrie.rank.ScoreboardListener.rankManager; -//92.0.69.141:25565 public class RankCommand extends Command { - private Main main; - public RankCommand(Main main) { + + public RankCommand() { super( "rank", new String[]{}, "Set rank of players", "" ); - this.main = main; } - private Cache cooldown = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.SECONDS).build(); + + private final Cache cooldown = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.SECONDS).build(); @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { + if (sender instanceof Player) { Player player = (Player) sender; - if(!cooldown.asMap().containsKey(player.getUniqueId())) { - 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])) { - rankManager.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()); + if (!cooldown.asMap().containsKey(player.getUniqueId())) { + 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])) { + rankManager.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; } - return; - } + } + 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!"); } - 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!"); + player.sendMessage(ChatColor.RED + "Invalid parameter, use /rank "); } } else { - player.sendMessage(ChatColor.RED + "Invalid parameter, use /rank "); + player.sendMessage(ChatColor.RED + "You must be server operator to use this command"); } - } else { - player.sendMessage(ChatColor.RED + "You must be server operator to use this command"); - } cooldown.put(player.getUniqueId(), System.currentTimeMillis() + 5000); - } else { + } else { long distance = cooldown.asMap().get(player.getUniqueId()) - System.currentTimeMillis(); player.sendMessage(ChatColor.RED + "You are on a " + TimeUnit.MILLISECONDS.toSeconds(distance) + " seconds cooldown to use the command again"); } @@ -73,15 +72,15 @@ public class RankCommand extends Command { @Override public List onTabComplete(CommandSender sender, String[] args) { - if(args.length == 1) { + if (args.length == 1) { List names = new ArrayList<>(); - for(Player player: Bukkit.getOnlinePlayers()) { + for (Player player : Bukkit.getOnlinePlayers()) { names.add(player.getName()); } return StringUtil.copyPartialMatches(args[0], names, new ArrayList<>()); - } else if(args.length == 2) { + } else if (args.length == 2) { List roles = new ArrayList<>(); - for(Rank rank : Rank.values()){ + for (Rank rank : Rank.values()) { roles.add(rank.name()); } return StringUtil.copyPartialMatches(args[1], roles, new ArrayList<>()); diff --git a/src/main/java/me/night/nullvalkyrie/commands/ShopCommand.java b/src/main/java/me/night/nullvalkyrie/commands/ShopCommand.java index ddb7a82..b21bf09 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/ShopCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/ShopCommand.java @@ -13,9 +13,10 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.List; -public class ShopCommand extends Command{ +public class ShopCommand extends Command { private FileConfiguration file; private Inventory inv; + public ShopCommand() { super("7elven", new String[]{"711", "seven", "7ven"}, @@ -24,10 +25,11 @@ public class ShopCommand extends Command{ ); file = CustomItemManager.loadConfig("miners.yml"); } + @Override public void onCommand(CommandSender sender, String[] args) { inv = Bukkit.createInventory(null, 45, ChatColor.GREEN + "7-Eleven 24/7"); - for(String c : file.getKeys(false)) { + for (String c : file.getKeys(false)) { ItemStack item = new ItemStack(Material.matchMaterial(file.getString(c + ".material"))); ItemMeta itemMeta = item.getItemMeta(); itemMeta.setDisplayName(file.getString(c + ".name")); diff --git a/src/main/java/me/night/nullvalkyrie/commands/TestCommand.java b/src/main/java/me/night/nullvalkyrie/commands/TestCommand.java index a080fbe..ad0b693 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/TestCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/TestCommand.java @@ -1,6 +1,5 @@ package me.night.nullvalkyrie.commands; - import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,11 +14,12 @@ public class TestCommand extends Command { "" ); } + @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { - if(args.length == 1) { - if(args[0].equalsIgnoreCase("hello")) { + if (sender instanceof Player) { + if (args.length == 1) { + if (args[0].equalsIgnoreCase("hello")) { Player player = (Player) sender; player.sendMessage(player.getAddress().getHostString()); } diff --git a/src/main/java/me/night/nullvalkyrie/commands/UtilCommand.java b/src/main/java/me/night/nullvalkyrie/commands/UtilCommand.java index c59a756..8012617 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/UtilCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/UtilCommand.java @@ -15,8 +15,8 @@ import java.util.List; import java.util.Objects; public class UtilCommand extends Command { - private Main main; - public UtilCommand(Main main) { + + public UtilCommand() { super( "util", new String[]{}, @@ -24,15 +24,15 @@ public class UtilCommand extends Command { "" ); - this.main = main; } + @Override public void onCommand(CommandSender sender, String[] args) { Player player = (Player) sender; StringBuilder s = new StringBuilder(); List b = Arrays.asList(args); - for(String a: args) { - if(a.equals(b.get(b.size() - 1))) { + for (String a : args) { + if (a.equals(b.get(b.size() - 1))) { s.append(a); } else { s.append(a); @@ -40,8 +40,8 @@ public class UtilCommand extends Command { } } - ItemStack item = main.getCustomItemManager().getItem(s.toString()); - if(item.hasItemMeta()) { + ItemStack item = CustomItemManager.getItem(s.toString()); + if (item.hasItemMeta()) { player.getInventory().addItem(item); } else { player.sendMessage(ChatColor.RED + "This item doesn't exist"); @@ -50,12 +50,12 @@ public class UtilCommand extends Command { @Override public List onTabComplete(CommandSender sender, String[] args) { - if(args.length == 1) { + if (args.length == 1) { List hh = CustomItemManager.getAllFilesFromDirectory("ItemData"); ArrayList cc = new ArrayList<>(); - for(int kk = 0; kk < hh.size(); kk++) { - FileConfiguration c = CustomItemManager.loadConfig("ItemData\\" + hh.get(kk)); - if(Objects.equals(c.getString("type"), "Util")) { + for (String s : hh) { + FileConfiguration c = CustomItemManager.loadConfig("ItemData\\" + s); + if (Objects.equals(c.getString("type"), "Util")) { cc.add(c.getString("name")); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java b/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java index 48e0a4a..9e8b852 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/VanishCommand.java @@ -11,19 +11,21 @@ import java.util.UUID; public class VanishCommand extends Command { private final List vanished = new ArrayList<>(); + public VanishCommand() { super( "vanish", new String[]{}, "Turn yourself into invisible", "" - ); + ); } + @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { + if (sender instanceof Player) { Player player = (Player) sender; - if(vanished.contains(player.getUniqueId())) { + if (vanished.contains(player.getUniqueId())) { vanished.remove(player.getUniqueId()); for (Player target : Bukkit.getOnlinePlayers()) { target.showPlayer(player); @@ -31,7 +33,7 @@ public class VanishCommand extends Command { player.sendMessage(ChatColor.GREEN + "You are now seen by people"); } else { vanished.add(player.getUniqueId()); - for (Player target: Bukkit.getOnlinePlayers()){ + for (Player target : Bukkit.getOnlinePlayers()) { target.hidePlayer(player); } player.sendMessage(ChatColor.GREEN + "You are now vanished");