From a9be204f83a7d2bb53416f63f4409f3153856fe6 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 22 Apr 2020 16:08:17 +1200 Subject: [PATCH] Add /libsdisguises help --- .../commands/LibsDisguisesCommand.java | 73 ++++++------------- .../commands/libsdisguises/LDCommand.java | 2 + .../commands/libsdisguises/LDConfig.java | 7 +- .../commands/libsdisguises/LDCount.java | 7 +- .../commands/libsdisguises/LDHelp.java | 51 +++++++++++++ .../commands/libsdisguises/LDJson.java | 7 +- .../commands/libsdisguises/LDMetaInfo.java | 7 +- .../commands/libsdisguises/LDMods.java | 7 +- .../commands/libsdisguises/LDPermTest.java | 7 +- .../commands/libsdisguises/LDReload.java | 7 +- .../commands/libsdisguises/LDScoreboard.java | 7 +- .../commands/libsdisguises/LDUpdate.java | 7 +- .../utilities/translations/LibsMsg.java | 21 +++++- 13 files changed, 150 insertions(+), 60 deletions(-) create mode 100644 src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDHelp.java diff --git a/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java b/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java index 0636f50a..2b668223 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java @@ -1,53 +1,35 @@ package me.libraryaddict.disguise.commands; -import com.comphenix.protocol.wrappers.nbt.NbtFactory; -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.DisguiseConfig; +import lombok.Getter; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.commands.libsdisguises.*; -import me.libraryaddict.disguise.disguisetypes.*; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsPremium; -import me.libraryaddict.disguise.utilities.UpdateChecker; -import me.libraryaddict.disguise.utilities.params.ParamInfoManager; -import me.libraryaddict.disguise.utilities.parser.DisguisePerm; -import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; -import me.libraryaddict.disguise.utilities.reflection.NmsVersion; -import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import me.libraryaddict.disguise.utilities.translations.TranslateType; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permissible; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { - private ArrayList commands = new ArrayList<>(); + @Getter + private final ArrayList commands = new ArrayList<>(); public LibsDisguisesCommand() { - commands.add(new LDConfig()); - commands.add(new LDCount()); - commands.add(new LDJson()); - commands.add(new LDMetaInfo()); - commands.add(new LDMods()); - commands.add(new LDPermTest()); - commands.add(new LDReload()); - commands.add(new LDScoreboard()); - commands.add(new LDUpdate()); + getCommands().add(new LDHelp(this)); + getCommands().add(new LDReload()); + getCommands().add(new LDUpdate()); + getCommands().add(new LDCount()); + getCommands().add(new LDConfig()); + getCommands().add(new LDPermTest()); + getCommands().add(new LDScoreboard()); + getCommands().add(new LDJson()); + getCommands().add(new LDMods()); + getCommands().add(new LDMetaInfo()); } protected ArrayList filterTabs(ArrayList list, String[] origArgs) { @@ -101,33 +83,24 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { version += disguises.getBuildNo(); } - sender.sendMessage(ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" + version + + sender.sendMessage(ChatColor.DARK_GREEN + "This server is running Lib's Disguises " + + (LibsPremium.isAPIPlugin() ? "API " : "") + "v" + version + " by libraryaddict, formerly maintained by Byteflux and NavidK0."); - // TODO You can use the following arguments, hover over them for more information - if (sender.hasPermission("libsdisguises.reload")) { sender.sendMessage(ChatColor.DARK_GREEN + "Use " + ChatColor.GREEN + "/libsdisguises " + "reload" + ChatColor.DARK_GREEN + " to reload the config. All disguises will be blown by doing this" + "."); + sender.sendMessage(ChatColor.DARK_GREEN + "Use /libsdisguises help to see more help"); } - if (sender.hasPermission("libsdisguises.update")) { - sender.sendMessage(ChatColor.DARK_GREEN + "Use " + ChatColor.GREEN + "/libsdisguises update" + - ChatColor.DARK_GREEN + - " to update Lib's Disguises to latest jenkins build. This will be updated on server restart. " + - "To force an update, use /libsdisguises update! with an ! on the end"); - } - - // TODO Other options - if (LibsPremium.isPremium()) { sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!"); } } else if (args.length > 0) { LDCommand command = null; - for (LDCommand c : commands) { + for (LDCommand c : getCommands()) { if (!c.getTabComplete().contains(args[0].toLowerCase())) { continue; } @@ -137,7 +110,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { } if (command != null) { - if (!sender.hasPermission(command.getPermission())) { + if (!command.hasPermission(sender)) { sender.sendMessage(LibsMsg.NO_PERM.get()); return true; } @@ -156,8 +129,8 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { ArrayList tabs = new ArrayList<>(); String[] args = getArgs(origArgs); - for (LDCommand command : commands) { - if (!sender.hasPermission(command.getPermission())) { + for (LDCommand command : getCommands()) { + if (!command.hasPermission(sender)) { continue; } diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDCommand.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDCommand.java index 0f2f3949..6fbf4bae 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDCommand.java @@ -11,6 +11,8 @@ import java.util.List; public interface LDCommand { List getTabComplete(); + boolean hasPermission(CommandSender sender); + String getPermission(); void onCommand(CommandSender sender, String[] args); diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDConfig.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDConfig.java index 018111d0..dec19b05 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDConfig.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDConfig.java @@ -19,6 +19,11 @@ public class LDConfig implements LDCommand { return Arrays.asList("config", "configuration"); } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + @Override public String getPermission() { return "libsdisguises.config"; @@ -40,6 +45,6 @@ public class LDConfig implements LDCommand { @Override public LibsMsg getHelp() { - return null; + return LibsMsg.LD_COMMAND_CONFIG; } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDCount.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDCount.java index 256e2a16..0464eaf9 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDCount.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDCount.java @@ -63,8 +63,13 @@ public class LDCount implements LDCommand { } } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + @Override public LibsMsg getHelp() { - return null; + return LibsMsg.LD_COMMAND_COUNT; } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDHelp.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDHelp.java new file mode 100644 index 00000000..f99a06cf --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDHelp.java @@ -0,0 +1,51 @@ +package me.libraryaddict.disguise.commands.libsdisguises; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import me.libraryaddict.disguise.commands.LibsDisguisesCommand; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.command.CommandSender; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * Created by libraryaddict on 22/04/2020. + */ +@AllArgsConstructor +@Getter +public class LDHelp implements LDCommand { + private LibsDisguisesCommand command; + + @Override + public List getTabComplete() { + return Collections.singletonList("help"); + } + + @Override + public String getPermission() { + return null; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return getCommand().getCommands().stream().anyMatch(c -> c.getPermission() != null && c.hasPermission(sender)); + } + + @Override + public void onCommand(CommandSender sender, String[] args) { + for (LDCommand cmd : command.getCommands()) { + if (!cmd.hasPermission(sender)) { + continue; + } + + sender.sendMessage(cmd.getHelp().get()); + } + } + + @Override + public LibsMsg getHelp() { + return LibsMsg.LD_COMMAND_HELP; + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDJson.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDJson.java index c504979a..f0ee24ab 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDJson.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDJson.java @@ -123,8 +123,13 @@ public class LDJson implements LDCommand { sender.spigot().sendMessage(builder.create()); } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + @Override public LibsMsg getHelp() { - return null; + return LibsMsg.LD_COMMAND_JSON; } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDMetaInfo.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDMetaInfo.java index 75d67f74..6a5bc0a0 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDMetaInfo.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDMetaInfo.java @@ -74,8 +74,13 @@ public class LDMetaInfo implements LDCommand { } } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + @Override public LibsMsg getHelp() { - return null; + return LibsMsg.LD_COMMAND_METAINFO; } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDMods.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDMods.java index 6a6af28b..1c7b407e 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDMods.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDMods.java @@ -57,8 +57,13 @@ public class LDMods implements LDCommand { StringUtils.join((List) player.getMetadata("forge_mods").get(0).value(), ", "))); } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + @Override public LibsMsg getHelp() { - return null; + return LibsMsg.LD_COMMAND_MODS; } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDPermTest.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDPermTest.java index 42a3fc40..103f2ad5 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDPermTest.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDPermTest.java @@ -57,8 +57,13 @@ public class LDPermTest implements LDCommand { } } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + @Override public LibsMsg getHelp() { - return null; + return LibsMsg.LD_COMMAND_PERMTEST; } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDReload.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDReload.java index a64b8a65..f49381c1 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDReload.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDReload.java @@ -27,8 +27,13 @@ public class LDReload implements LDCommand { sender.sendMessage(LibsMsg.RELOADED_CONFIG.get()); } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + @Override public LibsMsg getHelp() { - return null; + return LibsMsg.LD_COMMAND_RELOAD; } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java index 3a2e1b2c..e54f0207 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java @@ -110,8 +110,13 @@ public class LDScoreboard implements LDCommand { sender.sendMessage(LibsMsg.LIBS_SCOREBOARD_SUCCESS.get(team.getName())); } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + @Override public LibsMsg getHelp() { - return null; + return LibsMsg.LD_COMMAND_SCOREBOARD; } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java index 79659901..eb115ca8 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java @@ -73,8 +73,13 @@ public class LDUpdate implements LDCommand { }.runTaskAsynchronously(LibsDisguises.getInstance()); } + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + @Override public LibsMsg getHelp() { - return null; + return LibsMsg.LD_COMMAND_UPDATE; } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java b/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java index cd174dc0..761f9585 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java @@ -293,7 +293,26 @@ public enum LibsMsg { LIBS_SCOREBOARD_DISABLED( "The scoreboard modification has been disabled in config, will continue the debug incase this is intended" + "."), - USING_DEFAULT_CONFIG(ChatColor.DARK_GREEN + "Using the default config!"); + USING_DEFAULT_CONFIG(ChatColor.DARK_GREEN + "Using the default config!"), + LD_COMMAND_HELP(ChatColor.BLUE + "/libsdisguises help - " + ChatColor.AQUA + "Returns this!"), + LD_COMMAND_COUNT(ChatColor.BLUE + "/libsdisguises count - " + ChatColor.AQUA + + "Tells you how many active disguises there are"), + LD_COMMAND_METAINFO(ChatColor.BLUE + "/libsdisguises metainfo - " + ChatColor.AQUA + + "Debugging info, tells you what the metadata is for a disguise"), + LD_COMMAND_CONFIG(ChatColor.BLUE + "/libsdisguises config - " + ChatColor.AQUA + + "Tells you what's not normal in your config"), + LD_COMMAND_UPDATE(ChatColor.BLUE + "/libsdisguises update - " + ChatColor.AQUA + + "Update's the plugin, doing 'update!' will force an update. Server must be restarted to install update."), + LD_COMMAND_JSON(ChatColor.BLUE + "/libsdisguises json - " + ChatColor.AQUA + + "Turns the current held item into a string format"), + LD_COMMAND_MODS(ChatColor.BLUE + "/libsdisguises mods - " + ChatColor.AQUA + + "If using modded entities, this will tell you what mods a player is using if possible"), + LD_COMMAND_PERMTEST(ChatColor.BLUE + "/libsdisguises permtest - " + ChatColor.AQUA + + "Does a quick test to see if your permissions are working"), + LD_COMMAND_SCOREBOARD(ChatColor.BLUE + "/libsdisguises scoreboard - " + ChatColor.AQUA + + "Does a test to see if there's any scoreboard issues it can detect"), + LD_COMMAND_RELOAD(ChatColor.BLUE + "/libsdisguises reload - " + ChatColor.AQUA + + "Reload's the plugin config and possibly blows disguises"); private String string;