Add /libsdisguises help
This commit is contained in:
		| @@ -1,53 +1,35 @@ | |||||||
| package me.libraryaddict.disguise.commands; | package me.libraryaddict.disguise.commands; | ||||||
|  |  | ||||||
| import com.comphenix.protocol.wrappers.nbt.NbtFactory; | import lombok.Getter; | ||||||
| import me.libraryaddict.disguise.DisguiseAPI; |  | ||||||
| import me.libraryaddict.disguise.DisguiseConfig; |  | ||||||
| import me.libraryaddict.disguise.LibsDisguises; | import me.libraryaddict.disguise.LibsDisguises; | ||||||
| import me.libraryaddict.disguise.commands.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.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.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.ChatColor; | ||||||
| import org.bukkit.command.Command; | import org.bukkit.command.Command; | ||||||
| import org.bukkit.command.CommandExecutor; | import org.bukkit.command.CommandExecutor; | ||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.command.TabCompleter; | 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 { | public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { | ||||||
|     private ArrayList<LDCommand> commands = new ArrayList<>(); |     @Getter | ||||||
|  |     private final ArrayList<LDCommand> commands = new ArrayList<>(); | ||||||
|  |  | ||||||
|     public LibsDisguisesCommand() { |     public LibsDisguisesCommand() { | ||||||
|         commands.add(new LDConfig()); |         getCommands().add(new LDHelp(this)); | ||||||
|         commands.add(new LDCount()); |         getCommands().add(new LDReload()); | ||||||
|         commands.add(new LDJson()); |         getCommands().add(new LDUpdate()); | ||||||
|         commands.add(new LDMetaInfo()); |         getCommands().add(new LDCount()); | ||||||
|         commands.add(new LDMods()); |         getCommands().add(new LDConfig()); | ||||||
|         commands.add(new LDPermTest()); |         getCommands().add(new LDPermTest()); | ||||||
|         commands.add(new LDReload()); |         getCommands().add(new LDScoreboard()); | ||||||
|         commands.add(new LDScoreboard()); |         getCommands().add(new LDJson()); | ||||||
|         commands.add(new LDUpdate()); |         getCommands().add(new LDMods()); | ||||||
|  |         getCommands().add(new LDMetaInfo()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) { |     protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) { | ||||||
| @@ -101,33 +83,24 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { | |||||||
|                 version += disguises.getBuildNo(); |                 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."); |                     " 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")) { |             if (sender.hasPermission("libsdisguises.reload")) { | ||||||
|                 sender.sendMessage(ChatColor.DARK_GREEN + "Use " + ChatColor.GREEN + "/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" + |                         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()) { |             if (LibsPremium.isPremium()) { | ||||||
|                 sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!"); |                 sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!"); | ||||||
|             } |             } | ||||||
|         } else if (args.length > 0) { |         } else if (args.length > 0) { | ||||||
|             LDCommand command = null; |             LDCommand command = null; | ||||||
|  |  | ||||||
|             for (LDCommand c : commands) { |             for (LDCommand c : getCommands()) { | ||||||
|                 if (!c.getTabComplete().contains(args[0].toLowerCase())) { |                 if (!c.getTabComplete().contains(args[0].toLowerCase())) { | ||||||
|                     continue; |                     continue; | ||||||
|                 } |                 } | ||||||
| @@ -137,7 +110,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (command != null) { |             if (command != null) { | ||||||
|                 if (!sender.hasPermission(command.getPermission())) { |                 if (!command.hasPermission(sender)) { | ||||||
|                     sender.sendMessage(LibsMsg.NO_PERM.get()); |                     sender.sendMessage(LibsMsg.NO_PERM.get()); | ||||||
|                     return true; |                     return true; | ||||||
|                 } |                 } | ||||||
| @@ -156,8 +129,8 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { | |||||||
|         ArrayList<String> tabs = new ArrayList<>(); |         ArrayList<String> tabs = new ArrayList<>(); | ||||||
|         String[] args = getArgs(origArgs); |         String[] args = getArgs(origArgs); | ||||||
|  |  | ||||||
|         for (LDCommand command : commands) { |         for (LDCommand command : getCommands()) { | ||||||
|             if (!sender.hasPermission(command.getPermission())) { |             if (!command.hasPermission(sender)) { | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,6 +11,8 @@ import java.util.List; | |||||||
| public interface LDCommand { | public interface LDCommand { | ||||||
|     List<String> getTabComplete(); |     List<String> getTabComplete(); | ||||||
|  |  | ||||||
|  |     boolean hasPermission(CommandSender sender); | ||||||
|  |  | ||||||
|     String getPermission(); |     String getPermission(); | ||||||
|  |  | ||||||
|     void onCommand(CommandSender sender, String[] args); |     void onCommand(CommandSender sender, String[] args); | ||||||
|   | |||||||
| @@ -19,6 +19,11 @@ public class LDConfig implements LDCommand { | |||||||
|         return Arrays.asList("config", "configuration"); |         return Arrays.asList("config", "configuration"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean hasPermission(CommandSender sender) { | ||||||
|  |         return sender.hasPermission(getPermission()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public String getPermission() { |     public String getPermission() { | ||||||
|         return "libsdisguises.config"; |         return "libsdisguises.config"; | ||||||
| @@ -40,6 +45,6 @@ public class LDConfig implements LDCommand { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public LibsMsg getHelp() { |     public LibsMsg getHelp() { | ||||||
|         return null; |         return LibsMsg.LD_COMMAND_CONFIG; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -63,8 +63,13 @@ public class LDCount implements LDCommand { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean hasPermission(CommandSender sender) { | ||||||
|  |         return sender.hasPermission(getPermission()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public LibsMsg getHelp() { |     public LibsMsg getHelp() { | ||||||
|         return null; |         return LibsMsg.LD_COMMAND_COUNT; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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<String> 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; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -123,8 +123,13 @@ public class LDJson implements LDCommand { | |||||||
|         sender.spigot().sendMessage(builder.create()); |         sender.spigot().sendMessage(builder.create()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean hasPermission(CommandSender sender) { | ||||||
|  |         return sender.hasPermission(getPermission()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public LibsMsg getHelp() { |     public LibsMsg getHelp() { | ||||||
|         return null; |         return LibsMsg.LD_COMMAND_JSON; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -74,8 +74,13 @@ public class LDMetaInfo implements LDCommand { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean hasPermission(CommandSender sender) { | ||||||
|  |         return sender.hasPermission(getPermission()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public LibsMsg getHelp() { |     public LibsMsg getHelp() { | ||||||
|         return null; |         return LibsMsg.LD_COMMAND_METAINFO; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -57,8 +57,13 @@ public class LDMods implements LDCommand { | |||||||
|                 StringUtils.join((List<String>) player.getMetadata("forge_mods").get(0).value(), ", "))); |                 StringUtils.join((List<String>) player.getMetadata("forge_mods").get(0).value(), ", "))); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean hasPermission(CommandSender sender) { | ||||||
|  |         return sender.hasPermission(getPermission()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public LibsMsg getHelp() { |     public LibsMsg getHelp() { | ||||||
|         return null; |         return LibsMsg.LD_COMMAND_MODS; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -57,8 +57,13 @@ public class LDPermTest implements LDCommand { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean hasPermission(CommandSender sender) { | ||||||
|  |         return sender.hasPermission(getPermission()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public LibsMsg getHelp() { |     public LibsMsg getHelp() { | ||||||
|         return null; |         return LibsMsg.LD_COMMAND_PERMTEST; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -27,8 +27,13 @@ public class LDReload implements LDCommand { | |||||||
|         sender.sendMessage(LibsMsg.RELOADED_CONFIG.get()); |         sender.sendMessage(LibsMsg.RELOADED_CONFIG.get()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean hasPermission(CommandSender sender) { | ||||||
|  |         return sender.hasPermission(getPermission()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public LibsMsg getHelp() { |     public LibsMsg getHelp() { | ||||||
|         return null; |         return LibsMsg.LD_COMMAND_RELOAD; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -110,8 +110,13 @@ public class LDScoreboard implements LDCommand { | |||||||
|         sender.sendMessage(LibsMsg.LIBS_SCOREBOARD_SUCCESS.get(team.getName())); |         sender.sendMessage(LibsMsg.LIBS_SCOREBOARD_SUCCESS.get(team.getName())); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean hasPermission(CommandSender sender) { | ||||||
|  |         return sender.hasPermission(getPermission()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public LibsMsg getHelp() { |     public LibsMsg getHelp() { | ||||||
|         return null; |         return LibsMsg.LD_COMMAND_SCOREBOARD; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -73,8 +73,13 @@ public class LDUpdate implements LDCommand { | |||||||
|         }.runTaskAsynchronously(LibsDisguises.getInstance()); |         }.runTaskAsynchronously(LibsDisguises.getInstance()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean hasPermission(CommandSender sender) { | ||||||
|  |         return sender.hasPermission(getPermission()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public LibsMsg getHelp() { |     public LibsMsg getHelp() { | ||||||
|         return null; |         return LibsMsg.LD_COMMAND_UPDATE; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -293,7 +293,26 @@ public enum LibsMsg { | |||||||
|     LIBS_SCOREBOARD_DISABLED( |     LIBS_SCOREBOARD_DISABLED( | ||||||
|             "The scoreboard modification has been disabled in config, will continue the debug incase this is intended" + |             "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 <Player?> - " + 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 <Player?> - " + ChatColor.AQUA + | ||||||
|  |             "Does a quick test to see if your permissions are working"), | ||||||
|  |     LD_COMMAND_SCOREBOARD(ChatColor.BLUE + "/libsdisguises scoreboard <Player?> - " + 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; |     private String string; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user