diff --git a/src/main/java/fr/alexdoru/mwe/commands/CommandAddAlias.java b/src/main/java/fr/alexdoru/mwe/commands/CommandAddAlias.java index 08e02f87..01a7e687 100644 --- a/src/main/java/fr/alexdoru/mwe/commands/CommandAddAlias.java +++ b/src/main/java/fr/alexdoru/mwe/commands/CommandAddAlias.java @@ -72,15 +72,13 @@ public List getCommandAliases() { @Override protected void printCommandHelp() { - ChatUtil.addChatMessage( - EnumChatFormatting.GREEN + ChatUtil.bar() + "\n" - + ChatUtil.centerLine(EnumChatFormatting.GOLD + "AddAlias Help\n\n") - + EnumChatFormatting.YELLOW + "/addalias" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "Lists the alias in the lobby\n" - + EnumChatFormatting.YELLOW + "/addalias " + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "Adds an alias for the player\n" - + EnumChatFormatting.YELLOW + "/addalias " + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "Removes the alias for the player\n" - + EnumChatFormatting.YELLOW + "/addalias list" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "Prints list of alias\n" - + EnumChatFormatting.GREEN + ChatUtil.bar() - ); + final String slashCommand = '/' + getCommandName(); + printCommandHelpBlock(EnumChatFormatting.GREEN, "AddAlias Help", new String[][]{ + { slashCommand, "Lists the alias in the lobby" }, + { slashCommand + " ", "Adds an alias for the player" }, + { slashCommand + " ", "Removes the alias for the player" }, + { slashCommand + " list", "Prints list of alias" } + }); } private void listAlias(String[] args) { diff --git a/src/main/java/fr/alexdoru/mwe/commands/CommandFKCounter.java b/src/main/java/fr/alexdoru/mwe/commands/CommandFKCounter.java index b2fb642e..f68caf12 100644 --- a/src/main/java/fr/alexdoru/mwe/commands/CommandFKCounter.java +++ b/src/main/java/fr/alexdoru/mwe/commands/CommandFKCounter.java @@ -64,7 +64,7 @@ public void processCommand(ICommandSender sender, String[] args) { sendChatMessage("You shouldn't ask for finals and instead try to final kill everyone to win the game!"); - } else if (args.length > 0 && args[0].equalsIgnoreCase("help")) { + } else if (args.length > 0 && isHelpSubcommand(args[0])) { this.printCommandHelp(); @@ -113,14 +113,12 @@ public List addTabCompletionOptions(ICommandSender sender, String[] args @Override protected void printCommandHelp() { - ChatUtil.addChatMessage( - EnumChatFormatting.AQUA + ChatUtil.bar() + "\n" - + ChatUtil.centerLine(EnumChatFormatting.GOLD + "Fks Help") + "\n\n" - + EnumChatFormatting.YELLOW + "/fks" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "prints the amount of finals per team in the chat\n" - + EnumChatFormatting.YELLOW + "/fks players" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "prints the amount of finals per player in the chat\n" - + EnumChatFormatting.YELLOW + "/fks settings" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "opens the settings GUI\n" - + EnumChatFormatting.AQUA + ChatUtil.bar() - ); + final String slashCommand = '/' + getCommandName(); + printCommandHelpBlock(EnumChatFormatting.AQUA, "Fks Help", new String[][]{ + { slashCommand, "prints the amount of finals per team in the chat" }, + { slashCommand + " players", "prints the amount of finals per player in the chat" }, + { slashCommand + " settings", "opens the settings GUI" } + }); } private void removePlayer(String playerName) { diff --git a/src/main/java/fr/alexdoru/mwe/commands/CommandNocheaters.java b/src/main/java/fr/alexdoru/mwe/commands/CommandNocheaters.java index 8d1dec83..65568ee3 100644 --- a/src/main/java/fr/alexdoru/mwe/commands/CommandNocheaters.java +++ b/src/main/java/fr/alexdoru/mwe/commands/CommandNocheaters.java @@ -58,13 +58,11 @@ public List addTabCompletionOptions(ICommandSender sender, String[] args @Override protected void printCommandHelp() { - ChatUtil.addChatMessage( - RED + ChatUtil.bar() + "\n" - + ChatUtil.centerLine(GOLD + "NoCheaters Help\n\n") - + YELLOW + getCommandUsage(null) + GRAY + " - " + AQUA + "prints the list of reported players in your current world\n" - + YELLOW + getCommandUsage(null) + " reportlist" + GRAY + " - " + AQUA + "prints the list of reported players\n" - + RED + ChatUtil.bar() - ); + final String slashCommand = '/' + getCommandName(); + printCommandHelpBlock(RED, "NoCheaters Help", new String[][]{ + { slashCommand, "prints the list of reported players in your current world" }, + { slashCommand + " reportlist", "prints the list of reported players" } + }); } private void printReportList(String[] args) { diff --git a/src/main/java/fr/alexdoru/mwe/commands/CommandPlancke.java b/src/main/java/fr/alexdoru/mwe/commands/CommandPlancke.java index 79e221f1..a7a7f6dc 100644 --- a/src/main/java/fr/alexdoru/mwe/commands/CommandPlancke.java +++ b/src/main/java/fr/alexdoru/mwe/commands/CommandPlancke.java @@ -151,19 +151,16 @@ public List addTabCompletionOptions(ICommandSender sender, String[] args @Override protected void printCommandHelp() { - ChatUtil.addChatMessage( - EnumChatFormatting.AQUA + ChatUtil.bar() + "\n" - + ChatUtil.centerLine(EnumChatFormatting.GOLD + "Plancke Help\n\n") - + EnumChatFormatting.YELLOW + "/plancke " + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "General Hypixel stats\n" - + EnumChatFormatting.YELLOW + "/plancke bsg" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "Blitz stats\n" - + EnumChatFormatting.YELLOW + "/plancke sw" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "Skywars stats\n" - + EnumChatFormatting.YELLOW + "/plancke uhc" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "UHC stats\n" - + EnumChatFormatting.YELLOW + "/plancke mw" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "General Mega Walls stats\n" - + EnumChatFormatting.YELLOW + "/plancke mw classname" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "Class specific Mega Walls stats\n" - + EnumChatFormatting.YELLOW + "/plancke mw cp" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "Mega Walls classpoints\n" - + EnumChatFormatting.YELLOW + "/plancke mw leg" + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + "Mega Walls legendary skins\n" - + EnumChatFormatting.AQUA + ChatUtil.bar() - ); + final String slashCommand = '/' + getCommandName(); + printCommandHelpBlock(EnumChatFormatting.AQUA, "Plancke Help", new String[][]{ + { slashCommand + " ", "General Hypixel stats" }, + { slashCommand + " bsg", "Blitz stats" }, + { slashCommand + " sw", "Skywars stats" }, + { slashCommand + " uhc", "UHC stats" }, + { slashCommand + " mw", "General Mega Walls stats" }, + { slashCommand + " mw classname", "Class specific Mega Walls stats" }, + { slashCommand + " mw cp", "Mega Walls classpoints" }, + { slashCommand + " mw leg", "Mega Walls legendary skins" }, + }); } - } diff --git a/src/main/java/fr/alexdoru/mwe/commands/CommandSquad.java b/src/main/java/fr/alexdoru/mwe/commands/CommandSquad.java index d425cffa..924c454c 100644 --- a/src/main/java/fr/alexdoru/mwe/commands/CommandSquad.java +++ b/src/main/java/fr/alexdoru/mwe/commands/CommandSquad.java @@ -93,18 +93,16 @@ public List addTabCompletionOptions(ICommandSender sender, String[] args @Override protected void printCommandHelp() { - ChatUtil.addChatMessage( - GREEN + ChatUtil.bar() + "\n" - + ChatUtil.centerLine(GOLD + "Squad Help\n\n") - + YELLOW + "/squad add " + GRAY + " - " + AQUA + "add a player to the squad\n" - + YELLOW + "/squad add as Nickname" + GRAY + " - " + AQUA + "add a player to the squad and change their name\n" - + YELLOW + "/squad addteam" + GRAY + " - " + AQUA + "add all your teamates to the squad\n" - + YELLOW + "/squad formsquad" + GRAY + " - " + AQUA + "add your teamates to the squad when in a MW pre game\n" - + YELLOW + "/squad remove " + GRAY + " - " + AQUA + "remove a player from the squad\n" - + YELLOW + "/squad list" + GRAY + " - " + AQUA + "list players in the squad\n" - + YELLOW + "/squad disband" + GRAY + " - " + AQUA + "disband the squad\n" - + GREEN + ChatUtil.bar() - ); + final String slashCommand = '/' + getCommandName(); + printCommandHelpBlock(GREEN, "Squad Help", new String[][]{ + { slashCommand + " add ", "add a player to the squad" }, + {slashCommand + " add as ", "add a player to the squad and change their name"}, + { slashCommand + " addteam", "add all your teammates to the squad" }, + { slashCommand + " formsquad", "add your teammates to the squad when in a MW pre game" }, + { slashCommand + " remove ", "remove a player from the squad" }, + { slashCommand + " list", "list players in the squad" }, + { slashCommand + " disband", "disband the squad" } + }); } private static void addSquadMembers(String[] args) { diff --git a/src/main/java/fr/alexdoru/mwe/commands/MyAbstractCommand.java b/src/main/java/fr/alexdoru/mwe/commands/MyAbstractCommand.java index 29130e64..5ba0f106 100644 --- a/src/main/java/fr/alexdoru/mwe/commands/MyAbstractCommand.java +++ b/src/main/java/fr/alexdoru/mwe/commands/MyAbstractCommand.java @@ -1,8 +1,14 @@ package fr.alexdoru.mwe.commands; +import fr.alexdoru.mwe.chat.ChatUtil; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; +import net.minecraft.event.ClickEvent; +import net.minecraft.event.HoverEvent; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; public abstract class MyAbstractCommand extends CommandBase { @@ -33,4 +39,38 @@ protected static void sendChatMessage(String msg) { } } + protected static boolean isHelpSubcommand(String subcommand) { + return "h".equalsIgnoreCase(subcommand) || "help".equalsIgnoreCase(subcommand); + } + + /** + * Prints command help lines grouped inside 2 horizontal bars + * + * @see #printCommandHelpBlock(String, String[][]) + */ + protected static void printCommandHelpBlock(EnumChatFormatting barColor, String header, String[][] commandLines) { + final String bar = barColor + ChatUtil.bar(); + ChatUtil.addChatMessage(new ChatComponentText(bar)); + MyAbstractCommand.printCommandHelpBlock(header, commandLines); + ChatUtil.addChatMessage(new ChatComponentText(bar)); + } + + /** + * @param header Block Header + * @param commandLines Each command-line must be in this format: { command, description, [commandToPutOnClick] }. + * if (commandToPutOnClick) isn't provided will use (command) + */ + private static void printCommandHelpBlock(String header, String[][] commandLines) { + ChatUtil.addChatMessage(new ChatComponentText(ChatUtil.centerLine(EnumChatFormatting.GOLD + header))); + for (final String[] line : commandLines) { + if (line.length!=2) continue; + final String command = line[0]; + final String desc = line[1]; + ChatUtil.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + command + EnumChatFormatting.GRAY + " - " + EnumChatFormatting.AQUA + desc) + .setChatStyle(new ChatStyle() + .setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(EnumChatFormatting.GRAY + "Click to put the command in chat."))) + .setChatClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command))) + ); + } + } }