update brig in the API and patch cleanup

This commit is contained in:
Jake Potrebic 2024-12-18 18:30:29 -08:00
parent 5922e6334b
commit 49f715fdda
No known key found for this signature in database
GPG key ID: ECE0B3C133C016C5
8 changed files with 72 additions and 29 deletions

View file

@ -39,7 +39,7 @@ abstract class MockitoAgentProvider : CommandLineArgumentProvider {
// Paper end - configure mockito agent that is needed in newer java versions // Paper end - configure mockito agent that is needed in newer java versions
dependencies { dependencies {
api("com.mojang:brigadier:1.2.9") // Paper - Brigadier command api api("com.mojang:brigadier:1.3.10") // Paper - Brigadier command api
// api dependencies are listed transitively to API consumers // api dependencies are listed transitively to API consumers
api("com.google.guava:guava:33.3.1-jre") api("com.google.guava:guava:33.3.1-jre")
api("com.google.code.gson:gson:2.11.0") api("com.google.code.gson:gson:2.11.0")

View file

@ -37,10 +37,31 @@ public interface CustomArgumentType<T, N> extends ArgumentType<T> {
* @param reader string reader input * @param reader string reader input
* @return parsed value * @return parsed value
* @throws CommandSyntaxException if an error occurs while parsing * @throws CommandSyntaxException if an error occurs while parsing
* @see #parse(StringReader, Object)
*/ */
@Override @Override
T parse(final StringReader reader) throws CommandSyntaxException; T parse(final StringReader reader) throws CommandSyntaxException;
/**
* Parses the argument into the custom type ({@code T}). Keep in mind
* that this parsing will be done on the server. This means that if
* you throw a {@link CommandSyntaxException} during parsing, this
* will only show up to the user after the user has executed the command
* not while they are still entering it.
* <p>
* This method provides the command source for additional context when parsing. You
* may have to do your own {@code instanceof} checks for {@link io.papermc.paper.command.brigadier.CommandSourceStack}.
*
* @param reader string reader input
* @param source source of the command
* @return parsed value
* @throws CommandSyntaxException if an error occurs while parsing
*/
@Override
default <S> T parse(final StringReader reader, final S source) throws CommandSyntaxException {
return ArgumentType.super.parse(reader, source);
}
/** /**
* Gets the native type that this argument uses, * Gets the native type that this argument uses,
* the type that is sent to the client. * the type that is sent to the client.
@ -95,13 +116,35 @@ public interface CustomArgumentType<T, N> extends ArgumentType<T> {
return this.convert(this.getNativeType().parse(reader)); return this.convert(this.getNativeType().parse(reader));
} }
@ApiStatus.NonExtendable
@Override
default <S> T parse(final StringReader reader, final S source) throws CommandSyntaxException {
return this.convert(this.getNativeType().parse(reader, source), source);
}
/** /**
* Converts the value from the native type to the custom argument type. * Converts the value from the native type to the custom argument type.
* *
* @param nativeType native argument provided value * @param nativeType native argument provided value
* @return converted value * @return converted value
* @throws CommandSyntaxException if an exception occurs while parsing * @throws CommandSyntaxException if an exception occurs while parsing
* @see #convert(Object, Object)
*/ */
T convert(N nativeType) throws CommandSyntaxException; T convert(N nativeType) throws CommandSyntaxException;
/**
* Converts the value from the native type to the custom argument type.
* <p>
* This method provides the command source for additional context when converting. You
* may have to do your own {@code instanceof} checks for {@link io.papermc.paper.command.brigadier.CommandSourceStack}.
*
* @param nativeType native argument provided value
* @param source source of the command
* @return converted value
* @throws CommandSyntaxException if an exception occurs while parsing
*/
default <S> T convert(final N nativeType, final S source) throws CommandSyntaxException {
return this.convert(nativeType);
}
} }
} }

View file

