2023-12-05 22:51:34 +01:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Sweepyoface <github@sweepy.pw>
|
|
|
|
Date: Sat, 17 Jun 2017 18:48:21 -0400
|
|
|
|
Subject: [PATCH] Add UnknownCommandEvent
|
|
|
|
|
|
|
|
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/CommandSourceStack.java b/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
2024-01-22 19:01:10 +01:00
|
|
|
index f6938c35ac6f6116084d3e7ec9cdc918f20b6f61..edf49f2d9921b4517fb98929d842f7a62c5549df 100644
|
2023-12-05 22:51:34 +01:00
|
|
|
--- a/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
|
|
|
+++ b/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
|
|
|
@@ -334,8 +334,13 @@ public class CommandSourceStack implements ExecutionCommandSource<CommandSourceS
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendFailure(Component message) {
|
2024-01-22 19:01:10 +01:00
|
|
|
+ // Paper start - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
+ this.sendFailure(message, true);
|
|
|
|
+ }
|
|
|
|
+ public void sendFailure(Component message, boolean withStyle) {
|
2024-01-22 19:01:10 +01:00
|
|
|
+ // Paper end - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
if (this.source.acceptsFailure() && !this.silent) {
|
|
|
|
- this.source.sendSystemMessage(Component.empty().append(message).withStyle(ChatFormatting.RED));
|
2024-01-22 19:01:10 +01:00
|
|
|
+ this.source.sendSystemMessage(withStyle ? Component.empty().append(message).withStyle(ChatFormatting.RED) : message); // Paper - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
|
2024-01-22 19:01:10 +01:00
|
|
|
index 495a7b713a7ab9c19aad34512b76523bad43b89d..15a5059994371da4850adcf726034a715b80efba 100644
|
2023-12-05 22:51:34 +01:00
|
|
|
--- a/src/main/java/net/minecraft/commands/Commands.java
|
|
|
|
+++ b/src/main/java/net/minecraft/commands/Commands.java
|
|
|
|
@@ -152,6 +152,7 @@ public class Commands {
|
|
|
|
public static final int LEVEL_ADMINS = 3;
|
|
|
|
public static final int LEVEL_OWNERS = 4;
|
|
|
|
private final com.mojang.brigadier.CommandDispatcher<CommandSourceStack> dispatcher = new com.mojang.brigadier.CommandDispatcher();
|
2024-01-22 19:01:10 +01:00
|
|
|
+ public final java.util.List<CommandNode<CommandSourceStack>> vanillaCommandNodes = new java.util.ArrayList<>(); // Paper - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
|
|
|
|
public Commands(Commands.CommandSelection environment, CommandBuildContext commandRegistryAccess) {
|
|
|
|
this(); // CraftBukkit
|
|
|
|
@@ -254,6 +255,7 @@ public class Commands {
|
|
|
|
if (environment.includeIntegrated) {
|
|
|
|
PublishCommand.register(this.dispatcher);
|
|
|
|
}
|
2024-01-22 19:01:10 +01:00
|
|
|
+ this.vanillaCommandNodes.addAll(this.dispatcher.getRoot().getChildren()); // Paper - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
}
|
|
|
|
@@ -328,7 +330,7 @@ public class Commands {
|
|
|
|
commandlistenerwrapper.getServer().getProfiler().push(() -> {
|
|
|
|
return "/" + s;
|
|
|
|
});
|
|
|
|
- ContextChain contextchain = Commands.finishParsing(parseresults, s, commandlistenerwrapper, label); // CraftBukkit
|
2024-01-22 19:01:10 +01:00
|
|
|
+ ContextChain contextchain = this.finishParsing(parseresults, s, commandlistenerwrapper, label); // CraftBukkit // Paper - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (contextchain != null) {
|
|
|
|
@@ -362,14 +364,23 @@ public class Commands {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
- private static ContextChain<CommandSourceStack> finishParsing(ParseResults<CommandSourceStack> parseresults, String s, CommandSourceStack commandlistenerwrapper, String label) { // CraftBukkit
|
2024-01-22 19:01:10 +01:00
|
|
|
+ private ContextChain<CommandSourceStack> finishParsing(ParseResults<CommandSourceStack> parseresults, String s, CommandSourceStack commandlistenerwrapper, String label) { // CraftBukkit // Paper - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
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()));
|
2024-01-22 19:01:10 +01:00
|
|
|
+ // Paper start - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
+ 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()));
|
2024-01-22 19:01:10 +01:00
|
|
|
+ // Paper end - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
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) -> {
|
2024-01-22 19:01:10 +01:00
|
|
|
@@ -388,7 +399,18 @@ public class Commands {
|
2023-12-05 22:51:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ichatmutablecomponent.append((Component) Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
|
|
|
|
- commandlistenerwrapper.sendFailure(ichatmutablecomponent);
|
2024-01-22 19:01:10 +01:00
|
|
|
+ // Paper start - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
+ // 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);
|
2024-01-22 19:01:10 +01:00
|
|
|
+ // Paper end - Add UnknownCommandEvent
|
2023-12-05 22:51:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2024-01-24 22:13:08 +01:00
|
|
|
index 7678b7eb8561bca272bdb26de5a9f96bd18d005d..59776663cee396f29f05988d8e22dd5c23b118b5 100644
|
2023-12-05 22:51:34 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -527,6 +527,7 @@ public final class CraftServer implements Server {
|
2023-12-05 22:51:34 +01:00
|
|
|
}
|
|
|
|
node = clone;
|
|
|
|
}
|
|
|
|
+ dispatcher.vanillaCommandNodes.add(node); // Paper
|
|
|
|
|
|
|
|
dispatcher.getDispatcher().getRoot().addChild(node);
|
|
|
|
} else {
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -899,7 +900,13 @@ public final class CraftServer implements Server {
|
2023-12-05 22:51:34 +01:00
|
|
|
|
|
|
|
// Spigot start
|
|
|
|
if (!org.spigotmc.SpigotConfig.unknownCommandMessage.isEmpty()) {
|
|
|
|
- sender.sendMessage(org.spigotmc.SpigotConfig.unknownCommandMessage);
|
|
|
|
+ // Paper start
|
|
|
|
+ org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(sender, commandLine, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.unknownCommandMessage));
|
|
|
|
+ Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
+ if (event.message() != null) {
|
|
|
|
+ sender.sendMessage(event.message());
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
|