geforkt von Mirrors/Paper
Add UnknownCommandEvent
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
bb90110894
Commit
551d6ee71e
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
public CommandSourceStack(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String name, Component displayName, MinecraftServer server, @Nullable Entity entity) {
|
public CommandSourceStack(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String name, Component displayName, MinecraftServer server, @Nullable Entity entity) {
|
||||||
this(output, pos, rot, world, level, name, displayName, server, entity, false, CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(server));
|
this(output, pos, rot, world, level, name, displayName, server, entity, false, CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(server));
|
||||||
@@ -171,9 +174,23 @@
|
@@ -171,8 +174,22 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(int level) {
|
public boolean hasPermission(int level) {
|
||||||
@ -30,18 +30,17 @@
|
|||||||
+
|
+
|
||||||
return this.permissionLevel >= level;
|
return this.permissionLevel >= level;
|
||||||
}
|
}
|
||||||
|
+
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ public boolean hasPermission(int i, String bukkitPermission) {
|
+ public boolean hasPermission(int i, String bukkitPermission) {
|
||||||
+ // World is null when loading functions
|
+ // World is null when loading functions
|
||||||
+ return ((this.getLevel() == null || !this.getLevel().getCraftServer().ignoreVanillaPermissions) && this.permissionLevel >= i) || this.getBukkitSender().hasPermission(bukkitPermission);
|
+ return ((this.getLevel() == null || !this.getLevel().getCraftServer().ignoreVanillaPermissions) && this.permissionLevel >= i) || this.getBukkitSender().hasPermission(bukkitPermission);
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+
|
|
||||||
public Vec3 getPosition() {
|
public Vec3 getPosition() {
|
||||||
return this.worldPosition;
|
return this.worldPosition;
|
||||||
}
|
@@ -302,21 +319,26 @@
|
||||||
@@ -302,13 +319,13 @@
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
||||||
|
|
||||||
@ -57,7 +56,21 @@
|
|||||||
this.server.sendSystemMessage(ichatmutablecomponent);
|
this.server.sendSystemMessage(ichatmutablecomponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,4 +417,10 @@
|
}
|
||||||
|
|
||||||
|
public void sendFailure(Component message) {
|
||||||
|
+ // Paper start - Add UnknownCommandEvent
|
||||||
|
+ this.sendFailure(message, true);
|
||||||
|
+ }
|
||||||
|
+ public void sendFailure(Component message, boolean withStyle) {
|
||||||
|
+ // Paper end - Add UnknownCommandEvent
|
||||||
|
if (this.source.acceptsFailure() && !this.silent) {
|
||||||
|
- this.source.sendSystemMessage(Component.empty().append(message).withStyle(ChatFormatting.RED));
|
||||||
|
+ this.source.sendSystemMessage(withStyle ? Component.empty().append(message).withStyle(ChatFormatting.RED) : message); // Paper - Add UnknownCommandEvent
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@@ -400,4 +422,10 @@
|
||||||
public boolean isSilent() {
|
public boolean isSilent() {
|
||||||
return this.silent;
|
return this.silent;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
--- a/net/minecraft/commands/Commands.java
|
--- a/net/minecraft/commands/Commands.java
|
||||||
+++ b/net/minecraft/commands/Commands.java
|
+++ b/net/minecraft/commands/Commands.java
|
||||||
@@ -138,6 +138,14 @@
|
@@ -139,6 +139,14 @@
|
||||||
import net.minecraft.world.flag.FeatureFlags;
|
|
||||||
import net.minecraft.world.level.GameRules;
|
import net.minecraft.world.level.GameRules;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
+
|
|
||||||
+// CraftBukkit start
|
+// CraftBukkit start
|
||||||
+import com.google.common.base.Joiner;
|
+import com.google.common.base.Joiner;
|
||||||
+import java.util.Collection;
|
+import java.util.Collection;
|
||||||
@ -12,9 +11,10 @@
|
|||||||
+import org.bukkit.event.player.PlayerCommandSendEvent;
|
+import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||||
+import org.bukkit.event.server.ServerCommandEvent;
|
+import org.bukkit.event.server.ServerCommandEvent;
|
||||||
+// CraftBukkit end
|
+// CraftBukkit end
|
||||||
|
+
|
||||||
public class Commands {
|
public class Commands {
|
||||||
|
|
||||||
|
private static final ThreadLocal<ExecutionContext<CommandSourceStack>> CURRENT_EXECUTION_CONTEXT = new ThreadLocal();
|
||||||
@@ -151,6 +159,7 @@
|
@@ -151,6 +159,7 @@
|
||||||
private final com.mojang.brigadier.CommandDispatcher<CommandSourceStack> dispatcher = new com.mojang.brigadier.CommandDispatcher();
|
private final com.mojang.brigadier.CommandDispatcher<CommandSourceStack> dispatcher = new com.mojang.brigadier.CommandDispatcher();
|
||||||
|
|
||||||
@ -35,12 +35,13 @@
|
|||||||
this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer());
|
this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,32 +274,79 @@
|
@@ -262,30 +276,77 @@
|
||||||
CommandContextBuilder<S> commandcontextbuilder1 = commandcontextbuilder.withSource(sourceMapper.apply(commandcontextbuilder.getSource()));
|
|
||||||
|
|
||||||
return new ParseResults(commandcontextbuilder1, parseResults.getReader(), parseResults.getExceptions());
|
return new ParseResults(commandcontextbuilder1, parseResults.getReader(), parseResults.getExceptions());
|
||||||
+ }
|
}
|
||||||
+
|
|
||||||
|
- public void performPrefixedCommand(CommandSourceStack source, String command) {
|
||||||
|
- command = command.startsWith("/") ? command.substring(1) : command;
|
||||||
|
- this.performCommand(this.dispatcher.parse(command, source), command);
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ public void dispatchServerCommand(CommandSourceStack sender, String command) {
|
+ public void dispatchServerCommand(CommandSourceStack sender, String command) {
|
||||||
+ Joiner joiner = Joiner.on(" ");
|
+ Joiner joiner = Joiner.on(" ");
|
||||||
@ -78,13 +79,11 @@
|
|||||||
}
|
}
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
|
|
||||||
public void performPrefixedCommand(CommandSourceStack source, String command) {
|
+ public void performPrefixedCommand(CommandSourceStack source, String command) {
|
||||||
- command = command.startsWith("/") ? command.substring(1) : command;
|
|
||||||
- this.performCommand(this.dispatcher.parse(command, source), command);
|
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ this.performPrefixedCommand(source, command, command);
|
+ this.performPrefixedCommand(source, command, command);
|
||||||
}
|
+ }
|
||||||
|
+
|
||||||
+ public void performPrefixedCommand(CommandSourceStack commandlistenerwrapper, String s, String label) {
|
+ public void performPrefixedCommand(CommandSourceStack commandlistenerwrapper, String s, String label) {
|
||||||
+ s = s.startsWith("/") ? s.substring(1) : s;
|
+ s = s.startsWith("/") ? s.substring(1) : s;
|
||||||
+ this.performCommand(this.dispatcher.parse(s, commandlistenerwrapper), s, label);
|
+ this.performCommand(this.dispatcher.parse(s, commandlistenerwrapper), s, label);
|
||||||
@ -96,16 +95,15 @@
|
|||||||
+ this.performCommand(parseResults, command, command);
|
+ this.performCommand(parseResults, command, command);
|
||||||
+ }
|
+ }
|
||||||
|
|
||||||
- Profiler.get().push(() -> {
|
|
||||||
- return "/" + command;
|
|
||||||
+ public void performCommand(ParseResults<CommandSourceStack> parseresults, String s, String label) { // CraftBukkit
|
+ public void performCommand(ParseResults<CommandSourceStack> parseresults, String s, String label) { // CraftBukkit
|
||||||
+ CommandSourceStack commandlistenerwrapper = (CommandSourceStack) parseresults.getContext().getSource();
|
+ CommandSourceStack commandlistenerwrapper = (CommandSourceStack) parseresults.getContext().getSource();
|
||||||
+
|
+
|
||||||
+ Profiler.get().push(() -> {
|
Profiler.get().push(() -> {
|
||||||
|
- return "/" + command;
|
||||||
+ return "/" + s;
|
+ return "/" + s;
|
||||||
});
|
});
|
||||||
- ContextChain<CommandSourceStack> contextchain = Commands.finishParsing(parseResults, command, commandlistenerwrapper);
|
- ContextChain<CommandSourceStack> contextchain = Commands.finishParsing(parseResults, command, commandlistenerwrapper);
|
||||||
+ ContextChain<CommandSourceStack> contextchain = Commands.finishParsing(parseresults, s, commandlistenerwrapper, label); // CraftBukkit
|
+ ContextChain contextchain = this.finishParsing(parseresults, s, commandlistenerwrapper, label); // CraftBukkit // Paper - Add UnknownCommandEvent
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (contextchain != null) {
|
if (contextchain != null) {
|
||||||
@ -132,12 +130,12 @@
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Profiler.get().pop();
|
Profiler.get().pop();
|
||||||
@@ -307,18 +368,18 @@
|
@@ -307,18 +368,22 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
- private static ContextChain<CommandSourceStack> finishParsing(ParseResults<CommandSourceStack> parseResults, String command, CommandSourceStack source) {
|
- private static ContextChain<CommandSourceStack> finishParsing(ParseResults<CommandSourceStack> parseResults, String command, CommandSourceStack source) {
|
||||||
+ private static ContextChain<CommandSourceStack> finishParsing(ParseResults<CommandSourceStack> parseresults, String s, CommandSourceStack commandlistenerwrapper, String label) { // CraftBukkit
|
+ private ContextChain<CommandSourceStack> finishParsing(ParseResults<CommandSourceStack> parseresults, String s, CommandSourceStack commandlistenerwrapper, String label) { // CraftBukkit // Paper - Add UnknownCommandEvent
|
||||||
try {
|
try {
|
||||||
- Commands.validateParseResults(parseResults);
|
- Commands.validateParseResults(parseResults);
|
||||||
- return (ContextChain) ContextChain.tryFlatten(parseResults.getContext().build(command)).orElseThrow(() -> {
|
- return (ContextChain) ContextChain.tryFlatten(parseResults.getContext().build(command)).orElseThrow(() -> {
|
||||||
@ -148,7 +146,11 @@
|
|||||||
});
|
});
|
||||||
} catch (CommandSyntaxException commandsyntaxexception) {
|
} catch (CommandSyntaxException commandsyntaxexception) {
|
||||||
- source.sendFailure(ComponentUtils.fromMessage(commandsyntaxexception.getRawMessage()));
|
- source.sendFailure(ComponentUtils.fromMessage(commandsyntaxexception.getRawMessage()));
|
||||||
+ commandlistenerwrapper.sendFailure(ComponentUtils.fromMessage(commandsyntaxexception.getRawMessage()));
|
+ // Paper start - Add UnknownCommandEvent
|
||||||
|
+ final net.kyori.adventure.text.TextComponent.Builder builder = net.kyori.adventure.text.Component.text();
|
||||||
|
+ // 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 - Add UnknownCommandEvent
|
||||||
if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) {
|
if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) {
|
||||||
int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor());
|
int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor());
|
||||||
MutableComponent ichatmutablecomponent = Component.empty().withStyle(ChatFormatting.GRAY).withStyle((chatmodifier) -> {
|
MutableComponent ichatmutablecomponent = Component.empty().withStyle(ChatFormatting.GRAY).withStyle((chatmodifier) -> {
|
||||||
@ -157,16 +159,27 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (i > 10) {
|
if (i > 10) {
|
||||||
@@ -333,7 +394,7 @@
|
@@ -333,8 +398,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
ichatmutablecomponent.append((Component) Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
|
ichatmutablecomponent.append((Component) Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
|
||||||
- source.sendFailure(ichatmutablecomponent);
|
- source.sendFailure(ichatmutablecomponent);
|
||||||
+ commandlistenerwrapper.sendFailure(ichatmutablecomponent);
|
+ // 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.Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
+ if (event.message() != null) {
|
||||||
|
+ commandlistenerwrapper.sendFailure(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.message()), false);
|
||||||
|
+ // Paper end - Add UnknownCommandEvent
|
||||||
|
+ }
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -368,7 +429,7 @@
|
}
|
||||||
|
@@ -368,7 +443,7 @@
|
||||||
|
|
||||||
executioncontext1.close();
|
executioncontext1.close();
|
||||||
} finally {
|
} finally {
|
||||||
@ -175,7 +188,7 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
callback.accept(executioncontext);
|
callback.accept(executioncontext);
|
||||||
@@ -377,11 +438,37 @@
|
@@ -377,11 +452,37 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendCommands(ServerPlayer player) {
|
public void sendCommands(ServerPlayer player) {
|
||||||
@ -214,7 +227,7 @@
|
|||||||
player.connection.send(new ClientboundCommandsPacket(rootcommandnode));
|
player.connection.send(new ClientboundCommandsPacket(rootcommandnode));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,9 +477,10 @@
|
@@ -390,9 +491,10 @@
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
CommandNode<CommandSourceStack> commandnode2 = (CommandNode) iterator.next();
|
CommandNode<CommandSourceStack> commandnode2 = (CommandNode) iterator.next();
|
||||||
@ -226,7 +239,7 @@
|
|||||||
|
|
||||||
argumentbuilder.requires((icompletionprovider) -> {
|
argumentbuilder.requires((icompletionprovider) -> {
|
||||||
return true;
|
return true;
|
||||||
@@ -415,7 +503,7 @@
|
@@ -415,7 +517,7 @@
|
||||||
argumentbuilder.redirect((CommandNode) resultNodes.get(argumentbuilder.getRedirect()));
|
argumentbuilder.redirect((CommandNode) resultNodes.get(argumentbuilder.getRedirect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +248,7 @@
|
|||||||
|
|
||||||
resultNodes.put(commandnode2, commandnode3);
|
resultNodes.put(commandnode2, commandnode3);
|
||||||
result.addChild(commandnode3);
|
result.addChild(commandnode3);
|
||||||
@@ -481,7 +569,7 @@
|
@@ -481,7 +583,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> HolderLookup.RegistryLookup.Delegate<T> createLookup(final HolderLookup.RegistryLookup<T> original) {
|
private <T> HolderLookup.RegistryLookup.Delegate<T> createLookup(final HolderLookup.RegistryLookup<T> original) {
|
||||||
|
@ -950,7 +950,13 @@ public final class CraftServer implements Server {
|
|||||||
|
|
||||||
// Spigot start
|
// Spigot start
|
||||||
if (!org.spigotmc.SpigotConfig.unknownCommandMessage.isEmpty()) {
|
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));
|
||||||
|
this.getPluginManager().callEvent(event);
|
||||||
|
if (event.message() != null) {
|
||||||
|
sender.sendMessage(event.message());
|
||||||
|
}
|
||||||
|
// Paper end
|
||||||
}
|
}
|
||||||
// Spigot end
|
// Spigot end
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren