Add /libsdisguises help
This commit is contained in:
		| @@ -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<LDCommand> commands = new ArrayList<>(); | ||||
|     @Getter | ||||
|     private final ArrayList<LDCommand> 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<String> filterTabs(ArrayList<String> 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<String> 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; | ||||
|             } | ||||
|  | ||||
|   | ||||
| @@ -11,6 +11,8 @@ import java.util.List; | ||||
| public interface LDCommand { | ||||
|     List<String> getTabComplete(); | ||||
|  | ||||
|     boolean hasPermission(CommandSender sender); | ||||
|  | ||||
|     String getPermission(); | ||||
|  | ||||
|     void onCommand(CommandSender sender, String[] args); | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean hasPermission(CommandSender sender) { | ||||
|         return sender.hasPermission(getPermission()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     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 | ||||
|     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(), ", "))); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean hasPermission(CommandSender sender) { | ||||
|         return sender.hasPermission(getPermission()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     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 | ||||
|     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()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean hasPermission(CommandSender sender) { | ||||
|         return sender.hasPermission(getPermission()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     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())); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean hasPermission(CommandSender sender) { | ||||
|         return sender.hasPermission(getPermission()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public LibsMsg getHelp() { | ||||
|         return null; | ||||
|         return LibsMsg.LD_COMMAND_SCOREBOARD; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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 <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; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user