net.minecraft.commands.arguments.selector

This commit is contained in:
Jake Potrebic
2024-12-13 19:46:27 -08:00
parent 9793846a7e
commit aa7204fd62
3 changed files with 16 additions and 25 deletions

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/commands/arguments/selector/EntitySelector.java
+++ b/net/minecraft/commands/arguments/selector/EntitySelector.java
@@ -105,7 +_,7 @@
}
private void checkPermissions(CommandSourceStack source) throws CommandSyntaxException {
- if (this.usesSelector && !source.hasPermission(2)) {
+ if (!source.bypassSelectorPermissions && (this.usesSelector && !source.hasPermission(2, "minecraft.command.selector"))) { // CraftBukkit // Paper - add bypass for selector perms
throw EntityArgument.ERROR_SELECTORS_NOT_ALLOWED.create();
}
}

View File

@@ -0,0 +1,46 @@
--- a/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
+++ b/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
@@ -122,7 +_,7 @@
}
public static <S> boolean allowSelectors(S suggestionProvider) {
- return suggestionProvider instanceof SharedSuggestionProvider sharedSuggestionProvider && sharedSuggestionProvider.hasPermission(2);
+ return suggestionProvider instanceof net.minecraft.commands.CommandSourceStack stack ? stack.bypassSelectorPermissions || stack.hasPermission(2, "minecraft.command.selector") : suggestionProvider instanceof net.minecraft.commands.SharedSuggestionProvider sharedSuggestionProvider && sharedSuggestionProvider.hasPermission(2); // Paper - Fix EntityArgument permissions
}
public EntitySelector getSelector() {
@@ -198,8 +_,10 @@
};
}
- protected void parseSelector() throws CommandSyntaxException {
- this.usesSelectors = true;
+ // CraftBukkit start
+ protected void parseSelector(boolean overridePermissions) throws CommandSyntaxException {
+ this.usesSelectors = !overridePermissions;
+ // CraftBukkit end
this.suggestions = this::suggestSelector;
if (!this.reader.canRead()) {
throw ERROR_MISSING_SELECTOR_TYPE.createWithContext(this.reader);
@@ -467,6 +_,12 @@
}
public EntitySelector parse() throws CommandSyntaxException {
+ // CraftBukkit start
+ return this.parse(false);
+ }
+
+ public EntitySelector parse(boolean overridePermissions) throws CommandSyntaxException {
+ // CraftBukkit end
this.startPosition = this.reader.getCursor();
this.suggestions = this::suggestNameOrSelector;
if (this.reader.canRead() && this.reader.peek() == '@') {
@@ -475,7 +_,7 @@
}
this.reader.skip();
- this.parseSelector();
+ this.parseSelector(overridePermissions); // CraftBukkit
} else {
this.parseNameOrUUID();
}

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/commands/arguments/selector/SelectorPattern.java
+++ b/net/minecraft/commands/arguments/selector/SelectorPattern.java
@@ -13,7 +_,7 @@
EntitySelectorParser entitySelectorParser = new EntitySelectorParser(new StringReader(pattern), true);
return DataResult.success(new SelectorPattern(pattern, entitySelectorParser.parse()));
} catch (CommandSyntaxException var2) {
- return DataResult.error(() -> "Invalid selector component: " + pattern + ": " + var2.getMessage());
+ return DataResult.error(() -> "Invalid selector component"); // Paper - limit selector error message
}
}