From b384782e2ee7dbe66407d9328985b515cac11c5b Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:14:24 -0500 Subject: [PATCH 1/5] Cleanup Every Command --- .../core/commands/SlimefunCommand.java | 2 + .../core/commands/SlimefunTabCompleter.java | 2 + .../commands/subcommands/BackpackCommand.java | 72 +++++++-------- .../commands/subcommands/ChargeCommand.java | 35 ++++---- .../commands/subcommands/CheatCommand.java | 16 ++-- .../commands/subcommands/DebugCommand.java | 5 +- .../subcommands/DebugFishCommand.java | 1 + .../commands/subcommands/GiveCommand.java | 75 ++++++++-------- .../commands/subcommands/GuideCommand.java | 19 ++-- .../commands/subcommands/HelpCommand.java | 1 + .../subcommands/OpenGuideCommand.java | 15 ++-- .../commands/subcommands/ResearchCommand.java | 64 +++++++------- .../commands/subcommands/SearchCommand.java | 28 +++--- .../commands/subcommands/StatsCommand.java | 33 ++++--- .../subcommands/TeleporterCommand.java | 47 +++++----- .../commands/subcommands/TimingsCommand.java | 33 +++---- .../commands/subcommands/VersionsCommand.java | 87 ++++++++++--------- 17 files changed, 292 insertions(+), 243 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunCommand.java index 4ef1a411a5..bc9d298e3f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunCommand.java @@ -7,6 +7,7 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; import org.apache.commons.lang.Validate; import org.bukkit.command.Command; @@ -68,6 +69,7 @@ public void register() { } @Override + @ParametersAreNonnullByDefault public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length > 0) { for (SubCommand command : commands) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java index 07ca70bf0c..906f32fcbb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java @@ -9,6 +9,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -30,6 +31,7 @@ public SlimefunTabCompleter(@Nonnull SlimefunCommand command) { @Nullable @Override + @ParametersAreNonnullByDefault public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { if (args.length == 1) { return createReturnList(command.getSubCommandNames(), args[0]); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java index 431d47cb66..9d86d9a7d4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; +import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Bukkit; @@ -34,52 +35,55 @@ class BackpackCommand extends SubCommand { } @Override + @Nonnull protected String getDescription() { return "commands.backpack.description"; } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player player) { - if (sender.hasPermission("slimefun.command.backpack")) { - if (args.length != 3) { - Slimefun.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf backpack ")); - return; - } + if (!(sender instanceof Player player)) { + Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true); + return; + } - if (!CommonPatterns.NUMERIC.matcher(args[2]).matches()) { - Slimefun.getLocalization().sendMessage(sender, "commands.backpack.invalid-id"); - return; - } + if (!sender.hasPermission("slimefun.command.backpack")) { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + return; + } - @SuppressWarnings("deprecation") - OfflinePlayer backpackOwner = Bukkit.getOfflinePlayer(args[1]); + if (args.length != 3) { + Slimefun.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf backpack ")); + return; + } - if (!(backpackOwner instanceof Player) && !backpackOwner.hasPlayedBefore()) { - Slimefun.getLocalization().sendMessage(sender, "commands.backpack.player-never-joined"); - return; - } + if (!CommonPatterns.NUMERIC.matcher(args[2]).matches()) { + Slimefun.getLocalization().sendMessage(sender, "commands.backpack.invalid-id"); + return; + } - int id = Integer.parseInt(args[2]); + @SuppressWarnings("deprecation") + OfflinePlayer backpackOwner = Bukkit.getOfflinePlayer(args[1]); + if (!(backpackOwner instanceof Player) && !backpackOwner.hasPlayedBefore()) { + Slimefun.getLocalization().sendMessage(sender, "commands.backpack.player-never-joined"); + return; + } - PlayerProfile.get(backpackOwner, profile -> { - if (!profile.getBackpack(id).isPresent()) { - Slimefun.getLocalization().sendMessage(sender, "commands.backpack.backpack-does-not-exist"); - return; - } + int id = Integer.parseInt(args[2]); - Slimefun.runSync(() -> { - ItemStack item = SlimefunItems.RESTORED_BACKPACK.clone(); - Slimefun.getBackpackListener().setBackpackId(backpackOwner, item, 2, id); - player.getInventory().addItem(item); - Slimefun.getLocalization().sendMessage(sender, "commands.backpack.restored-backpack-given"); - }); - }); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + PlayerProfile.get(backpackOwner, profile -> { + if (!profile.getBackpack(id).isPresent()) { + Slimefun.getLocalization().sendMessage(sender, "commands.backpack.backpack-does-not-exist"); + return; } - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true); - } + + Slimefun.runSync(() -> { + ItemStack item = SlimefunItems.RESTORED_BACKPACK.clone(); + Slimefun.getBackpackListener().setBackpackId(backpackOwner, item, 2, id); + player.getInventory().addItem(item); + Slimefun.getLocalization().sendMessage(sender, "commands.backpack.restored-backpack-given"); + }); + }); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java index 119091e1e6..e2485a35bc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; +import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.command.CommandSender; @@ -27,28 +28,32 @@ class ChargeCommand extends SubCommand { } @Override + @Nonnull protected String getDescription() { return "commands.charge.description"; } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player player) { - if (sender.hasPermission("slimefun.command.charge")) { - ItemStack item = player.getInventory().getItemInMainHand(); - SlimefunItem slimefunItem = SlimefunItem.getByItem(item); - - if (slimefunItem instanceof Rechargeable rechargeableItem) { - rechargeableItem.setItemCharge(item, rechargeableItem.getMaxItemCharge(item)); - Slimefun.getLocalization().sendMessage(sender, "commands.charge.charge-success", true); - } else { - Slimefun.getLocalization().sendMessage(sender, "commands.charge.not-rechargeable", true); - } - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); - } - } else { + if (!(sender instanceof Player player)) { Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true); + return; + } + + if (!sender.hasPermission("slimefun.command.charge")) { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + return; + } + + ItemStack item = player.getInventory().getItemInMainHand(); + SlimefunItem slimefunItem = SlimefunItem.getByItem(item); + + if (slimefunItem instanceof Rechargeable rechargeableItem) { + rechargeableItem.setItemCharge(item, rechargeableItem.getMaxItemCharge(item)); + Slimefun.getLocalization().sendMessage(sender, "commands.charge.charge-success", true); + } else { + Slimefun.getLocalization().sendMessage(sender, "commands.charge.not-rechargeable", true); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java index 973ed1ee39..1342c1f2a6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/CheatCommand.java @@ -18,15 +18,17 @@ class CheatCommand extends SubCommand { } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player player) { - if (sender.hasPermission("slimefun.cheat.items")) { - SlimefunGuide.openCheatMenu(player); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); - } - } else { + if (!(sender instanceof Player player)) { Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true); + return; + } + + if (sender.hasPermission("slimefun.cheat.items")) { + SlimefunGuide.openCheatMenu(player); + } else { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugCommand.java index 12c567cb14..833f716385 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugCommand.java @@ -1,6 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.command.CommandSender; @@ -22,11 +23,13 @@ protected DebugCommand(@Nonnull Slimefun plugin, @Nonnull SlimefunCommand cmd) { } @Override - protected @Nonnull String getDescription() { + @Nonnull + protected String getDescription() { return "commands.debug.description"; } @Override + @ParametersAreNonnullByDefault public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) { if (!sender.hasPermission("slimefun.command.debug")) { Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java index cc79b113e6..92acb319e5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugFishCommand.java @@ -18,6 +18,7 @@ class DebugFishCommand extends SubCommand { } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { if (sender instanceof Player player && sender.hasPermission("slimefun.debugging")) { player.getInventory().addItem(SlimefunItems.DEBUG_FISH.clone()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java index 5d56959e84..01b0452740 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java @@ -31,52 +31,55 @@ class GiveCommand extends SubCommand { } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { - if (sender.hasPermission("slimefun.cheat.items") || !(sender instanceof Player)) { - if (args.length > 2) { - Optional player = PlayerList.findByName(args[1]); - - if (player.isPresent()) { - Player p = player.get(); - - SlimefunItem sfItem = SlimefunItem.getById(args[2].toUpperCase(Locale.ROOT)); - - if (sfItem != null) { - giveItem(sender, p, sfItem, args); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.invalid-item", true, msg -> msg.replace(PLACEHOLDER_ITEM, args[2])); - } - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.not-online", true, msg -> msg.replace(PLACEHOLDER_PLAYER, args[1])); - } - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf give [Amount]")); - } - } else { + if (!sender.hasPermission("slimefun.cheat.items") && sender instanceof Player) { Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + return; + } + + if (args.length <= 2) { + Slimefun.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf give [Amount]")); + return; + } + + Optional player = PlayerList.findByName(args[1]); + if (player.isEmpty()) { + Slimefun.getLocalization().sendMessage(sender, "messages.not-online", true, msg -> msg.replace(PLACEHOLDER_PLAYER, args[1])); + return; + } + + Player p = player.get(); + SlimefunItem sfItem = SlimefunItem.getById(args[2].toUpperCase(Locale.ROOT)); + if (sfItem == null) { + Slimefun.getLocalization().sendMessage(sender, "messages.invalid-item", true, msg -> msg.replace(PLACEHOLDER_ITEM, args[2])); + return; } + + giveItem(sender, p, sfItem, args); } private void giveItem(CommandSender sender, Player p, SlimefunItem sfItem, String[] args) { if (sfItem instanceof MultiBlockMachine) { Slimefun.getLocalization().sendMessage(sender, "guide.cheat.no-multiblocks"); - } else { - int amount = parseAmount(args); - - if (amount > 0) { - Slimefun.getLocalization().sendMessage(p, "messages.given-item", true, msg -> msg.replace(PLACEHOLDER_ITEM, sfItem.getItemName()).replace(PLACEHOLDER_AMOUNT, String.valueOf(amount))); - Map excess = p.getInventory().addItem(new CustomItemStack(sfItem.getItem(), amount)); - if (Slimefun.getCfg().getBoolean("options.drop-excess-sf-give-items") && !excess.isEmpty()) { - for (ItemStack is : excess.values()) { - p.getWorld().dropItem(p.getLocation(), is); - } - } - - Slimefun.getLocalization().sendMessage(sender, "messages.give-item", true, msg -> msg.replace(PLACEHOLDER_PLAYER, args[1]).replace(PLACEHOLDER_ITEM, sfItem.getItemName()).replace(PLACEHOLDER_AMOUNT, String.valueOf(amount))); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.invalid-amount", true, msg -> msg.replace(PLACEHOLDER_AMOUNT, args[3])); + return; + } + + int amount = parseAmount(args); + if (amount <= 0) { + Slimefun.getLocalization().sendMessage(sender, "messages.invalid-amount", true, msg -> msg.replace(PLACEHOLDER_AMOUNT, args[3])); + return; + } + + Slimefun.getLocalization().sendMessage(p, "messages.given-item", true, msg -> msg.replace(PLACEHOLDER_ITEM, sfItem.getItemName()).replace(PLACEHOLDER_AMOUNT, String.valueOf(amount))); + Map excess = p.getInventory().addItem(new CustomItemStack(sfItem.getItem(), amount)); + if (Slimefun.getCfg().getBoolean("options.drop-excess-sf-give-items") && !excess.isEmpty()) { + for (ItemStack is : excess.values()) { + p.getWorld().dropItem(p.getLocation(), is); } } + + Slimefun.getLocalization().sendMessage(sender, "messages.give-item", true, msg -> msg.replace(PLACEHOLDER_PLAYER, args[1]).replace(PLACEHOLDER_ITEM, sfItem.getItemName()).replace(PLACEHOLDER_AMOUNT, String.valueOf(amount))); } private int parseAmount(String[] args) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java index 006744d6c7..306700ed58 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java @@ -19,17 +19,20 @@ class GuideCommand extends SubCommand { } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player player) { - if (sender.hasPermission("slimefun.command.guide")) { - SlimefunGuideMode design = SlimefunGuide.getDefaultMode(); - player.getInventory().addItem(SlimefunGuide.getItem(design).clone()); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); - } - } else { + if (!(sender instanceof Player player)) { Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true); + return; + } + + if (!sender.hasPermission("slimefun.command.guide")) { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + return; } + + SlimefunGuideMode design = SlimefunGuide.getDefaultMode(); + player.getInventory().addItem(SlimefunGuide.getItem(design).clone()); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/HelpCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/HelpCommand.java index b3e411d388..271a7d2d55 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/HelpCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/HelpCommand.java @@ -16,6 +16,7 @@ class HelpCommand extends SubCommand { } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { cmd.sendHelp(sender); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java index 83db842925..e23a1b9b8e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java @@ -21,14 +21,15 @@ class OpenGuideCommand extends SubCommand { @Override @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player player) { - if (sender.hasPermission("slimefun.command.open_guide")) { - SlimefunGuide.openGuide(player, SlimefunGuideMode.SURVIVAL_MODE); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); - } - } else { + if (!(sender instanceof Player player)) { Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true); + return; + } + + if (sender.hasPermission("slimefun.command.open_guide")) { + SlimefunGuide.openGuide(player, SlimefunGuideMode.SURVIVAL_MODE); + } else { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java index 8b81c87b53..2b0e3b7330 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java @@ -27,11 +27,13 @@ class ResearchCommand extends SubCommand { } @Override + @Nonnull protected String getDescription() { return "commands.research.description"; } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { // Check if researching is even enabled if (!Slimefun.getRegistry().isResearchingEnabled()) { @@ -39,46 +41,48 @@ public void onExecute(CommandSender sender, String[] args) { return; } - if (args.length == 3) { - if (!(sender instanceof Player) || sender.hasPermission("slimefun.cheat.researches")) { - Optional player = PlayerList.findByName(args[1]); - - if (player.isPresent()) { - Player p = player.get(); - - // Getting the PlayerProfile async - PlayerProfile.get(p, profile -> { - if (args[2].equalsIgnoreCase("all")) { - researchAll(sender, profile, p); - } else if (args[2].equalsIgnoreCase("reset")) { - reset(profile, p); - } else { - giveResearch(sender, p, args[2]); - } - }); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.not-online", true, msg -> msg.replace(PLACEHOLDER_PLAYER, args[1])); - } - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); - } - } else { + if (args.length != 3) { Slimefun.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf research ")); + return; + } + + if (sender instanceof Player && !sender.hasPermission("slimefun.cheat.researches")) { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + return; } + + Optional player = PlayerList.findByName(args[1]); + if (player.isEmpty()) { + Slimefun.getLocalization().sendMessage(sender, "messages.not-online", true, msg -> msg.replace(PLACEHOLDER_PLAYER, args[1])); + return; + } + + // Getting the PlayerProfile async + Player p = player.get(); + PlayerProfile.get(p, profile -> { + if (args[2].equalsIgnoreCase("all")) { + researchAll(sender, profile, p); + } else if (args[2].equalsIgnoreCase("reset")) { + reset(profile, p); + } else { + giveResearch(sender, p, args[2]); + } + }); } @ParametersAreNonnullByDefault private void giveResearch(CommandSender sender, Player p, String input) { Optional research = getResearchFromString(input); - if (research.isPresent()) { - research.get().unlock(p, true, player -> { - UnaryOperator variables = msg -> msg.replace(PLACEHOLDER_PLAYER, player.getName()).replace(PLACEHOLDER_RESEARCH, research.get().getName(player)); - Slimefun.getLocalization().sendMessage(player, "messages.give-research", true, variables); - }); - } else { + if (research.isEmpty()) { Slimefun.getLocalization().sendMessage(sender, "messages.invalid-research", true, msg -> msg.replace(PLACEHOLDER_RESEARCH, input)); + return; } + + research.get().unlock(p, true, player -> { + UnaryOperator variables = msg -> msg.replace(PLACEHOLDER_PLAYER, player.getName()).replace(PLACEHOLDER_RESEARCH, research.get().getName(player)); + Slimefun.getLocalization().sendMessage(player, "messages.give-research", true, variables); + }); } @ParametersAreNonnullByDefault diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java index 9783518b17..b4fd77863c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SearchCommand.java @@ -22,21 +22,25 @@ class SearchCommand extends SubCommand { } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player player) { - if (sender.hasPermission("slimefun.command.search")) { - if (args.length > 1) { - String query = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); - PlayerProfile.get(player, profile -> SlimefunGuide.openSearch(profile, query, SlimefunGuideMode.SURVIVAL_MODE, true)); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf search ")); - } - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); - } - } else { + if (!(sender instanceof Player player)) { Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true); + return; + } + + if (!sender.hasPermission("slimefun.command.search")) { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + return; } + + if (args.length <= 1) { + Slimefun.getLocalization().sendMessage(sender, "messages.usage", true, msg -> msg.replace("%usage%", "/sf search ")); + return; + } + + String query = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); + PlayerProfile.get(player, profile -> SlimefunGuide.openSearch(profile, query, SlimefunGuideMode.SURVIVAL_MODE, true)); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java index cb9069eb6a..e6f6b6e966 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/StatsCommand.java @@ -22,6 +22,7 @@ class StatsCommand extends SubCommand { } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { // Check if researching is even enabled if (!Slimefun.getRegistry().isResearchingEnabled()) { @@ -29,23 +30,27 @@ public void onExecute(CommandSender sender, String[] args) { return; } - if (args.length > 1) { - if (sender.hasPermission("slimefun.stats.others") || sender instanceof ConsoleCommandSender) { - Optional player = PlayerList.findByName(args[1]); - - if (player.isPresent()) { - PlayerProfile.get(player.get(), profile -> profile.sendStats(sender)); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.not-online", true, msg -> msg.replace("%player%", args[1])); - } + if (args.length <= 1) { + if (sender instanceof Player player) { + PlayerProfile.get(player, profile -> profile.sendStats(sender)); } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true); } - } else if (sender instanceof Player player) { - PlayerProfile.get(player, profile -> profile.sendStats(sender)); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.only-players", true); + return; + } + + if (!sender.hasPermission("slimefun.stats.others") && !(sender instanceof ConsoleCommandSender)) { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + return; } + + Optional player = PlayerList.findByName(args[1]); + if (player.isEmpty()) { + Slimefun.getLocalization().sendMessage(sender, "messages.not-online", true, msg -> msg.replace("%player%", args[1])); + return; + } + + PlayerProfile.get(player.get(), profile -> profile.sendStats(sender)); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java index 891ba85059..e35ce6836d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java @@ -20,30 +20,35 @@ class TeleporterCommand extends SubCommand { } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player player) { - if (sender.hasPermission("slimefun.command.teleporter")) { - if (args.length == 1) { - Slimefun.getGPSNetwork().getTeleportationManager().openTeleporterGUI(player, player.getUniqueId(), player.getLocation().getBlock().getRelative(BlockFace.DOWN), 999999999); - } else if (args.length == 2) { - - @SuppressWarnings("deprecation") - OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(args[1]); - - if (targetPlayer.getName() != null) { - Slimefun.getGPSNetwork().getTeleportationManager().openTeleporterGUI(player, targetPlayer.getUniqueId(), player.getLocation().getBlock().getRelative(BlockFace.DOWN), 999999999); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.unknown-player", msg -> msg.replace("%player%", args[1])); - } - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.usage", msg -> msg.replace("%usage%", "/sf teleporter [Player]")); - } - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission"); - } - } else { + if (!(sender instanceof Player player)) { Slimefun.getLocalization().sendMessage(sender, "messages.only-players"); + return; + } + + if (!sender.hasPermission("slimefun.command.teleporter")) { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission"); + return; + } + + if (args.length != 1 && args.length != 2) { + Slimefun.getLocalization().sendMessage(sender, "messages.usage", msg -> msg.replace("%usage%", "/sf teleporter [Player]")); } + + if (args.length == 1) { + Slimefun.getGPSNetwork().getTeleportationManager().openTeleporterGUI(player, player.getUniqueId(), player.getLocation().getBlock().getRelative(BlockFace.DOWN), 999999999); + return; + } + + @SuppressWarnings("deprecation") + OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(args[1]); + if (targetPlayer.getName() == null) { + Slimefun.getLocalization().sendMessage(sender, "messages.unknown-player", msg -> msg.replace("%player%", args[1])); + return; + } + + Slimefun.getGPSNetwork().getTeleportationManager().openTeleporterGUI(player, targetPlayer.getUniqueId(), player.getLocation().getBlock().getRelative(BlockFace.DOWN), 999999999); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java index 3f65ee2410..9dc2760ab4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java @@ -30,31 +30,32 @@ class TimingsCommand extends SubCommand { } @Override + @Nonnull protected String getDescription() { return "commands.timings.description"; } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { - if (sender.hasPermission("slimefun.command.timings") || sender instanceof ConsoleCommandSender) { - if (hasInvalidFlags(sender, args)) { - return; - } - - boolean verbose = hasFlag(args, "verbose"); - - if (verbose && sender instanceof Player) { - Slimefun.getLocalization().sendMessage(sender, "commands.timings.verbose-player", true); - return; - } + if (!sender.hasPermission("slimefun.command.timings") && !(sender instanceof ConsoleCommandSender)) { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + return; + } - Slimefun.getLocalization().sendMessage(sender, "commands.timings.please-wait", true); + if (hasInvalidFlags(sender, args)) { + return; + } - PerformanceInspector inspector = inspectorOf(sender, verbose); - Slimefun.getProfiler().requestSummary(inspector); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + boolean verbose = hasFlag(args, "verbose"); + if (verbose && sender instanceof Player) { + Slimefun.getLocalization().sendMessage(sender, "commands.timings.verbose-player", true); + return; } + + Slimefun.getLocalization().sendMessage(sender, "commands.timings.please-wait", true); + PerformanceInspector inspector = inspectorOf(sender, verbose); + Slimefun.getProfiler().requestSummary(inspector); } @ParametersAreNonnullByDefault diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java index 415d75555b..12980c0bd6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java @@ -50,17 +50,22 @@ class VersionsCommand extends SubCommand { } @Override - public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) { - if (sender.hasPermission("slimefun.command.versions") || sender instanceof ConsoleCommandSender) { - /* - * After all these years... Spigot still displays as "CraftBukkit". - * so we will just fix this inconsistency for them :) - */ - String serverSoftware = PaperLib.isSpigot() && !PaperLib.isPaper() ? "Spigot" : Bukkit.getName(); - ComponentBuilder builder = new ComponentBuilder(); + @ParametersAreNonnullByDefault + public void onExecute(CommandSender sender, String[] args) { + if (!sender.hasPermission("slimefun.command.versions") && !(sender instanceof ConsoleCommandSender)) { + Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); + return; + } - // @formatter:off - builder.append("This Server uses the following setup of Slimefun:\n") + /* + * After all these years... Spigot still displays as "CraftBukkit". + * so we will just fix this inconsistency for them :) + */ + String serverSoftware = PaperLib.isSpigot() && !PaperLib.isPaper() ? "Spigot" : Bukkit.getName(); + ComponentBuilder builder = new ComponentBuilder(); + + // @formatter:off + builder.append("This Server uses the following setup of Slimefun:\n") .color(ChatColor.GRAY) .append(serverSoftware) .color(ChatColor.GREEN) @@ -70,57 +75,55 @@ public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) { .color(ChatColor.GREEN) .append(Slimefun.getVersion() + '\n') .color(ChatColor.DARK_GREEN); - // @formatter:on + // @formatter:on - if (Slimefun.getMetricsService().getVersion() != null) { - // @formatter:off - builder.append("Metrics-Module ") + if (Slimefun.getMetricsService().getVersion() != null) { + // @formatter:off + builder.append("Metrics-Module ") .color(ChatColor.GREEN) .append("#" + Slimefun.getMetricsService().getVersion() + '\n') .color(ChatColor.DARK_GREEN); - // @formatter:on - } + // @formatter:on + } - addJavaVersion(builder); + addJavaVersion(builder); - if (Slimefun.getRegistry().isBackwardsCompatible()) { - // @formatter:off - HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text( + if (Slimefun.getRegistry().isBackwardsCompatible()) { + // @formatter:off + HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text( "Backwards compatibility has a negative impact on performance!\n" + - "We recommend you to disable this setting unless your server still " + - "has legacy Slimefun items (from before summer 2019) in circulation." - )); - // @formatter:on + "We recommend you to disable this setting unless your server still " + + "has legacy Slimefun items (from before summer 2019) in circulation." + )); + // @formatter:on - builder.append("\nBackwards compatibility enabled!\n").color(ChatColor.RED).event(hoverEvent); - } + builder.append("\nBackwards compatibility enabled!\n").color(ChatColor.RED).event(hoverEvent); + } - builder.append("\n").event((HoverEvent) null); - addPluginVersions(builder); + builder.append("\n").event((HoverEvent) null); + addPluginVersions(builder); - sender.spigot().sendMessage(builder.create()); - } else { - Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); - } + sender.spigot().sendMessage(builder.create()); } private void addJavaVersion(@Nonnull ComponentBuilder builder) { int version = NumberUtils.getJavaVersion(); - if (version < RECOMMENDED_JAVA_VERSION) { - // @formatter:off - builder.append("Java " + version).color(ChatColor.RED) + if (version >= RECOMMENDED_JAVA_VERSION) { + builder.append("Java ").color(ChatColor.GREEN).append(version + "\n").color(ChatColor.DARK_GREEN); + return; + } + + // @formatter:off + builder.append("Java " + version).color(ChatColor.RED) .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text( - "Your Java version is out of date!\n!" + - "You should use Java " + RECOMMENDED_JAVA_VERSION + " or higher.\n" + - JAVA_VERSION_NOTICE + "Your Java version is out of date!\n!" + + "You should use Java " + RECOMMENDED_JAVA_VERSION + " or higher.\n" + + JAVA_VERSION_NOTICE ))) .append("\n") .event((HoverEvent) null); - // @formatter:on - } else { - builder.append("Java ").color(ChatColor.GREEN).append(version + "\n").color(ChatColor.DARK_GREEN); - } + // @formatter:on } private void addPluginVersions(@Nonnull ComponentBuilder builder) { From 196f156fce28c424224d43f51654527ff763ab3c Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Sat, 5 Aug 2023 17:30:14 -0500 Subject: [PATCH 2/5] Fix Annotations & Spaces --- .../core/commands/subcommands/BackpackCommand.java | 3 +-- .../core/commands/subcommands/ChargeCommand.java | 3 +-- .../slimefun4/core/commands/subcommands/DebugCommand.java | 5 ++--- .../core/commands/subcommands/ResearchCommand.java | 6 ++---- .../core/commands/subcommands/SlimefunSubCommands.java | 3 +-- .../core/commands/subcommands/TimingsCommand.java | 6 ++---- .../core/commands/subcommands/VersionsCommand.java | 8 ++++---- 7 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java index 9d86d9a7d4..9a52801406 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java @@ -35,8 +35,7 @@ class BackpackCommand extends SubCommand { } @Override - @Nonnull - protected String getDescription() { + protected @Nonnull String getDescription() { return "commands.backpack.description"; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java index e2485a35bc..ec3815c78e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ChargeCommand.java @@ -28,8 +28,7 @@ class ChargeCommand extends SubCommand { } @Override - @Nonnull - protected String getDescription() { + protected @Nonnull String getDescription() { return "commands.charge.description"; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugCommand.java index 833f716385..0d9b59f962 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DebugCommand.java @@ -23,14 +23,13 @@ protected DebugCommand(@Nonnull Slimefun plugin, @Nonnull SlimefunCommand cmd) { } @Override - @Nonnull - protected String getDescription() { + protected @Nonnull String getDescription() { return "commands.debug.description"; } @Override @ParametersAreNonnullByDefault - public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) { + public void onExecute(CommandSender sender, String[] args) { if (!sender.hasPermission("slimefun.command.debug")) { Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true); return; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java index 2b0e3b7330..d3b7c7b3ab 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ResearchCommand.java @@ -27,8 +27,7 @@ class ResearchCommand extends SubCommand { } @Override - @Nonnull - protected String getDescription() { + protected @Nonnull String getDescription() { return "commands.research.description"; } @@ -105,8 +104,7 @@ private void reset(PlayerProfile profile, Player p) { Slimefun.getLocalization().sendMessage(p, "commands.research.reset", true, msg -> msg.replace(PLACEHOLDER_PLAYER, p.getName())); } - @Nonnull - private Optional getResearchFromString(@Nonnull String input) { + private @Nonnull Optional getResearchFromString(@Nonnull String input) { if (!input.contains(":")) { return Optional.empty(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java index 17d70bce3e..fa02cba436 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/SlimefunSubCommands.java @@ -22,8 +22,7 @@ public final class SlimefunSubCommands { private SlimefunSubCommands() {} - @Nonnull - public static Collection getAllCommands(@Nonnull SlimefunCommand cmd) { + public static @Nonnull Collection getAllCommands(@Nonnull SlimefunCommand cmd) { Slimefun plugin = cmd.getPlugin(); List commands = new LinkedList<>(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java index 9dc2760ab4..8cc11dae6f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TimingsCommand.java @@ -30,8 +30,7 @@ class TimingsCommand extends SubCommand { } @Override - @Nonnull - protected String getDescription() { + protected @Nonnull String getDescription() { return "commands.timings.description"; } @@ -87,8 +86,7 @@ private boolean hasFlag(String[] args, String flag) { return false; } - @Nonnull - private PerformanceInspector inspectorOf(@Nonnull CommandSender sender, boolean verbose) { + private @Nonnull PerformanceInspector inspectorOf(@Nonnull CommandSender sender, boolean verbose) { if (sender instanceof Player player) { return new PlayerPerformanceInspector(player); } else { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java index 12980c0bd6..5b59208bf7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java @@ -92,8 +92,8 @@ public void onExecute(CommandSender sender, String[] args) { // @formatter:off HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text( "Backwards compatibility has a negative impact on performance!\n" + - "We recommend you to disable this setting unless your server still " + - "has legacy Slimefun items (from before summer 2019) in circulation." + "We recommend you to disable this setting unless your server still " + + "has legacy Slimefun items (from before summer 2019) in circulation." )); // @formatter:on @@ -118,8 +118,8 @@ private void addJavaVersion(@Nonnull ComponentBuilder builder) { builder.append("Java " + version).color(ChatColor.RED) .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text( "Your Java version is out of date!\n!" + - "You should use Java " + RECOMMENDED_JAVA_VERSION + " or higher.\n" + - JAVA_VERSION_NOTICE + "You should use Java " + RECOMMENDED_JAVA_VERSION + " or higher.\n" + + JAVA_VERSION_NOTICE ))) .append("\n") .event((HoverEvent) null); From 9b86c76c34d6347fdac49df519b0ef41bd79a1d2 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Sun, 13 Aug 2023 11:20:34 -0500 Subject: [PATCH 3/5] Feedback --- .../slimefun4/core/commands/SlimefunTabCompleter.java | 10 ++++------ .../core/commands/subcommands/GiveCommand.java | 4 +++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java index 906f32fcbb..fcb0fb0797 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java @@ -29,10 +29,9 @@ public SlimefunTabCompleter(@Nonnull SlimefunCommand command) { this.command = command; } - @Nullable @Override @ParametersAreNonnullByDefault - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { + public @Nullable List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { if (args.length == 1) { return createReturnList(command.getSubCommandNames(), args[0]); } else if (args.length == 3) { @@ -71,8 +70,8 @@ public List onTabComplete(CommandSender sender, Command cmd, String labe * The typed string * @return Sublist if string is not empty */ - @Nonnull - private List createReturnList(@Nonnull List list, @Nonnull String string) { + @ParametersAreNonnullByDefault + private @Nonnull List createReturnList(List list, String string) { if (string.length() == 0) { return list; } @@ -95,8 +94,7 @@ private List createReturnList(@Nonnull List list, @Nonnull Strin return returnList; } - @Nonnull - private List getSlimefunItems() { + private @Nonnull List getSlimefunItems() { List items = Slimefun.getRegistry().getEnabledSlimefunItems(); List list = new ArrayList<>(items.size()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java index 01b0452740..4b3ef1ff74 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java @@ -4,6 +4,7 @@ import java.util.Map; import java.util.Optional; +import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.command.CommandSender; @@ -59,6 +60,7 @@ public void onExecute(CommandSender sender, String[] args) { giveItem(sender, p, sfItem, args); } + @ParametersAreNonnullByDefault private void giveItem(CommandSender sender, Player p, SlimefunItem sfItem, String[] args) { if (sfItem instanceof MultiBlockMachine) { Slimefun.getLocalization().sendMessage(sender, "guide.cheat.no-multiblocks"); @@ -82,7 +84,7 @@ private void giveItem(CommandSender sender, Player p, SlimefunItem sfItem, Strin Slimefun.getLocalization().sendMessage(sender, "messages.give-item", true, msg -> msg.replace(PLACEHOLDER_PLAYER, args[1]).replace(PLACEHOLDER_ITEM, sfItem.getItemName()).replace(PLACEHOLDER_AMOUNT, String.valueOf(amount))); } - private int parseAmount(String[] args) { + private int parseAmount(@Nonnull String[] args) { int amount = 1; if (args.length == 4) { From ae0fb01cb6478f6fbdb31005fbb6bae234bc5cdd Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Wed, 6 Sep 2023 08:56:09 -0500 Subject: [PATCH 4/5] Remove deprecation warnings supression --- .../slimefun4/core/commands/subcommands/BackpackCommand.java | 1 - .../slimefun4/core/commands/subcommands/TeleporterCommand.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java index 9a52801406..6326a153a1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java @@ -62,7 +62,6 @@ public void onExecute(CommandSender sender, String[] args) { return; } - @SuppressWarnings("deprecation") OfflinePlayer backpackOwner = Bukkit.getOfflinePlayer(args[1]); if (!(backpackOwner instanceof Player) && !backpackOwner.hasPlayedBefore()) { Slimefun.getLocalization().sendMessage(sender, "commands.backpack.player-never-joined"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java index e35ce6836d..d2d7ecd203 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/TeleporterCommand.java @@ -41,7 +41,6 @@ public void onExecute(CommandSender sender, String[] args) { return; } - @SuppressWarnings("deprecation") OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(args[1]); if (targetPlayer.getName() == null) { Slimefun.getLocalization().sendMessage(sender, "messages.unknown-player", msg -> msg.replace("%player%", args[1])); From 51f12b4ea7c5b44d8f1b85841837d33a36343454 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Thu, 4 Apr 2024 12:52:50 -0500 Subject: [PATCH 5/5] *sigh* --- .../slimefun4/core/commands/subcommands/VersionsCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java index 3d0055682a..56c46bcd6c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java @@ -89,7 +89,7 @@ public void onExecute(CommandSender sender, String[] args) { .append(")").color(ChatColor.GRAY); } - builder.append("\n").event((HoverEvent) null; + builder.append("\n").event((HoverEvent) null); // @formatter:on if (Slimefun.getMetricsService().getVersion() != null) {