9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-22 16:39:22 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0054-Configurable-unknown-command-message.patch
Dreeam 387597f347 Updated Upstream (Leaves)
Upstream has released updates that appear to apply and compile correctly

Leaves Changes:
LeavesMC/Leaves@88819fe8 Add mc-old hopper suck-in behavior (#395)
LeavesMC/Leaves@7394e8dd Fix papermc repo
LeavesMC/Leaves@85c7bf11 Remove cache-world-generator-sea-level (#392)
LeavesMC/Leaves@00798036 init 1.21.4, and boom!
LeavesMC/Leaves@91fc24da build change, but weight not work
LeavesMC/Leaves@4ccdf459 just work
LeavesMC/Leaves@05ee2e36 Build changes, and delete timings
LeavesMC/Leaves@fcc859dc Fix API patches (#406)
LeavesMC/Leaves@6a1259df 0006/0129
LeavesMC/Leaves@3e3b05df 0009/0129
LeavesMC/Leaves@c3255c4f 0011/0129
LeavesMC/Leaves@6284c7b6 0018/0129
LeavesMC/Leaves@7abdc88c 0030/0129
LeavesMC/Leaves@4d119ff9 0035/0129
LeavesMC/Leaves@60baed99 0043/0129
LeavesMC/Leaves@dc319d5b 0048/0129
LeavesMC/Leaves@73a505d5 0049/0129
LeavesMC/Leaves@016b29dd 0057/0129
LeavesMC/Leaves@c9cf5af8 0065/0129
LeavesMC/Leaves@330b79ff 0086/0129 (#408)
LeavesMC/Leaves@06c1d946 0087/0129
LeavesMC/Leaves@bf4bc284 0091/0129
LeavesMC/Leaves@102a3b70 0097/0129
LeavesMC/Leaves@53b43fed 0101/0129
LeavesMC/Leaves@892f3925 102/129
LeavesMC/Leaves@08c3043a 0107/0129
LeavesMC/Leaves@48764d8e 0112/0129
LeavesMC/Leaves@8380feff 0118/0129
LeavesMC/Leaves@e51603db 0129/0129, 100% patched
LeavesMC/Leaves@ef851152 fix some
LeavesMC/Leaves@9b7c6e88 server work
LeavesMC/Leaves@272b7dcb Protocol... (#409)
LeavesMC/Leaves@7be1bc97 Make jade better
LeavesMC/Leaves@5350f6ea Make action work
LeavesMC/Leaves@f07c26c8 fix action jar
2025-02-06 23:28:14 -05:00

132 lines
8.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Wed, 7 Aug 2024 18:54:01 +0800
Subject: [PATCH] Configurable unknown command message
diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java
index d8464f77c54f547161356b78e76429923937b4a7..a59162764f141d9bb88c7084c66661f14de7ad57 100644
--- a/net/minecraft/commands/Commands.java
+++ b/net/minecraft/commands/Commands.java
@@ -389,31 +389,9 @@ public class Commands {
// Paper start - Add UnknownCommandEvent
final net.kyori.adventure.text.TextComponent.Builder builder = net.kyori.adventure.text.Component.text();
// source.sendFailure(ComponentUtils.fromMessage(var7.getRawMessage()));
- builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.command.brigadier.MessageComponentSerializer.message().deserialize(var7.getRawMessage()));
+ final net.kyori.adventure.text.TextComponent message = getUnknownCommandMessage(builder, var7, label); // Leaf - Configurable unknown command message
// Paper end - Add UnknownCommandEvent
- if (var7.getInput() != null && var7.getCursor() >= 0) {
- int min = Math.min(var7.getInput().length(), var7.getCursor());
- MutableComponent mutableComponent = Component.empty()
- .withStyle(ChatFormatting.GRAY)
- .withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + label))); // CraftBukkit // Paper
- if (min > 10) {
- mutableComponent.append(CommonComponents.ELLIPSIS);
- }
-
- mutableComponent.append(var7.getInput().substring(Math.max(0, min - 10), min));
- if (min < var7.getInput().length()) {
- Component component = Component.literal(var7.getInput().substring(min)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE);
- mutableComponent.append(component);
- }
-
- mutableComponent.append(Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
- // Paper start - Add UnknownCommandEvent
- // source.sendFailure(mutableComponent);
- builder
- .append(net.kyori.adventure.text.Component.newline())
- .append(io.papermc.paper.adventure.PaperAdventure.asAdventure(mutableComponent));
- }
- org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(source.getBukkitSender(), command, org.spigotmc.SpigotConfig.unknownCommandMessage.isEmpty() ? null : builder.build());
+ org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(source.getBukkitSender(), command, message); // Leaf - Configurable unknown command message
org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event);
if (event.message() != null) {
source.sendFailure(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.message()), false);
@@ -676,6 +654,86 @@ 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("<detail>") && input != null && cursor >= 0) {
+ final int min = 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 (min > 10) {
+ detail.append(net.kyori.adventure.text.Component.text("..."));
+ }
+
+ detail.append(net.kyori.adventure.text.Component.text(input.substring(Math.max(0, min - 10), min)));
+ if (min < input.length()) {
+ net.kyori.adventure.text.Component commandInput = net.kyori.adventure.text.Component.text(input.substring(min))
+ .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("<detail>", "");
+ 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 var7, String label
+ ) {
+ builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.command.brigadier.MessageComponentSerializer.message().deserialize(var7.getRawMessage()));
+
+ if (var7.getInput() != null && var7.getCursor() >= 0) {
+ int min = Math.min(var7.getInput().length(), var7.getCursor());
+ MutableComponent mutableComponent = Component.empty()
+ .withStyle(ChatFormatting.GRAY)
+ .withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + label))); // CraftBukkit // Paper
+ if (min > 10) {
+ mutableComponent.append(CommonComponents.ELLIPSIS);
+ }
+
+ mutableComponent.append(var7.getInput().substring(Math.max(0, min - 10), min));
+ if (min < var7.getInput().length()) {
+ Component component = Component.literal(var7.getInput().substring(min)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE);
+ mutableComponent.append(component);
+ }
+
+ mutableComponent.append(Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
+ // Paper start - Add UnknownCommandEvent
+ // source.sendFailure(mutableComponent);
+ builder
+ .append(net.kyori.adventure.text.Component.newline())
+ .append(io.papermc.paper.adventure.PaperAdventure.asAdventure(mutableComponent));
+ }
+
+ return builder.build();
+ }
+ // Leaf end - Configurable unknown command message
+
public static void validate() {
CommandBuildContext commandBuildContext = createValidationContext(VanillaRegistries.createLookup());
CommandDispatcher<CommandSourceStack> dispatcher = new Commands(Commands.CommandSelection.ALL, commandBuildContext).getDispatcher();