From 90685edae6980934dd82494d34eb9e98af64bce3 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 31 Jul 2020 01:32:43 +0200 Subject: [PATCH] Added a permission node for the debug fish --- CHANGELOG.md | 1 + .../slimefun4/core/commands/SubCommand.java | 28 +++++++++++++-- .../commands/subcommands/BackpackCommand.java | 12 +------ .../commands/subcommands/CheatCommand.java | 12 +------ .../subcommands/DebugFishCommand.java | 16 ++------- .../commands/subcommands/GiveCommand.java | 12 +------ .../commands/subcommands/GuideCommand.java | 12 +------ .../commands/subcommands/HelpCommand.java | 12 +------ .../subcommands/OpenGuideCommand.java | 12 +------ .../commands/subcommands/ResearchCommand.java | 12 +------ .../commands/subcommands/SearchCommand.java | 12 +------ .../commands/subcommands/StatsCommand.java | 12 +------ .../subcommands/TeleporterCommand.java | 12 +------ .../commands/subcommands/TimingsCommand.java | 12 +------ .../commands/subcommands/VersionsCommand.java | 35 ++++++++----------- src/main/resources/plugin.yml | 3 ++ 16 files changed, 57 insertions(+), 158 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27a1e0044..d09af459c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ * Added Bee protection to Hazmat Suit * Added Enchantment Rune * Added Tape Measure +* Added a permission node for /sf debug_fish #### Changes * Refactored and reworked the Generator API diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java index ede461878..4edbd09c4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java @@ -4,6 +4,7 @@ import java.util.Map; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.command.defaults.HelpCommand; import org.bukkit.entity.Player; import io.github.thebusybiscuit.slimefun4.core.services.localization.Language; @@ -23,14 +24,35 @@ public abstract class SubCommand { protected final SlimefunPlugin plugin; protected final SlimefunCommand cmd; - protected SubCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { + private final String name; + private final boolean hidden; + + protected SubCommand(SlimefunPlugin plugin, SlimefunCommand cmd, String name, boolean hidden) { this.plugin = plugin; this.cmd = cmd; + + this.name = name; + this.hidden = hidden; } - public abstract String getName(); + /** + * This returns the name of this {@link SubCommand}, the name is equivalent to the + * first argument given to the actual command. + * + * @return The name of this {@link SubCommand} + */ + public final String getName() { + return name; + } - public abstract boolean isHidden(); + /** + * This method returns whether this {@link SubCommand} is hidden from the {@link HelpCommand}. + * + * @return Whether to hide this {@link SubCommand} + */ + public final boolean isHidden() { + return hidden; + } protected void recordUsage(Map commandUsage) { commandUsage.merge(this, 1, Integer::sum); 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 f607010c3..1b1478e30 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 @@ -17,12 +17,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun; class BackpackCommand extends SubCommand { BackpackCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "backpack"; + super(plugin, cmd, "backpack", false); } @Override @@ -30,11 +25,6 @@ class BackpackCommand extends SubCommand { return "commands.backpack.description"; } - @Override - public boolean isHidden() { - return false; - } - @Override public void onExecute(CommandSender sender, String[] args) { if (!(sender instanceof Player) || !sender.hasPermission("slimefun.command.backpack")) { 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 faa553341..450abd94d 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 @@ -11,17 +11,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class CheatCommand extends SubCommand { CheatCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "cheat"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "cheat", false); } @Override 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 dcc63f273..f1e8656fc 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 @@ -11,23 +11,13 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class DebugFishCommand extends SubCommand { DebugFishCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "debug_fish"; - } - - @Override - public boolean isHidden() { - return true; + super(plugin, cmd, "debug_fish", true); } @Override public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player && sender.isOp()) { - ((Player) sender).getInventory().addItem(SlimefunItems.DEBUG_FISH); + if (sender instanceof Player && sender.hasPermission("slimefun.debugging")) { + ((Player) sender).getInventory().addItem(SlimefunItems.DEBUG_FISH.clone()); } else { SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true); 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 8c9457845..eb9c8d131 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 @@ -22,17 +22,7 @@ class GiveCommand extends SubCommand { private static final String PLACEHOLDER_AMOUNT = "%amount%"; GiveCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "give"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "give", false); } @Override 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 a233cc3f5..457151115 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 @@ -12,17 +12,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class GuideCommand extends SubCommand { GuideCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "guide"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "guide", false); } @Override 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 1c241462d..43e43feb3 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 @@ -9,17 +9,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class HelpCommand extends SubCommand { HelpCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "help"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "help", false); } @Override 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 a286db515..ab6e087b2 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 @@ -12,17 +12,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class OpenGuideCommand extends SubCommand { OpenGuideCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "open_guide"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "open_guide", false); } @Override 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 1ea35f95b..bb230acda 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 @@ -19,17 +19,7 @@ class ResearchCommand extends SubCommand { private static final String PLACEHOLDER_RESEARCH = "%research%"; ResearchCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "research"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "research", false); } @Override 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 60186e0c4..22169a7ae 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 @@ -14,17 +14,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class SearchCommand extends SubCommand { SearchCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "search"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "search", false); } @Override 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 29e3b861a..a2e9628b3 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 @@ -15,17 +15,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class StatsCommand extends SubCommand { StatsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "stats"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "stats", false); } @Override 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 75437e35e..8031116ca 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 @@ -13,17 +13,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class TeleporterCommand extends SubCommand { TeleporterCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "teleporter"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "teleporter", false); } @Override 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 2b85e48aa..7b5e4b7e9 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 @@ -10,17 +10,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class TimingsCommand extends SubCommand { TimingsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "timings"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "timings", false); } @Override 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 9be653ac9..505f29c62 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 @@ -2,32 +2,23 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; import java.util.Collection; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.plugin.Plugin; + import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.cscorelib2.reflection.ReflectionUtils; import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.plugin.Plugin; import io.papermc.lib.PaperLib; class VersionsCommand extends SubCommand { VersionsCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - } - - @Override - public String getName() { - return "versions"; - } - - @Override - public boolean isHidden() { - return false; + super(plugin, cmd, "versions", false); } @Override @@ -37,8 +28,8 @@ class VersionsCommand extends SubCommand { // so we will just fix this inconsistency for them :) String serverSoftware = PaperLib.isSpigot() && !PaperLib.isPaper() ? "Spigot" : Bukkit.getName(); + sender.sendMessage(ChatColor.GRAY + "This Server uses the following setup of Slimefun:"); sender.sendMessage(ChatColors.color("&a" + serverSoftware + " &2" + ReflectionUtils.getVersion())); - sender.sendMessage(""); sender.sendMessage(ChatColors.color("&aCS-CoreLib &2v" + SlimefunPlugin.getCSCoreLibVersion())); sender.sendMessage(ChatColors.color("&aSlimefun &2v" + SlimefunPlugin.getVersion())); @@ -47,20 +38,22 @@ class VersionsCommand extends SubCommand { } if (SlimefunPlugin.getRegistry().isBackwardsCompatible()) { - sender.sendMessage(ChatColor.YELLOW + "Backwards compatibility enabled!"); + sender.sendMessage(ChatColor.RED + "Backwards compatibility enabled!"); } sender.sendMessage(""); Collection addons = SlimefunPlugin.getInstalledAddons(); - sender.sendMessage(ChatColors.color("&7Installed Addons &8(" + addons.size() + ")")); + sender.sendMessage(ChatColors.color("&7Installed Addons: &8(" + addons.size() + ")")); for (Plugin plugin : addons) { + String version = plugin.getDescription().getVersion(); + if (Bukkit.getPluginManager().isPluginEnabled(plugin)) { - sender.sendMessage(ChatColors.color(" &a" + plugin.getName() + " &2v" + plugin.getDescription().getVersion())); + sender.sendMessage(ChatColor.GREEN + " " + plugin.getName() + ChatColor.DARK_GREEN + " v" + version); } else { - sender.sendMessage(ChatColors.color(" &c" + plugin.getName() + " &4v" + plugin.getDescription().getVersion())); + sender.sendMessage(ChatColor.RED + " " + plugin.getName() + ChatColor.DARK_RED + " v" + version); } } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b991fb322..1841a7839 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -58,3 +58,6 @@ permissions: slimefun.inventory.bypass: description: Allows you to open all Slimefun Machines default: op + slimefun.debugging: + description: Allows you to use the debugging tool from Slimefun + default: op