From a433529d07b19c0c2e202328909028c5ee2a4bcd Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 5 Dec 2023 13:51:34 -0800 Subject: [PATCH] port UnknownCommandEvent patch --- .../server/Add-UnknownCommandEvent.patch | 89 ++++++++++++------- 1 file changed, 57 insertions(+), 32 deletions(-) rename patches/{unapplied => }/server/Add-UnknownCommandEvent.patch (51%) diff --git a/patches/unapplied/server/Add-UnknownCommandEvent.patch b/patches/server/Add-UnknownCommandEvent.patch similarity index 51% rename from patches/unapplied/server/Add-UnknownCommandEvent.patch rename to patches/server/Add-UnknownCommandEvent.patch index 3f33774eaa..2b2db9abb4 100644 --- a/patches/unapplied/server/Add-UnknownCommandEvent.patch +++ b/patches/server/Add-UnknownCommandEvent.patch @@ -9,7 +9,7 @@ diff --git a/src/main/java/net/minecraft/commands/CommandSourceStack.java b/src/ index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/commands/CommandSourceStack.java +++ b/src/main/java/net/minecraft/commands/CommandSourceStack.java -@@ -0,0 +0,0 @@ public class CommandSourceStack implements SharedSuggestionProvider { +@@ -0,0 +0,0 @@ public class CommandSourceStack implements ExecutionCommandSource { + return "/" + s; + }); +- ContextChain contextchain = Commands.finishParsing(parseresults, s, commandlistenerwrapper, label); // CraftBukkit ++ ContextChain contextchain = this.finishParsing(parseresults, s, commandlistenerwrapper, label); // CraftBukkit // Paper - make finishParsing not static + + try { + if (contextchain != null) { +@@ -0,0 +0,0 @@ public class Commands { + } + + @Nullable +- private static ContextChain finishParsing(ParseResults parseresults, String s, CommandSourceStack commandlistenerwrapper, String label) { // CraftBukkit ++ private ContextChain finishParsing(ParseResults parseresults, String s, CommandSourceStack commandlistenerwrapper, String label) { // CraftBukkit // Paper - make not static + try { + Commands.validateParseResults(parseresults); + return (ContextChain) ContextChain.tryFlatten(parseresults.getContext().build(s)).orElseThrow(() -> { + return CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().createWithContext(parseresults.getReader()); + }); + } catch (CommandSyntaxException commandsyntaxexception) { +- commandlistenerwrapper.sendFailure(ComponentUtils.fromMessage(commandsyntaxexception.getRawMessage())); ++ // Paper start ++ final net.kyori.adventure.text.TextComponent.Builder builder = net.kyori.adventure.text.Component.text(); ++ if ((parseresults.getContext().getNodes().isEmpty() || !this.vanillaCommandNodes.contains(parseresults.getContext().getNodes().get(0).getNode()))) { ++ if (!org.spigotmc.SpigotConfig.unknownCommandMessage.isEmpty()) { ++ builder.append(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.unknownCommandMessage)); ++ } ++ } else { + // commandlistenerwrapper.sendFailure(ComponentUtils.fromMessage(commandsyntaxexception.getRawMessage())); + builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.brigadier.PaperBrigadier.componentFromMessage(commandsyntaxexception.getRawMessage())); + // Paper end - if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) { - int j = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor()); - MutableComponent ichatmutablecomponent = Component.empty().withStyle(ChatFormatting.GRAY).withStyle((chatmodifier) -> { + 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) -> { @@ -0,0 +0,0 @@ public class Commands { - } - - ichatmutablecomponent.append((Component) Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC)); -- commandlistenerwrapper.sendFailure(ichatmutablecomponent); -+ // Paper start -+ // 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.Bukkit.getServer().getPluginManager().callEvent(event); -+ if (event.message() != null) { -+ commandlistenerwrapper.sendFailure(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.message()), false); -+ // Paper end + ichatmutablecomponent.append(CommonComponents.ELLIPSIS); } - b1 = 0; ++ + 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); +@@ -0,0 +0,0 @@ public class Commands { + } + + ichatmutablecomponent.append((Component) Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC)); +- commandlistenerwrapper.sendFailure(ichatmutablecomponent); ++ // Paper start ++ // 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.Bukkit.getServer().getPluginManager().callEvent(event); ++ if (event.message() != null) { ++ commandlistenerwrapper.sendFailure(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.message()), false); ++ // Paper end + } + + return null; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java