@ -35,10 +35,10 @@ index 704a63890a06d793f8ac3452838917e7c7335232..75262c8c9eaecb4a88a94f4076d67119
+ // Paper end - tell clients to ask server for suggestions for EntityArguments + // Paper end - tell clients to ask server for suggestions for EntityArguments
} }
diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java
index 45fa9cdc34e78613e346138aa92a6d3bbdee374c..e422a266de555bbf77eee201df9e4c5d89f7b801 100644 index fa8c5ba4e0efd0c36613aaa8eaafba0cb70ceb87..19ccf3abf14c67f72a1ca065e4a304f50e645ef4 100644
--- a/net/minecraft/commands/Commands.java --- a/net/minecraft/commands/Commands.java
+++ b/net/minecraft/commands/Commands.java +++ b/net/minecraft/commands/Commands.java
@@ -510,6 +510,7 @@ public class Commands { @@ -509,6 +509,7 @@ public class Commands {
Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> commandNodeToSuggestionNode Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> commandNodeToSuggestionNode
) { ) {
commandNodeToSuggestionNode.keySet().removeIf((node) -> !org.spigotmc.SpigotConfig.sendNamespaced && node.getName().contains(":")); // Paper - Remove namedspaced from result nodes to prevent redirect trimming ~ see comment below commandNodeToSuggestionNode.keySet().removeIf((node) -> !org.spigotmc.SpigotConfig.sendNamespaced && node.getName().contains(":")); // Paper - Remove namedspaced from result nodes to prevent redirect trimming ~ see comment below

View file

@ -183,7 +183,6 @@
+ private void sendAsync(ServerPlayer player, java.util.Collection<CommandNode<CommandSourceStack>> dispatcherRootChildren) { + private void sendAsync(ServerPlayer player, java.util.Collection<CommandNode<CommandSourceStack>> dispatcherRootChildren) {
+ // Paper end - Perf: Async command map building + // Paper end - Perf: Async command map building
+ Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues + Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues
+ // Paper - brigadier API removes the need to fill the map twice
RootCommandNode<SharedSuggestionProvider> rootCommandNode = new RootCommandNode<>(); RootCommandNode<SharedSuggestionProvider> rootCommandNode = new RootCommandNode<>();
map.put(this.dispatcher.getRoot(), rootCommandNode); map.put(this.dispatcher.getRoot(), rootCommandNode);
- this.fillUsableCommands(this.dispatcher.getRoot(), rootCommandNode, player.createCommandSourceStack(), map); - this.fillUsableCommands(this.dispatcher.getRoot(), rootCommandNode, player.createCommandSourceStack(), map);
@ -276,6 +275,7 @@
- argumentBuilder.executes(commandContext -> 0); - argumentBuilder.executes(commandContext -> 0);
+ // Paper start - fix suggestions due to falsely equal nodes + // Paper start - fix suggestions due to falsely equal nodes
+ // Always create a new instance + // Always create a new instance
+ //noinspection Convert2Lambda
+ argumentBuilder.executes(new com.mojang.brigadier.Command<>() { + argumentBuilder.executes(new com.mojang.brigadier.Command<>() {
+ @Override + @Override
+ public int run(com.mojang.brigadier.context.CommandContext<SharedSuggestionProvider> commandContext) { + public int run(com.mojang.brigadier.context.CommandContext<SharedSuggestionProvider> commandContext) {

View file

@ -4,11 +4,11 @@
public static void resolveChatMessage(CommandContext<CommandSourceStack> context, String key, Consumer<PlayerChatMessage> callback) throws CommandSyntaxException { public static void resolveChatMessage(CommandContext<CommandSourceStack> context, String key, Consumer<PlayerChatMessage> callback) throws CommandSyntaxException {
MessageArgument.Message message = context.getArgument(key, MessageArgument.Message.class); MessageArgument.Message message = context.getArgument(key, MessageArgument.Message.class);
+ // Paper start + // Paper start - brig message argument support
+ resolveChatMessage(message, context, key, callback); + resolveChatMessage(message, context, key, callback);
+ } + }
+ public static void resolveChatMessage(MessageArgument.Message message, CommandContext<CommandSourceStack> context, String key, Consumer<PlayerChatMessage> callback) throws CommandSyntaxException { + public static void resolveChatMessage(MessageArgument.Message message, CommandContext<CommandSourceStack> context, String key, Consumer<PlayerChatMessage> callback) throws CommandSyntaxException {
+ // Paper end + // Paper end - brig message argument support
CommandSourceStack commandSourceStack = context.getSource(); CommandSourceStack commandSourceStack = context.getSource();
Component component = message.resolveComponent(commandSourceStack); Component component = message.resolveComponent(commandSourceStack);
CommandSigningContext signingContext = commandSourceStack.getSigningContext(); CommandSigningContext signingContext = commandSourceStack.getSigningContext();

View file

@ -7,7 +7,7 @@
- component.streamCodec().encode(buffer, (T)value); - component.streamCodec().encode(buffer, (T)value);
+ // Paper start - codec errors of random anonymous classes are useless + // Paper start - codec errors of random anonymous classes are useless
+ try { + try {
+ component.streamCodec().encode(buffer, (T) value); // CraftBukkit - decompile error + component.streamCodec().encode(buffer, (T)value);
+ } catch (final Exception e) { + } catch (final Exception e) {
+ throw new RuntimeException("Error encoding component " + component, e); + throw new RuntimeException("Error encoding component " + component, e);
+ } + }

View file

@ -5,9 +5,9 @@
} }
+ // CraftBukkit start + // CraftBukkit start
+ ItemStack itemstack1 = item.copyWithCount(1); // Paper - shrink at end and single item in event + ItemStack singleItemStack = item.copyWithCount(1); // Paper - shrink at end and single item in event
+ org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(serverLevel, blockSource.pos()); + org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(serverLevel, blockSource.pos());
+ org.bukkit.craftbukkit.inventory.CraftItemStack craftItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack1); + org.bukkit.craftbukkit.inventory.CraftItemStack craftItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(singleItemStack);
+ +
+ org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d1, d2 + d4, d3)); + org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d1, d2 + d4, d3));
+ if (!DispenserBlock.eventFired) { + if (!DispenserBlock.eventFired) {

View file

@ -6,9 +6,9 @@
+ // CraftBukkit start + // CraftBukkit start
+ ServerLevel serverLevel = blockSource.level(); + ServerLevel serverLevel = blockSource.level();
+ ItemStack itemstack1 = item.copyWithCount(1); // Paper - shrink below and single item in event + ItemStack singleItemStack = item.copyWithCount(1); // Paper - shrink below and single item in event
+ org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(serverLevel, blockSource.pos()); + org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(serverLevel, blockSource.pos());
+ org.bukkit.craftbukkit.inventory.CraftItemStack craftItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack1); + org.bukkit.craftbukkit.inventory.CraftItemStack craftItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(singleItemStack);
+ +
+ org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0)); + org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
+ if (!DispenserBlock.eventFired) { + if (!DispenserBlock.eventFired) {
@ -25,20 +25,20 @@
+ shrink = false; // Paper - shrink below + shrink = false; // Paper - shrink below
+ // Chain to handler for new item + // Chain to handler for new item
+ ItemStack eventStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItem()); + ItemStack eventStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItem());
+ DispenseItemBehavior idispensebehavior = DispenserBlock.getDispenseBehavior(blockSource, eventStack); // Paper - Fix NPE with equippable and items without behavior + DispenseItemBehavior dispenseBehavior = DispenserBlock.getDispenseBehavior(blockSource, eventStack); // Paper - Fix NPE with equippable and items without behavior
+ if (idispensebehavior != DispenseItemBehavior.NOOP && idispensebehavior != this) { + if (dispenseBehavior != DispenseItemBehavior.NOOP && dispenseBehavior != this) {
+ idispensebehavior.dispense(blockSource, eventStack); + dispenseBehavior.dispense(blockSource, eventStack);
+ return item; + return item;
+ } + }
+ // Paper start - track changed items in the dispense event + // Paper start - track changed items in the dispense event
+ itemstack1 = org.bukkit.craftbukkit.inventory.CraftItemStack.unwrap(event.getItem()); // unwrap is safe because the stack won't be modified + singleItemStack = org.bukkit.craftbukkit.inventory.CraftItemStack.unwrap(event.getItem()); // unwrap is safe because the stack won't be modified
+ type = ((SpawnEggItem) itemstack1.getItem()).getType(serverLevel.registryAccess(), itemstack1); + type = ((SpawnEggItem) singleItemStack.getItem()).getType(serverLevel.registryAccess(), singleItemStack);
+ // Paper end - track changed item from dispense event + // Paper end - track changed item from dispense event
+ } + }
try { try {
type.spawn( type.spawn(
- blockSource.level(), item, null, blockSource.pos().relative(direction), EntitySpawnReason.DISPENSER, direction != Direction.UP, false - blockSource.level(), item, null, blockSource.pos().relative(direction), EntitySpawnReason.DISPENSER, direction != Direction.UP, false
+ blockSource.level(), itemstack1, null, blockSource.pos().relative(direction), EntitySpawnReason.DISPENSER, direction != Direction.UP, false // Paper - track changed item in dispense event + blockSource.level(), singleItemStack, null, blockSource.pos().relative(direction), EntitySpawnReason.DISPENSER, direction != Direction.UP, false // Paper - track changed item in dispense event
); );
} catch (Exception var6) { } catch (Exception var6) {
LOGGER.error("Error while dispensing spawn egg from dispenser at {}", blockSource.pos(), var6); LOGGER.error("Error while dispensing spawn egg from dispenser at {}", blockSource.pos(), var6);
@ -56,9 +56,9 @@
BlockPos blockPos = blockSource.pos().relative(direction); BlockPos blockPos = blockSource.pos().relative(direction);
ServerLevel serverLevel = blockSource.level(); ServerLevel serverLevel = blockSource.level();
+ // CraftBukkit start + // CraftBukkit start
+ ItemStack itemstack1 = item.copyWithCount(1); // Paper - shrink below and single item in event + ItemStack singleItemStack = item.copyWithCount(1); // Paper - shrink below and single item in event
+ org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(serverLevel, blockSource.pos()); + org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(serverLevel, blockSource.pos());
+ org.bukkit.craftbukkit.inventory.CraftItemStack craftItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack1); + org.bukkit.craftbukkit.inventory.CraftItemStack craftItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(singleItemStack);
+ +
+ org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0)); + org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
+ if (!DispenserBlock.eventFired) { + if (!DispenserBlock.eventFired) {
@ -100,10 +100,10 @@
if (!entitiesOfClass.isEmpty()) { if (!entitiesOfClass.isEmpty()) {
- ((Saddleable)entitiesOfClass.get(0)).equipSaddle(item.split(1), SoundSource.BLOCKS); - ((Saddleable)entitiesOfClass.get(0)).equipSaddle(item.split(1), SoundSource.BLOCKS);
+ // CraftBukkit start + // CraftBukkit start
+ ItemStack itemstack1 = item.copyWithCount(1); // Paper - shrink below and single item in event + ItemStack singleItemStack = item.copyWithCount(1); // Paper - shrink below and single item in event
+ ServerLevel world = blockSource.level(); + ServerLevel world = blockSource.level();
+ org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(world, blockSource.pos()); + org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(world, blockSource.pos());
+ org.bukkit.craftbukkit.inventory.CraftItemStack craftItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack1); + org.bukkit.craftbukkit.inventory.CraftItemStack craftItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(singleItemStack);
+ +
+ org.bukkit.event.block.BlockDispenseArmorEvent event = new org.bukkit.event.block.BlockDispenseArmorEvent(block, craftItem.clone(), entitiesOfClass.get(0).getBukkitLivingEntity()); + org.bukkit.event.block.BlockDispenseArmorEvent event = new org.bukkit.event.block.BlockDispenseArmorEvent(block, craftItem.clone(), entitiesOfClass.get(0).getBukkitLivingEntity());
+ if (!DispenserBlock.eventFired) { + if (!DispenserBlock.eventFired) {
@ -120,9 +120,9 @@
+ shrink = false; // Paper - shrink below + shrink = false; // Paper - shrink below
+ // Chain to handler for new item + // Chain to handler for new item
+ ItemStack eventStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItem()); + ItemStack eventStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItem());
+ DispenseItemBehavior idispensebehavior = DispenserBlock.getDispenseBehavior(blockSource, eventStack); // Paper - Fix NPE with equippable and items without behavior + DispenseItemBehavior dispenseBehavior = DispenserBlock.getDispenseBehavior(blockSource, eventStack); // Paper - Fix NPE with equippable and items without behavior
+ if (idispensebehavior != DispenseItemBehavior.NOOP && idispensebehavior != this) { // Paper - fix possible StackOverflowError + if (dispenseBehavior != DispenseItemBehavior.NOOP && dispenseBehavior != this) { // Paper - fix possible StackOverflowError
+ idispensebehavior.dispense(blockSource, eventStack); + dispenseBehavior.dispense(blockSource, eventStack);
+ return item; + return item;
+ } + }
+ } + }
@ -379,9 +379,9 @@
BlockPos blockPos = blockSource.pos().relative(blockSource.state().getValue(DispenserBlock.FACING)); BlockPos blockPos = blockSource.pos().relative(blockSource.state().getValue(DispenserBlock.FACING));
- PrimedTnt primedTnt = new PrimedTnt(level, blockPos.getX() + 0.5, blockPos.getY(), blockPos.getZ() + 0.5, null); - PrimedTnt primedTnt = new PrimedTnt(level, blockPos.getX() + 0.5, blockPos.getY(), blockPos.getZ() + 0.5, null);
+ // CraftBukkit start + // CraftBukkit start
+ ItemStack itemstack1 = item.copyWithCount(1); // Paper - shrink at end and single item in event + ItemStack singleItemStack = item.copyWithCount(1); // Paper - shrink at end and single item in event
+ org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(level, blockSource.pos()); + org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(level, blockSource.pos());
+ org.bukkit.craftbukkit.inventory.CraftItemStack craftItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack1); + org.bukkit.craftbukkit.inventory.CraftItemStack craftItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(singleItemStack);
+ +
+ org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) blockPos.getX() + 0.5D, (double) blockPos.getY(), (double) blockPos.getZ() + 0.5D)); + org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) blockPos.getX() + 0.5D, (double) blockPos.getY(), (double) blockPos.getZ() + 0.5D));
+ if (!DispenserBlock.eventFired) { + if (!DispenserBlock.eventFired) {
@ -557,9 +557,9 @@
+ if (!event.getItem().equals(craftItem)) { + if (!event.getItem().equals(craftItem)) {
+ // Chain to handler for new item + // Chain to handler for new item
+ ItemStack eventStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItem()); + ItemStack eventStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItem());
+ DispenseItemBehavior idispensebehavior = DispenserBlock.getDispenseBehavior(blockSource, eventStack); // Paper - Fix NPE with equippable and items without behavior + DispenseItemBehavior dispenseBehavior = DispenserBlock.getDispenseBehavior(blockSource, eventStack); // Paper - Fix NPE with equippable and items without behavior
+ if (idispensebehavior != DispenseItemBehavior.NOOP && idispensebehavior != this) { // Paper - fix possible StackOverflowError + if (dispenseBehavior != DispenseItemBehavior.NOOP && dispenseBehavior != this) { // Paper - fix possible StackOverflowError
+ idispensebehavior.dispense(blockSource, eventStack); + dispenseBehavior.dispense(blockSource, eventStack);
+ return item; + return item;
+ } + }
+ } + }