From fc0840c9d3ec5cf3d2ecf59758e6ca5228eb7b71 Mon Sep 17 00:00:00 2001 From: kmecpp Date: Fri, 20 Jul 2018 14:32:49 -0400 Subject: [PATCH] Made the commands easier to use Display the command list when the user uses the base command in addition to /hd help. Move the plugin information to the subcommand /hd version --- .../main/HologramsCommandHandler.java | 80 ++++++++++++---- .../commands/main/subs/HelpCommand.java | 96 ------------------- .../commands/main/subs/VersionCommand.java | 52 ++++++++++ 3 files changed, 113 insertions(+), 115 deletions(-) delete mode 100644 Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/HelpCommand.java create mode 100644 Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/VersionCommand.java diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/HologramsCommandHandler.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/HologramsCommandHandler.java index 441bdb38..f7c6c0f5 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/HologramsCommandHandler.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/HologramsCommandHandler.java @@ -4,13 +4,17 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import com.gmail.filoghost.holographicdisplays.HolographicDisplays; import com.gmail.filoghost.holographicdisplays.commands.Colors; +import com.gmail.filoghost.holographicdisplays.commands.CommandValidator; import com.gmail.filoghost.holographicdisplays.commands.Strings; +import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand.SubCommandType; import com.gmail.filoghost.holographicdisplays.commands.main.subs.AddlineCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.AlignCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.CopyCommand; @@ -18,7 +22,6 @@ import com.gmail.filoghost.holographicdisplays.commands.main.subs.CreateCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.DeleteCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.EditCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.FixCommand; -import com.gmail.filoghost.holographicdisplays.commands.main.subs.HelpCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.InfoCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.InsertlineCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.ListCommand; @@ -30,16 +33,17 @@ import com.gmail.filoghost.holographicdisplays.commands.main.subs.ReloadCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.RemovelineCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.SetlineCommand; import com.gmail.filoghost.holographicdisplays.commands.main.subs.TeleportCommand; +import com.gmail.filoghost.holographicdisplays.commands.main.subs.VersionCommand; import com.gmail.filoghost.holographicdisplays.exception.CommandException; import com.gmail.filoghost.holographicdisplays.util.Utils; public class HologramsCommandHandler implements CommandExecutor { private List subCommands; - + public HologramsCommandHandler() { subCommands = Utils.newList(); - + registerSubCommand(new AddlineCommand()); registerSubCommand(new CreateCommand()); registerSubCommand(new DeleteCommand()); @@ -51,45 +55,69 @@ public class HologramsCommandHandler implements CommandExecutor { registerSubCommand(new AlignCommand()); registerSubCommand(new CopyCommand()); registerSubCommand(new ReloadCommand()); + registerSubCommand(new VersionCommand()); registerSubCommand(new FixCommand()); - + registerSubCommand(new RemovelineCommand()); registerSubCommand(new SetlineCommand()); registerSubCommand(new InsertlineCommand()); registerSubCommand(new ReadtextCommand()); registerSubCommand(new ReadimageCommand()); registerSubCommand(new InfoCommand()); - - registerSubCommand(new HelpCommand(this)); } - + public void registerSubCommand(HologramSubCommand subCommand) { subCommands.add(subCommand); } - + public List getSubCommands() { return new ArrayList(subCommands); } - + @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - - if (args.length == 0) { - sender.sendMessage(Colors.PRIMARY_SHADOW + "Server is running " + Colors.PRIMARY + "Holographic Displays " + Colors.PRIMARY_SHADOW + "v" + HolographicDisplays.getInstance().getDescription().getVersion() + " by " + Colors.PRIMARY + "filoghost"); - if (sender.hasPermission(Strings.BASE_PERM + "help")) { - sender.sendMessage(Colors.PRIMARY_SHADOW + "Commands: " + Colors.PRIMARY + "/" + label + " help"); + if (args.length == 0 || args[0].equalsIgnoreCase("help")) { + sender.sendMessage(""); + sender.sendMessage(Strings.formatTitle("Holographic Displays Commands")); + for (HologramSubCommand subCommand : subCommands) { + if (subCommand.getType() == SubCommandType.GENERIC) { + String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments() : ""); + + if (CommandValidator.isPlayerSender(sender)) { + + List help = Utils.newList(); + help.add(Colors.PRIMARY + usage); + for (String tutLine : subCommand.getTutorial()) { + help.add(Colors.SECONDARY_SHADOW + tutLine); + } + + HolographicDisplays.getNMSManager() + .newFancyMessage(usage) + .color(ChatColor.AQUA) + .suggest(usage) + .tooltip(Utils.join(help, "\n")) + .send((Player) sender); + + } else { + sender.sendMessage(Colors.PRIMARY + usage); + } + } + } + + if (CommandValidator.isPlayerSender(sender)) { + sendHoverTip(sender); } return true; } - + for (HologramSubCommand subCommand : subCommands) { if (subCommand.isValidTrigger(args[0])) { - + if (!subCommand.hasPermission(sender)) { sender.sendMessage(Colors.ERROR + "You don't have permission."); return true; } - + if (args.length - 1 >= subCommand.getMinimumArguments()) { try { subCommand.execute(sender, label, Arrays.copyOfRange(args, 1, args.length)); @@ -99,12 +127,26 @@ public class HologramsCommandHandler implements CommandExecutor { } else { sender.sendMessage(Colors.ERROR + "Usage: /" + label + " " + subCommand.getName() + " " + subCommand.getPossibleArguments()); } - + return true; } } - + sender.sendMessage(Colors.ERROR + "Unknown sub-command. Type \"/" + label + " help\" for a list of commands."); return true; } + + public static void sendHoverTip(CommandSender sender) { + sender.sendMessage(""); + HolographicDisplays.getNMSManager().newFancyMessage("TIP").style(ChatColor.BOLD).color(ChatColor.YELLOW) + .then(" Try to ").color(ChatColor.GRAY) + .then("hover").color(ChatColor.WHITE).style(ChatColor.ITALIC, ChatColor.UNDERLINE) + .tooltip(ChatColor.LIGHT_PURPLE + "Hover on the commands to get info about them.") + .then(" or ").color(ChatColor.GRAY) + .then("click").color(ChatColor.WHITE).style(ChatColor.ITALIC, ChatColor.UNDERLINE) + .tooltip(ChatColor.LIGHT_PURPLE + "Click on the commands to insert them in the chat.") + .then(" on the commands!").color(ChatColor.GRAY) + .send((Player) sender); + } + } diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/HelpCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/HelpCommand.java deleted file mode 100644 index 44c95451..00000000 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/HelpCommand.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.gmail.filoghost.holographicdisplays.commands.main.subs; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.gmail.filoghost.holographicdisplays.HolographicDisplays; -import com.gmail.filoghost.holographicdisplays.commands.Colors; -import com.gmail.filoghost.holographicdisplays.commands.CommandValidator; -import com.gmail.filoghost.holographicdisplays.commands.Strings; -import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand; -import com.gmail.filoghost.holographicdisplays.commands.main.HologramsCommandHandler; -import com.gmail.filoghost.holographicdisplays.exception.CommandException; -import com.gmail.filoghost.holographicdisplays.util.Utils; - -public class HelpCommand extends HologramSubCommand { - - private HologramsCommandHandler mainCommandHandler; - - public HelpCommand(HologramsCommandHandler mainCommandHandler) { - super("help"); - setPermission(Strings.BASE_PERM + "help"); - this.mainCommandHandler = mainCommandHandler; - } - - @Override - public String getPossibleArguments() { - return ""; - } - - @Override - public int getMinimumArguments() { - return 0; - } - - - @Override - public void execute(CommandSender sender, String label, String[] args) throws CommandException { - sender.sendMessage(""); - sender.sendMessage(Strings.formatTitle("Holographic Displays Commands")); - for (HologramSubCommand subCommand : mainCommandHandler.getSubCommands()) { - if (subCommand.getType() == SubCommandType.GENERIC) { - String usage = "/" + label + " " + subCommand.getName() + (subCommand.getPossibleArguments().length() > 0 ? " " + subCommand.getPossibleArguments() : ""); - - if (CommandValidator.isPlayerSender(sender)) { - - List help = Utils.newList(); - help.add(Colors.PRIMARY + usage); - for (String tutLine : subCommand.getTutorial()) { - help.add(Colors.SECONDARY_SHADOW + tutLine); - } - - HolographicDisplays.getNMSManager().newFancyMessage(usage) - .color(ChatColor.AQUA) - .suggest(usage) - .tooltip(Utils.join(help, "\n")) - .send((Player) sender); - - } else { - sender.sendMessage(Colors.PRIMARY + usage); - } - } - } - - if (CommandValidator.isPlayerSender(sender)) { - sendHoverTip(sender); - } - } - - public static void sendHoverTip(CommandSender sender) { - sender.sendMessage(""); - HolographicDisplays.getNMSManager().newFancyMessage("TIP").style(ChatColor.BOLD).color(ChatColor.YELLOW) - .then(" Try to ").color(ChatColor.GRAY) - .then("hover").color(ChatColor.WHITE).style(ChatColor.ITALIC, ChatColor.UNDERLINE) - .tooltip(ChatColor.LIGHT_PURPLE + "Hover on the commands to get info about them.") - .then(" or ").color(ChatColor.GRAY) - .then("click").color(ChatColor.WHITE).style(ChatColor.ITALIC, ChatColor.UNDERLINE) - .tooltip(ChatColor.LIGHT_PURPLE + "Click on the commands to insert them in the chat.") - .then(" on the commands!").color(ChatColor.GRAY) - .send((Player) sender); - } - - @Override - public List getTutorial() { - return null; - } - - @Override - public SubCommandType getType() { - return SubCommandType.HIDDEN; - } - - -} diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/VersionCommand.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/VersionCommand.java new file mode 100644 index 00000000..1f5db707 --- /dev/null +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/commands/main/subs/VersionCommand.java @@ -0,0 +1,52 @@ +package com.gmail.filoghost.holographicdisplays.commands.main.subs; + +import java.util.Arrays; +import java.util.List; + +import org.bukkit.command.CommandSender; + +import com.gmail.filoghost.holographicdisplays.HolographicDisplays; +import com.gmail.filoghost.holographicdisplays.commands.Colors; +import com.gmail.filoghost.holographicdisplays.commands.Strings; +import com.gmail.filoghost.holographicdisplays.commands.main.HologramSubCommand; +import com.gmail.filoghost.holographicdisplays.exception.CommandException; + +public class VersionCommand extends HologramSubCommand { + + public VersionCommand() { + super("version"); + setPermission(Strings.BASE_PERM + "version"); + } + + @Override + public String getPossibleArguments() { + return ""; + } + + @Override + public int getMinimumArguments() { + return 0; + } + + + @Override + public void execute(CommandSender sender, String label, String[] args) throws CommandException { + sender.sendMessage(""); + sender.sendMessage(Colors.PRIMARY_SHADOW + "Server is running " + Colors.PRIMARY + "Holographic Displays " + Colors.PRIMARY_SHADOW + "v" + HolographicDisplays.getInstance().getDescription().getVersion() + " by " + Colors.PRIMARY + "filoghost"); + if (sender.hasPermission(Strings.BASE_PERM + "help")) { + sender.sendMessage(Colors.PRIMARY_SHADOW + "Commands: " + Colors.PRIMARY + "/" + label + " help"); + } + } + + @Override + public List getTutorial() { + return Arrays.asList("Displays plugin information."); + } + + @Override + public SubCommandType getType() { + return SubCommandType.GENERIC; + } + + +}