geforkt von Mirrors/Paper
Vanilla command permission fixes
Fixes permission checks for vanilla commands which don't have a requirement, as well as for namespaced vanilla commands. == AT == public-f com.mojang.brigadier.tree.CommandNode requirement
Dieser Commit ist enthalten in:
Ursprung
33aad47ee1
Commit
6dafeceebd
@ -0,0 +1,21 @@
|
|||||||
|
--- a/com/mojang/brigadier/builder/ArgumentBuilder.java
|
||||||
|
+++ b/com/mojang/brigadier/builder/ArgumentBuilder.java
|
||||||
|
@@ -14,9 +14,17 @@
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
||||||
|
+ // Paper start - Vanilla command permission fixes
|
||||||
|
+ private static final Predicate<Object> DEFAULT_REQUIREMENT = s -> true;
|
||||||
|
+
|
||||||
|
+ @SuppressWarnings("unchecked")
|
||||||
|
+ public static <S> Predicate<S> defaultRequirement() {
|
||||||
|
+ return (Predicate<S>) DEFAULT_REQUIREMENT;
|
||||||
|
+ }
|
||||||
|
+ // Paper end - Vanilla command permission fixes
|
||||||
|
private final RootCommandNode<S> arguments = new RootCommandNode<>();
|
||||||
|
private Command<S> command;
|
||||||
|
- private Predicate<S> requirement = s -> true;
|
||||||
|
+ private Predicate<S> requirement = defaultRequirement(); // Paper - Vanilla command permission fixes
|
||||||
|
private CommandNode<S> target;
|
||||||
|
private RedirectModifier<S> modifier = null;
|
||||||
|
private boolean forks;
|
@ -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();
|
||||||
|
|
||||||
@ -23,19 +23,28 @@
|
|||||||
AdvancementCommands.register(this.dispatcher);
|
AdvancementCommands.register(this.dispatcher);
|
||||||
AttributeCommand.register(this.dispatcher, commandRegistryAccess);
|
AttributeCommand.register(this.dispatcher, commandRegistryAccess);
|
||||||
ExecuteCommand.register(this.dispatcher, commandRegistryAccess);
|
ExecuteCommand.register(this.dispatcher, commandRegistryAccess);
|
||||||
@@ -252,6 +261,11 @@
|
@@ -250,8 +259,20 @@
|
||||||
PublishCommand.register(this.dispatcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (environment.includeIntegrated) {
|
||||||
|
PublishCommand.register(this.dispatcher);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ // Paper start - Vanilla command permission fixes
|
||||||
|
+ for (final CommandNode<CommandSourceStack> node : this.dispatcher.getRoot().getChildren()) {
|
||||||
|
+ if (node.getRequirement() == com.mojang.brigadier.builder.ArgumentBuilder.<CommandSourceStack>defaultRequirement()) {
|
||||||
|
+ node.requirement = stack -> stack.source == CommandSource.NULL || stack.getBukkitSender().hasPermission(org.bukkit.craftbukkit.command.VanillaCommandWrapper.getPermission(node));
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
+ // Paper end - Vanilla command permission fixes
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ }
|
+ }
|
||||||
+
|
|
||||||
+ public Commands() {
|
+ public Commands() {
|
||||||
+ // CraftBukkkit end
|
+ // CraftBukkkit end
|
||||||
this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer());
|
this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,30 +276,78 @@
|
@@ -262,30 +283,78 @@
|
||||||
return new ParseResults(commandcontextbuilder1, parseResults.getReader(), parseResults.getExceptions());
|
return new ParseResults(commandcontextbuilder1, parseResults.getReader(), parseResults.getExceptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +132,7 @@
|
|||||||
StackTraceElement[] astacktraceelement = exception.getStackTrace();
|
StackTraceElement[] astacktraceelement = exception.getStackTrace();
|
||||||
|
|
||||||
for (int i = 0; i < Math.min(astacktraceelement.length, 3); ++i) {
|
for (int i = 0; i < Math.min(astacktraceelement.length, 3); ++i) {
|
||||||
@@ -298,7 +360,7 @@
|
@@ -298,7 +367,7 @@
|
||||||
}));
|
}));
|
||||||
if (SharedConstants.IS_RUNNING_IN_IDE) {
|
if (SharedConstants.IS_RUNNING_IN_IDE) {
|
||||||
commandlistenerwrapper.sendFailure(Component.literal(Util.describeError(exception)));
|
commandlistenerwrapper.sendFailure(Component.literal(Util.describeError(exception)));
|
||||||
@ -132,7 +141,7 @@
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Profiler.get().pop();
|
Profiler.get().pop();
|
||||||
@@ -307,18 +369,22 @@
|
@@ -307,18 +376,22 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -161,7 +170,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (i > 10) {
|
if (i > 10) {
|
||||||
@@ -333,8 +399,18 @@
|
@@ -333,8 +406,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));
|
||||||
@ -181,7 +190,7 @@
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -368,7 +444,7 @@
|
@@ -368,7 +451,7 @@
|
||||||
|
|
||||||
executioncontext1.close();
|
executioncontext1.close();
|
||||||
} finally {
|
} finally {
|
||||||
@ -190,7 +199,7 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
callback.accept(executioncontext);
|
callback.accept(executioncontext);
|
||||||
@@ -377,22 +453,89 @@
|
@@ -377,22 +460,89 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendCommands(ServerPlayer player) {
|
public void sendCommands(ServerPlayer player) {
|
||||||
@ -285,7 +294,7 @@
|
|||||||
|
|
||||||
argumentbuilder.requires((icompletionprovider) -> {
|
argumentbuilder.requires((icompletionprovider) -> {
|
||||||
return true;
|
return true;
|
||||||
@@ -415,12 +558,12 @@
|
@@ -415,12 +565,12 @@
|
||||||
argumentbuilder.redirect((CommandNode) resultNodes.get(argumentbuilder.getRedirect()));
|
argumentbuilder.redirect((CommandNode) resultNodes.get(argumentbuilder.getRedirect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +309,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -481,7 +624,7 @@
|
@@ -481,7 +631,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) {
|
||||||
|
@ -91,7 +91,21 @@ public final class VanillaCommandWrapper extends BukkitCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getPermission(CommandNode<CommandSourceStack> vanillaCommand) {
|
public static String getPermission(CommandNode<CommandSourceStack> vanillaCommand) {
|
||||||
return "minecraft.command." + ((vanillaCommand.getRedirect() == null) ? vanillaCommand.getName() : vanillaCommand.getRedirect().getName());
|
// Paper start - Vanilla command permission fixes
|
||||||
|
while (vanillaCommand.getRedirect() != null) {
|
||||||
|
vanillaCommand = vanillaCommand.getRedirect();
|
||||||
|
}
|
||||||
|
final String commandName = vanillaCommand.getName();
|
||||||
|
return "minecraft.command." + stripDefaultNamespace(commandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String stripDefaultNamespace(final String maybeNamespaced) {
|
||||||
|
final String prefix = "minecraft:";
|
||||||
|
if (maybeNamespaced.startsWith(prefix)) {
|
||||||
|
return maybeNamespaced.substring(prefix.length());
|
||||||
|
}
|
||||||
|
return maybeNamespaced;
|
||||||
|
// Paper end - Vanilla command permission fixes
|
||||||
}
|
}
|
||||||
|
|
||||||
private String toDispatcher(String[] args, String name) {
|
private String toDispatcher(String[] args, String name) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren