diff --git a/patches/server/0079-Configurable-unknown-command-message.patch b/patches/server/0079-Configurable-unknown-command-message.patch index 2c495d6e2..62c05be02 100644 --- a/patches/server/0079-Configurable-unknown-command-message.patch +++ b/patches/server/0079-Configurable-unknown-command-message.patch @@ -3,42 +3,142 @@ From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Wed, 7 Aug 2024 18:54:01 +0800 Subject: [PATCH] Configurable unknown command message -TODO - Dreeam: total configurable diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java -index 91eea05a68d0ace8678fc5071e67cedb18a4386b..7af159281a69510d2b0787d472f1af39e1225a47 100644 +index 91eea05a68d0ace8678fc5071e67cedb18a4386b..64d22c2be510ad759bcd6fe192d1ea8cf6bc9a6f 100644 --- a/src/main/java/net/minecraft/commands/Commands.java +++ b/src/main/java/net/minecraft/commands/Commands.java -@@ -390,7 +390,14 @@ public class Commands { +@@ -390,33 +390,10 @@ public class Commands { // Paper start - Add UnknownCommandEvent final net.kyori.adventure.text.TextComponent.Builder builder = net.kyori.adventure.text.Component.text(); // commandlistenerwrapper.sendFailure(ComponentUtils.fromMessage(commandsyntaxexception.getRawMessage())); -+ // Leaf start - Configurable unknown command message -+ if (!"default".equals(org.dreeam.leaf.config.modules.misc.UnknownCommandMessage.unknownCommandMessage)) { -+ net.kyori.adventure.text.Component message = net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(org.dreeam.leaf.config.modules.misc.UnknownCommandMessage.unknownCommandMessage); -+ builder.append(message); -+ } else { - builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.brigadier.PaperBrigadier.componentFromMessage(commandsyntaxexception.getRawMessage())); -+ } -+ // Leaf end - Configurable unknown command message +- builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.brigadier.PaperBrigadier.componentFromMessage(commandsyntaxexception.getRawMessage())); ++ final net.kyori.adventure.text.TextComponent message = getUnknownCommandMessage(builder, commandsyntaxexception, label); // Leaf - Configurable unknown command message // Paper end - Add UnknownCommandEvent - if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) { - int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor()); -@@ -416,7 +423,7 @@ public class Commands { - .append(net.kyori.adventure.text.Component.newline()) - .append(io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent)); - } +- if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) { +- int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor()); +- MutableComponent ichatmutablecomponent = Component.empty().withStyle(ChatFormatting.GRAY).withStyle((chatmodifier) -> { +- return chatmodifier.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + label)); // CraftBukkit // Paper +- }); +- +- if (i > 10) { +- ichatmutablecomponent.append(CommonComponents.ELLIPSIS); +- } +- +- ichatmutablecomponent.append(commandsyntaxexception.getInput().substring(Math.max(0, i - 10), i)); +- if (i < commandsyntaxexception.getInput().length()) { +- MutableComponent ichatmutablecomponent1 = Component.literal(commandsyntaxexception.getInput().substring(i)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE); + +- ichatmutablecomponent.append((Component) ichatmutablecomponent1); +- } +- +- ichatmutablecomponent.append((Component) Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC)); +- // Paper start - Add UnknownCommandEvent +- // commandlistenerwrapper.sendFailure(ichatmutablecomponent); +- builder +- .append(net.kyori.adventure.text.Component.newline()) +- .append(io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent)); +- } - org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(commandlistenerwrapper.getBukkitSender(), s, org.spigotmc.SpigotConfig.unknownCommandMessage.isEmpty() ? null : builder.build()); -+ org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(commandlistenerwrapper.getBukkitSender(), s, builder.build()); // Leaf - Configurable unknown command message ++ org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(commandlistenerwrapper.getBukkitSender(), s, message); // Leaf - Configurable unknown command message org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event); if (event.message() != null) { commandlistenerwrapper.sendFailure(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.message()), false); +@@ -691,6 +668,88 @@ public class Commands { + }; + } + ++ // Leaf start - Configurable unknown command message ++ private static net.kyori.adventure.text.TextComponent getUnknownCommandMessage( ++ net.kyori.adventure.text.TextComponent.Builder builder, CommandSyntaxException commandsyntaxexception, String label ++ ) { ++ String rawMessage = org.dreeam.leaf.config.modules.misc.UnknownCommandMessage.unknownCommandMessage; ++ ++ if (!"default".equals(rawMessage)) { ++ final String input = commandsyntaxexception.getInput(); ++ final int cursor = commandsyntaxexception.getCursor(); ++ ++ if (rawMessage.contains("") && input != null && cursor >= 0) { ++ final int i = Math.min(input.length(), cursor); ++ final net.kyori.adventure.text.TextComponent.Builder detail = net.kyori.adventure.text.Component.text(); ++ final net.kyori.adventure.text.Component context = net.kyori.adventure.text.Component.translatable("command.context.here") ++ .color(net.kyori.adventure.text.format.NamedTextColor.RED) ++ .decorate(net.kyori.adventure.text.format.TextDecoration.ITALIC); ++ final net.kyori.adventure.text.event.ClickEvent event = net.kyori.adventure.text.event.ClickEvent.suggestCommand("/" + label); ++ ++ detail.color(net.kyori.adventure.text.format.NamedTextColor.GRAY); ++ ++ if (i > 10) { ++ detail.append(net.kyori.adventure.text.Component.text("...")); ++ } ++ ++ detail.append(net.kyori.adventure.text.Component.text(input.substring(Math.max(0, i - 10), i))); ++ if (i < input.length()) { ++ net.kyori.adventure.text.Component commandInput = net.kyori.adventure.text.Component.text(input.substring(i)) ++ .color(net.kyori.adventure.text.format.NamedTextColor.RED) ++ .decorate(net.kyori.adventure.text.format.TextDecoration.UNDERLINED); ++ ++ detail.append(commandInput); ++ } ++ ++ detail.append(context); ++ detail.clickEvent(event); ++ ++ builder.append(net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(rawMessage, net.kyori.adventure.text.minimessage.tag.resolver.Placeholder.component("detail", detail.build()))); ++ } else { ++ rawMessage = rawMessage.replace("", ""); ++ builder.append(net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(rawMessage)); ++ } ++ ++ return builder.build(); ++ } ++ ++ return getVanillaUnknownCommandMessage(builder, commandsyntaxexception, label); ++ } ++ ++ private static net.kyori.adventure.text.TextComponent getVanillaUnknownCommandMessage( ++ net.kyori.adventure.text.TextComponent.Builder builder, CommandSyntaxException commandsyntaxexception, String label ++ ) { ++ builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.brigadier.PaperBrigadier.componentFromMessage(commandsyntaxexception.getRawMessage())); ++ ++ if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) { ++ int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor()); ++ MutableComponent ichatmutablecomponent = Component.empty().withStyle(ChatFormatting.GRAY).withStyle((chatmodifier) -> { ++ return chatmodifier.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + label)); // CraftBukkit // Paper ++ }); ++ ++ if (i > 10) { ++ ichatmutablecomponent.append(CommonComponents.ELLIPSIS); ++ } ++ ++ ichatmutablecomponent.append(commandsyntaxexception.getInput().substring(Math.max(0, i - 10), i)); ++ if (i < commandsyntaxexception.getInput().length()) { ++ MutableComponent ichatmutablecomponent1 = Component.literal(commandsyntaxexception.getInput().substring(i)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE); ++ ++ ichatmutablecomponent.append(ichatmutablecomponent1); ++ } ++ ++ ichatmutablecomponent.append(Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC)); ++ // Paper start - Add UnknownCommandEvent ++ // commandlistenerwrapper.sendFailure(ichatmutablecomponent); ++ builder ++ .append(net.kyori.adventure.text.Component.newline()) ++ .append(io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent)); ++ } ++ ++ return builder.build(); ++ } ++ // Leaf end - Configurable unknown command message ++ + public static void validate() { + CommandBuildContext commandbuildcontext = Commands.createValidationContext(VanillaRegistries.createLookup()); + com.mojang.brigadier.CommandDispatcher com_mojang_brigadier_commanddispatcher = (new Commands(Commands.CommandSelection.ALL, commandbuildcontext)).getDispatcher(); diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/UnknownCommandMessage.java b/src/main/java/org/dreeam/leaf/config/modules/misc/UnknownCommandMessage.java new file mode 100644 -index 0000000000000000000000000000000000000000..cfa68915552899ce6ec0b202e1d6cf8a1ca0a777 +index 0000000000000000000000000000000000000000..d54e1aee7421129b25b7a4ce8027816d76e3c368 --- /dev/null +++ b/src/main/java/org/dreeam/leaf/config/modules/misc/UnknownCommandMessage.java -@@ -0,0 +1,20 @@ +@@ -0,0 +1,21 @@ +package org.dreeam.leaf.config.modules.misc; + +import org.dreeam.leaf.config.ConfigModules; @@ -50,12 +150,13 @@ index 0000000000000000000000000000000000000000..cfa68915552899ce6ec0b202e1d6cf8a + return EnumConfigCategory.MISC.getBaseKeyName() + ".message"; + } + -+ public static String unknownCommandMessage = ""; ++ public static String unknownCommandMessage = ""; + + @Override + public void onLoaded() { + unknownCommandMessage = config.getString(getBasePath() + ".unknown-command", unknownCommandMessage, """ -+ Unknown command message, using MiniMessage format, set to "default" to use vanilla message. ++ Unknown command message, using MiniMessage format, set to "default" to use vanilla message, ++ placeholder: , shows detail of the unknown command information. + """); + } +}