diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java index c45817d7..f6cac891 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java @@ -95,6 +95,12 @@ public void init() { .executes(this::statusCommand) .build(); + LiteralCommandNode helpCommand = + literal("help") + .requires(requirementsUnloaded("bluemap.help")) + .executes(this::helpCommand) + .build(); + LiteralCommandNode reloadCommand = literal("reload") .requires(requirementsUnloaded("bluemap.reload")) @@ -216,6 +222,7 @@ public void init() { // command tree dispatcher.getRoot().addChild(baseCommand); + baseCommand.addChild(helpCommand); baseCommand.addChild(reloadCommand); baseCommand.addChild(debugCommand); baseCommand.addChild(pauseCommand); @@ -304,6 +311,34 @@ public int statusCommand(CommandContext context) { return 1; } + public int helpCommand(CommandContext context) { + CommandSource source = commandSourceInterface.apply(context.getSource()); + + source.sendMessage(Text.of(TextColor.BLUE, "BlueMap Commands:")); + for (String usage : dispatcher.getAllUsage(dispatcher.getRoot().getChild("bluemap"), context.getSource(), true)) { + Text usageText = Text.of(TextColor.GREEN, "/bluemap"); + + String[] arguments = usage.split(" "); + for (String arg : arguments) { + if (arg.isEmpty()) continue; + if (arg.charAt(0) == '<' && arg.charAt(arg.length() - 1) == '>') { + usageText.addChild(Text.of(TextColor.GRAY, " " + arg)); + } else { + usageText.addChild(Text.of(TextColor.WHITE, " " + arg)); + } + } + + source.sendMessage(usageText); + } + + source.sendMessage( + Text.of(TextColor.BLUE, "\nOpen this link to get a description for each command:\n") + .addChild(Text.of(TextColor.GRAY, "https://bluecolo.red/bluemap-commands").setClickLink("https://bluecolo.red/bluemap-commands")) + ); + + return 1; + } + public int reloadCommand(CommandContext context) { CommandSource source = commandSourceInterface.apply(context.getSource()); diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/text/Text.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/text/Text.java index a3641939..d05ed42d 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/text/Text.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/text/Text.java @@ -36,6 +36,7 @@ public class Text { private Set formats = new HashSet<>(); private Text hoverText; private String clickCommand; + private String clickLink; private List children = new ArrayList<>(); public Text setHoverText(Text hoverText) { @@ -50,6 +51,12 @@ public Text setClickCommand(String clickCommand) { return this; } + public Text setClickLink(String clickLink) { + this.clickLink = clickLink; + + return this; + } + public Text addChild(Text child) { children.add(child); @@ -82,6 +89,13 @@ public String toJSONString() { sb.append(quote("action")).append(":").append(quote("run_command")).append(','); sb.append(quote("value")).append(":").append(quote(clickCommand)); sb.append("},"); + } + + else if (clickLink != null) { + sb.append(quote("clickEvent")).append(":{"); + sb.append(quote("action")).append(":").append(quote("open_url")).append(','); + sb.append(quote("value")).append(":").append(quote(clickLink)); + sb.append("},"); } if (!children.isEmpty()) { diff --git a/implementations/spigot/src/main/resources/plugin.yml b/implementations/spigot/src/main/resources/plugin.yml index 0db125e0..9b0eb29e 100644 --- a/implementations/spigot/src/main/resources/plugin.yml +++ b/implementations/spigot/src/main/resources/plugin.yml @@ -10,6 +10,7 @@ permissions: bluemap.*: children: bluemap.status: true + bluemap.help: true bluemap.reload: true bluemap.pause: true bluemap.resume: true @@ -19,6 +20,8 @@ permissions: default: op bluemap.status: default: op + bluemap.help: + default: op bluemap.reload: default: op bluemap.pause: