From f1ee7a02621374b3431fd8c81b4a825c54b0292e Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 14 Dec 2024 20:30:29 +0100 Subject: [PATCH] net.minecraft.commands.arguments(.{blocks|item}) --- .../arguments/EntityArgument.java.patch | 32 ++++++++++++ .../arguments/MessageArgument.java.patch | 32 ++++++------ .../blocks/BlockStateParser.java.patch | 11 ++++ .../arguments/EntityArgument.java.patch | 52 ------------------- .../blocks/BlockStateParser.java.patch | 38 -------------- .../arguments/item/ItemInput.java.patch | 10 ---- 6 files changed, 59 insertions(+), 116 deletions(-) create mode 100644 paper-server/patches/sources/net/minecraft/commands/arguments/EntityArgument.java.patch rename paper-server/patches/{unapplied => sources}/net/minecraft/commands/arguments/MessageArgument.java.patch (60%) create mode 100644 paper-server/patches/sources/net/minecraft/commands/arguments/blocks/BlockStateParser.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/commands/arguments/EntityArgument.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/commands/arguments/blocks/BlockStateParser.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/commands/arguments/item/ItemInput.java.patch diff --git a/paper-server/patches/sources/net/minecraft/commands/arguments/EntityArgument.java.patch b/paper-server/patches/sources/net/minecraft/commands/arguments/EntityArgument.java.patch new file mode 100644 index 0000000000..30696dc07f --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/commands/arguments/EntityArgument.java.patch @@ -0,0 +1,32 @@ +--- a/net/minecraft/commands/arguments/EntityArgument.java ++++ b/net/minecraft/commands/arguments/EntityArgument.java +@@ -105,9 +_,14 @@ + } + + private EntitySelector parse(StringReader reader, boolean allowSelectors) throws CommandSyntaxException { ++ // CraftBukkit start ++ return this.parse(reader, allowSelectors, true); ++ } ++ private EntitySelector parse(StringReader reader, boolean allowSelectors, boolean overridePermissions) throws CommandSyntaxException { ++ // CraftBukkit end + int i = 0; + EntitySelectorParser entitySelectorParser = new EntitySelectorParser(reader, allowSelectors); +- EntitySelector entitySelector = entitySelectorParser.parse(); ++ EntitySelector entitySelector = entitySelectorParser.parse(overridePermissions); // CraftBukkit + if (entitySelector.getMaxResults() > 1 && this.single) { + if (this.playersOnly) { + reader.setCursor(0); +@@ -129,7 +_,12 @@ + if (context.getSource() instanceof SharedSuggestionProvider sharedSuggestionProvider) { + StringReader stringReader = new StringReader(builder.getInput()); + stringReader.setCursor(builder.getStart()); +- EntitySelectorParser entitySelectorParser = new EntitySelectorParser(stringReader, EntitySelectorParser.allowSelectors(sharedSuggestionProvider)); ++ // Paper start - Fix EntityArgument permissions ++ final boolean permission = sharedSuggestionProvider instanceof CommandSourceStack stack ++ ? stack.bypassSelectorPermissions || stack.hasPermission(2, "minecraft.command.selector") ++ : sharedSuggestionProvider.hasPermission(2); ++ EntitySelectorParser entitySelectorParser = new EntitySelectorParser(stringReader, permission); ++ // Paper end - Fix EntityArgument permissions + + try { + entitySelectorParser.parse(); diff --git a/paper-server/patches/unapplied/net/minecraft/commands/arguments/MessageArgument.java.patch b/paper-server/patches/sources/net/minecraft/commands/arguments/MessageArgument.java.patch similarity index 60% rename from paper-server/patches/unapplied/net/minecraft/commands/arguments/MessageArgument.java.patch rename to paper-server/patches/sources/net/minecraft/commands/arguments/MessageArgument.java.patch index ba048d7f68..9c9cb202be 100644 --- a/paper-server/patches/unapplied/net/minecraft/commands/arguments/MessageArgument.java.patch +++ b/paper-server/patches/sources/net/minecraft/commands/arguments/MessageArgument.java.patch @@ -1,30 +1,30 @@ --- a/net/minecraft/commands/arguments/MessageArgument.java +++ b/net/minecraft/commands/arguments/MessageArgument.java -@@ -40,6 +40,11 @@ +@@ -40,6 +_,11 @@ - public static void resolveChatMessage(CommandContext context, String name, Consumer callback) throws CommandSyntaxException { - MessageArgument.Message message = context.getArgument(name, MessageArgument.Message.class); -+ // Paper start -+ resolveChatMessage(message, context, name, callback); + public static void resolveChatMessage(CommandContext context, String key, Consumer callback) throws CommandSyntaxException { + MessageArgument.Message message = context.getArgument(key, MessageArgument.Message.class); ++ // Paper start ++ resolveChatMessage(message, context, key, callback); + } -+ public static void resolveChatMessage(MessageArgument.Message message, CommandContext context, String name, Consumer callback) throws CommandSyntaxException { -+ // Paper end ++ public static void resolveChatMessage(MessageArgument.Message message, CommandContext context, String key, Consumer callback) throws CommandSyntaxException { ++ // Paper end CommandSourceStack commandSourceStack = context.getSource(); Component component = message.resolveComponent(commandSourceStack); - CommandSigningContext commandSigningContext = commandSourceStack.getSigningContext(); -@@ -54,17 +59,21 @@ + CommandSigningContext signingContext = commandSourceStack.getSigningContext(); +@@ -54,17 +_,21 @@ private static void resolveSignedMessage(Consumer callback, CommandSourceStack source, PlayerChatMessage message) { - MinecraftServer minecraftServer = source.getServer(); + MinecraftServer server = source.getServer(); CompletableFuture completableFuture = filterPlainText(source, message); -- Component component = minecraftServer.getChatDecorator().decorate(source.getPlayer(), message.decoratedContent()); -- source.getChatMessageChainer().append(completableFuture, filtered -> { -- PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(component).filter(filtered.mask()); +- Component component = server.getChatDecorator().decorate(source.getPlayer(), message.decoratedContent()); +- source.getChatMessageChainer().append(completableFuture, filteredText -> { +- PlayerChatMessage playerChatMessage = message.withUnsignedContent(component).filter(filteredText.mask()); + // Paper start - support asynchronous chat decoration -+ CompletableFuture componentFuture = minecraftServer.getChatDecorator().decorate(source.getPlayer(), source, message.decoratedContent()); ++ CompletableFuture componentFuture = server.getChatDecorator().decorate(source.getPlayer(), source, message.decoratedContent()); + source.getChatMessageChainer().append(CompletableFuture.allOf(completableFuture, componentFuture), filtered -> { -+ PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(componentFuture.join()).filter(completableFuture.join().mask()); ++ PlayerChatMessage playerChatMessage = message.withUnsignedContent(componentFuture.join()).filter(completableFuture.join().mask()); + // Paper end - support asynchronous chat decoration - callback.accept(playerChatMessage2); + callback.accept(playerChatMessage); }); } diff --git a/paper-server/patches/sources/net/minecraft/commands/arguments/blocks/BlockStateParser.java.patch b/paper-server/patches/sources/net/minecraft/commands/arguments/blocks/BlockStateParser.java.patch new file mode 100644 index 0000000000..5d7a0a0c8b --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/commands/arguments/blocks/BlockStateParser.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/commands/arguments/blocks/BlockStateParser.java ++++ b/net/minecraft/commands/arguments/blocks/BlockStateParser.java +@@ -69,7 +_,7 @@ + private final StringReader reader; + private final boolean forTesting; + private final boolean allowNbt; +- private final Map, Comparable> properties = Maps.newHashMap(); ++ private final Map, Comparable> properties = Maps.newLinkedHashMap(); // CraftBukkit - stable + private final Map vagueProperties = Maps.newHashMap(); + private ResourceLocation id = ResourceLocation.withDefaultNamespace(""); + @Nullable diff --git a/paper-server/patches/unapplied/net/minecraft/commands/arguments/EntityArgument.java.patch b/paper-server/patches/unapplied/net/minecraft/commands/arguments/EntityArgument.java.patch deleted file mode 100644 index 9c45cfda8f..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/commands/arguments/EntityArgument.java.patch +++ /dev/null @@ -1,52 +0,0 @@ ---- a/net/minecraft/commands/arguments/EntityArgument.java -+++ b/net/minecraft/commands/arguments/EntityArgument.java -@@ -102,21 +102,27 @@ - } - - private EntitySelector parse(StringReader reader, boolean allowAtSelectors) throws CommandSyntaxException { -+ // CraftBukkit start -+ return this.parse(reader, allowAtSelectors, false); -+ } -+ -+ public EntitySelector parse(StringReader stringreader, boolean flag, boolean overridePermissions) throws CommandSyntaxException { -+ // CraftBukkit end - boolean flag1 = false; -- EntitySelectorParser argumentparserselector = new EntitySelectorParser(reader, allowAtSelectors); -- EntitySelector entityselector = argumentparserselector.parse(); -+ EntitySelectorParser argumentparserselector = new EntitySelectorParser(stringreader, flag); -+ EntitySelector entityselector = argumentparserselector.parse(overridePermissions); // CraftBukkit - - if (entityselector.getMaxResults() > 1 && this.single) { - if (this.playersOnly) { -- reader.setCursor(0); -- throw EntityArgument.ERROR_NOT_SINGLE_PLAYER.createWithContext(reader); -+ stringreader.setCursor(0); -+ throw EntityArgument.ERROR_NOT_SINGLE_PLAYER.createWithContext(stringreader); - } else { -- reader.setCursor(0); -- throw EntityArgument.ERROR_NOT_SINGLE_ENTITY.createWithContext(reader); -+ stringreader.setCursor(0); -+ throw EntityArgument.ERROR_NOT_SINGLE_ENTITY.createWithContext(stringreader); - } - } else if (entityselector.includesEntities() && this.playersOnly && !entityselector.isSelfSelector()) { -- reader.setCursor(0); -- throw EntityArgument.ERROR_ONLY_PLAYERS_ALLOWED.createWithContext(reader); -+ stringreader.setCursor(0); -+ throw EntityArgument.ERROR_ONLY_PLAYERS_ALLOWED.createWithContext(stringreader); - } else { - return entityselector; - } -@@ -129,7 +135,12 @@ - StringReader stringreader = new StringReader(suggestionsbuilder.getInput()); - - stringreader.setCursor(suggestionsbuilder.getStart()); -- EntitySelectorParser argumentparserselector = new EntitySelectorParser(stringreader, EntitySelectorParser.allowSelectors(icompletionprovider)); -+ // Paper start - Fix EntityArgument permissions -+ final boolean permission = object instanceof CommandSourceStack stack -+ ? stack.bypassSelectorPermissions || stack.hasPermission(2, "minecraft.command.selector") -+ : icompletionprovider.hasPermission(2); -+ EntitySelectorParser argumentparserselector = new EntitySelectorParser(stringreader, permission); -+ // Paper end - Fix EntityArgument permissions - - try { - argumentparserselector.parse(); diff --git a/paper-server/patches/unapplied/net/minecraft/commands/arguments/blocks/BlockStateParser.java.patch b/paper-server/patches/unapplied/net/minecraft/commands/arguments/blocks/BlockStateParser.java.patch deleted file mode 100644 index 46961c4f64..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/commands/arguments/blocks/BlockStateParser.java.patch +++ /dev/null @@ -1,38 +0,0 @@ ---- a/net/minecraft/commands/arguments/blocks/BlockStateParser.java -+++ b/net/minecraft/commands/arguments/blocks/BlockStateParser.java -@@ -67,7 +67,7 @@ - private final StringReader reader; - private final boolean forTesting; - private final boolean allowNbt; -- private final Map, Comparable> properties = Maps.newHashMap(); -+ private final Map, Comparable> properties = Maps.newLinkedHashMap(); // CraftBukkit - stable - private final Map vagueProperties = Maps.newHashMap(); - private ResourceLocation id = ResourceLocation.withDefaultNamespace(""); - @Nullable -@@ -275,7 +275,7 @@ - Iterator iterator = property.getPossibleValues().iterator(); - - while (iterator.hasNext()) { -- T t0 = (Comparable) iterator.next(); -+ T t0 = (T) iterator.next(); // CraftBukkit - decompile error - - if (t0 instanceof Integer integer) { - builder.suggest(integer); -@@ -545,7 +545,7 @@ - Optional optional = property.getValue(value); - - if (optional.isPresent()) { -- this.state = (BlockState) this.state.setValue(property, (Comparable) optional.get()); -+ this.state = (BlockState) this.state.setValue(property, (T) optional.get()); // CraftBukkit - decompile error - this.properties.put(property, (Comparable) optional.get()); - } else { - this.reader.setCursor(cursor); -@@ -581,7 +581,7 @@ - private static > void appendProperty(StringBuilder builder, Property property, Comparable value) { - builder.append(property.getName()); - builder.append('='); -- builder.append(property.getName(value)); -+ builder.append(property.getName((T) value)); // CraftBukkit - decompile error - } - - public static record BlockResult(BlockState blockState, Map, Comparable> properties, @Nullable CompoundTag nbt) { diff --git a/paper-server/patches/unapplied/net/minecraft/commands/arguments/item/ItemInput.java.patch b/paper-server/patches/unapplied/net/minecraft/commands/arguments/item/ItemInput.java.patch deleted file mode 100644 index a20c412208..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/commands/arguments/item/ItemInput.java.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- a/net/minecraft/commands/arguments/item/ItemInput.java -+++ b/net/minecraft/commands/arguments/item/ItemInput.java -@@ -78,6 +78,6 @@ - } - - private String getItemName() { -- return this.item.unwrapKey().map(ResourceKey::location).orElseGet(() -> "unknown[" + this.item + "]").toString(); -+ return this.item.unwrapKey().map(ResourceKey::location).orElseGet(() -> "unknown[" + this.item + "]").toString(); // Paper - decompile fix - } - }