diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.patch index d4d7f2842e..51a8d8e138 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.patch @@ -1,6 +1,19 @@ --- a/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.java +++ b/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.java -@@ -219,13 +219,18 @@ +@@ -47,6 +47,12 @@ + import net.minecraft.world.phys.Vec3D; + import net.minecraft.world.phys.shapes.VoxelShapeCollision; + ++// CraftBukkit start ++import org.bukkit.craftbukkit.event.CraftEventFactory; ++import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.event.block.BlockDispenseLootEvent; ++// CraftBukkit end ++ + public final class TrialSpawner { + + public static final String NORMAL_CONFIG_TAG_NAME = "normal_config"; +@@ -219,13 +225,18 @@ } entityinsentient.setPersistenceRequired(); @@ -21,3 +34,19 @@ return Optional.empty(); } else { TrialSpawner.a trialspawner_a = this.isOminous ? TrialSpawner.a.OMINOUS : TrialSpawner.a.NORMAL; +@@ -248,6 +259,15 @@ + ObjectArrayList objectarraylist = loottable.getRandomItems(lootparams); + + if (!objectarraylist.isEmpty()) { ++ // CraftBukkit start ++ BlockDispenseLootEvent spawnerDispenseLootEvent = CraftEventFactory.callBlockDispenseLootEvent(worldserver, blockposition, null, objectarraylist); ++ if (spawnerDispenseLootEvent.isCancelled()) { ++ return; ++ } ++ ++ objectarraylist = new ObjectArrayList<>(spawnerDispenseLootEvent.getDispensedLoot().stream().map(CraftItemStack::asNMSCopy).toList()); ++ // CraftBukkit end ++ + ObjectListIterator objectlistiterator = objectarraylist.iterator(); + + while (objectlistiterator.hasNext()) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.patch new file mode 100644 index 0000000000..8cf5a218b5 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.patch @@ -0,0 +1,82 @@ +--- a/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java ++++ b/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java +@@ -47,6 +47,13 @@ + import net.minecraft.world.phys.Vec3D; + import org.slf4j.Logger; + ++// CraftBukkit start ++import org.bukkit.craftbukkit.event.CraftEventFactory; ++import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.event.block.BlockDispenseLootEvent; ++import org.bukkit.event.block.VaultDisplayItemEvent; ++// CraftBukkit end ++ + public class VaultBlockEntity extends TileEntity { + + private static final Logger LOGGER = LogUtils.getLogger(); +@@ -97,18 +104,18 @@ + dataresult = VaultServerData.CODEC.parse(dynamicops, nbttagcompound.get("server_data")); + logger = VaultBlockEntity.LOGGER; + Objects.requireNonNull(logger); +- optional = dataresult.resultOrPartial(logger::error); ++ optional = ((DataResult) dataresult).resultOrPartial(logger::error); // CraftBukkit - decompile error + VaultServerData vaultserverdata = this.serverData; + + Objects.requireNonNull(this.serverData); +- optional.ifPresent(vaultserverdata::set); ++ ((Optional) optional).ifPresent(vaultserverdata::set); // CraftBukkit - decompile error + } + + if (nbttagcompound.contains("config")) { + dataresult = VaultConfig.CODEC.parse(dynamicops, nbttagcompound.get("config")); + logger = VaultBlockEntity.LOGGER; + Objects.requireNonNull(logger); +- dataresult.resultOrPartial(logger::error).ifPresent((vaultconfig) -> { ++ ((DataResult) dataresult).resultOrPartial(logger::error).ifPresent((vaultconfig) -> { // CraftBukkit - decompile error + this.config = vaultconfig; + }); + } +@@ -117,11 +124,11 @@ + dataresult = VaultSharedData.CODEC.parse(dynamicops, nbttagcompound.get("shared_data")); + logger = VaultBlockEntity.LOGGER; + Objects.requireNonNull(logger); +- optional = dataresult.resultOrPartial(logger::error); ++ optional = ((DataResult) dataresult).resultOrPartial(logger::error); // CraftBukkit - decompile error + VaultSharedData vaultshareddata = this.sharedData; + + Objects.requireNonNull(this.sharedData); +- optional.ifPresent(vaultshareddata::set); ++ ((Optional) optional).ifPresent(vaultshareddata::set); // CraftBukkit - decompile error + } + + } +@@ -321,6 +328,14 @@ + if (!list.isEmpty()) { + entityhuman.awardStat(StatisticList.ITEM_USED.get(itemstack.getItem())); + itemstack.consume(vaultconfig.keyItem().getCount(), entityhuman); ++ // CraftBukkit start ++ BlockDispenseLootEvent vaultDispenseLootEvent = CraftEventFactory.callBlockDispenseLootEvent(worldserver, blockposition, entityhuman, list); ++ if (vaultDispenseLootEvent.isCancelled()) { ++ return; ++ } ++ ++ list = vaultDispenseLootEvent.getDispensedLoot().stream().map(CraftItemStack::asNMSCopy).toList(); ++ // CraftBukkit end + unlock(worldserver, iblockdata, blockposition, vaultconfig, vaultserverdata, vaultshareddata, list); + vaultserverdata.addToRewardedPlayers(entityhuman); + vaultshareddata.updateConnectedPlayersWithinRange(worldserver, blockposition, vaultserverdata, vaultconfig, vaultconfig.deactivationRange()); +@@ -342,6 +357,14 @@ + vaultshareddata.setDisplayItem(ItemStack.EMPTY); + } else { + ItemStack itemstack = getRandomDisplayItemFromLootTable(worldserver, blockposition, (ResourceKey) vaultconfig.overrideLootTableToDisplay().orElse(vaultconfig.lootTable())); ++ // CraftBukkit start ++ VaultDisplayItemEvent event = CraftEventFactory.callVaultDisplayItemEvent(worldserver, blockposition, itemstack); ++ if (event.isCancelled()) { ++ return; ++ } ++ ++ itemstack = CraftItemStack.asNMSCopy(event.getDisplayItem()); ++ // CraftBukkit end + + vaultshareddata.setDisplayItem(itemstack); + } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index fe60bfb5b5..fb7d1e8f3e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -145,6 +145,7 @@ import org.bukkit.event.block.BellResonateEvent; import org.bukkit.event.block.BellRingEvent; import org.bukkit.event.block.BlockDamageAbortEvent; import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.block.BlockDispenseLootEvent; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockFadeEvent; @@ -164,6 +165,7 @@ import org.bukkit.event.block.FluidLevelChangeEvent; import org.bukkit.event.block.MoistureChangeEvent; import org.bukkit.event.block.NotePlayEvent; import org.bukkit.event.block.TNTPrimeEvent; +import org.bukkit.event.block.VaultDisplayItemEvent; import org.bukkit.event.entity.AreaEffectCloudApplyEvent; import org.bukkit.event.entity.ArrowBodyCountChangeEvent; import org.bukkit.event.entity.BatToggleSleepEvent; @@ -1607,6 +1609,20 @@ public class CraftEventFactory { return event; } + public static BlockDispenseLootEvent callBlockDispenseLootEvent(WorldServer worldServer, BlockPosition blockPosition, EntityHuman player, List rewardLoot) { + List craftItemStacks = rewardLoot.stream().map(CraftItemStack::asBukkitCopy).collect(Collectors.toList()); + + BlockDispenseLootEvent event = new BlockDispenseLootEvent((player == null) ? null : (Player) player.getBukkitEntity(), CraftBlock.at(worldServer, blockPosition), craftItemStacks); + Bukkit.getPluginManager().callEvent(event); + return event; + } + + public static VaultDisplayItemEvent callVaultDisplayItemEvent(WorldServer worldServer, BlockPosition blockPosition, ItemStack displayitemStack) { + VaultDisplayItemEvent event = new VaultDisplayItemEvent(CraftBlock.at(worldServer, blockPosition), CraftItemStack.asBukkitCopy(displayitemStack)); + Bukkit.getPluginManager().callEvent(event); + return event; + } + public static EntityToggleGlideEvent callToggleGlideEvent(EntityLiving entity, boolean gliding) { EntityToggleGlideEvent event = new EntityToggleGlideEvent((LivingEntity) entity.getBukkitEntity(), gliding); entity.level().getCraftServer().getPluginManager().callEvent(event);