geforkt von Mirrors/Paper
SPIGOT-7783, SPIGOT-7784, #1460: Add Trial Vault & Spawner event API
By: ShreyasAyyengar <shreyas.ayyengar@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
3a8b574f16
Commit
71695536dd
@ -1,6 +1,19 @@
|
|||||||
--- a/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.java
|
--- a/net/minecraft/world/level/block/entity/trialspawner/TrialSpawner.java
|
||||||
+++ b/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();
|
entityinsentient.setPersistenceRequired();
|
||||||
@ -21,3 +34,19 @@
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
} else {
|
} else {
|
||||||
TrialSpawner.a trialspawner_a = this.isOminous ? TrialSpawner.a.OMINOUS : TrialSpawner.a.NORMAL;
|
TrialSpawner.a trialspawner_a = this.isOminous ? TrialSpawner.a.OMINOUS : TrialSpawner.a.NORMAL;
|
||||||
|
@@ -248,6 +259,15 @@
|
||||||
|
ObjectArrayList<ItemStack> 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()) {
|
||||||
|
@ -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<VaultServerData>) dataresult).resultOrPartial(logger::error); // CraftBukkit - decompile error
|
||||||
|
VaultServerData vaultserverdata = this.serverData;
|
||||||
|
|
||||||
|
Objects.requireNonNull(this.serverData);
|
||||||
|
- optional.ifPresent(vaultserverdata::set);
|
||||||
|
+ ((Optional<VaultServerData>) 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<VaultConfig>) 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<VaultSharedData>) dataresult).resultOrPartial(logger::error); // CraftBukkit - decompile error
|
||||||
|
VaultSharedData vaultshareddata = this.sharedData;
|
||||||
|
|
||||||
|
Objects.requireNonNull(this.sharedData);
|
||||||
|
- optional.ifPresent(vaultshareddata::set);
|
||||||
|
+ ((Optional<VaultSharedData>) 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);
|
||||||
|
}
|
@ -145,6 +145,7 @@ import org.bukkit.event.block.BellResonateEvent;
|
|||||||
import org.bukkit.event.block.BellRingEvent;
|
import org.bukkit.event.block.BellRingEvent;
|
||||||
import org.bukkit.event.block.BlockDamageAbortEvent;
|
import org.bukkit.event.block.BlockDamageAbortEvent;
|
||||||
import org.bukkit.event.block.BlockDamageEvent;
|
import org.bukkit.event.block.BlockDamageEvent;
|
||||||
|
import org.bukkit.event.block.BlockDispenseLootEvent;
|
||||||
import org.bukkit.event.block.BlockDropItemEvent;
|
import org.bukkit.event.block.BlockDropItemEvent;
|
||||||
import org.bukkit.event.block.BlockExplodeEvent;
|
import org.bukkit.event.block.BlockExplodeEvent;
|
||||||
import org.bukkit.event.block.BlockFadeEvent;
|
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.MoistureChangeEvent;
|
||||||
import org.bukkit.event.block.NotePlayEvent;
|
import org.bukkit.event.block.NotePlayEvent;
|
||||||
import org.bukkit.event.block.TNTPrimeEvent;
|
import org.bukkit.event.block.TNTPrimeEvent;
|
||||||
|
import org.bukkit.event.block.VaultDisplayItemEvent;
|
||||||
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
||||||
import org.bukkit.event.entity.ArrowBodyCountChangeEvent;
|
import org.bukkit.event.entity.ArrowBodyCountChangeEvent;
|
||||||
import org.bukkit.event.entity.BatToggleSleepEvent;
|
import org.bukkit.event.entity.BatToggleSleepEvent;
|
||||||
@ -1607,6 +1609,20 @@ public class CraftEventFactory {
|
|||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BlockDispenseLootEvent callBlockDispenseLootEvent(WorldServer worldServer, BlockPosition blockPosition, EntityHuman player, List<ItemStack> rewardLoot) {
|
||||||
|
List<org.bukkit.inventory.ItemStack> 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) {
|
public static EntityToggleGlideEvent callToggleGlideEvent(EntityLiving entity, boolean gliding) {
|
||||||
EntityToggleGlideEvent event = new EntityToggleGlideEvent((LivingEntity) entity.getBukkitEntity(), gliding);
|
EntityToggleGlideEvent event = new EntityToggleGlideEvent((LivingEntity) entity.getBukkitEntity(), gliding);
|
||||||
entity.level().getCraftServer().getPluginManager().callEvent(event);
|
entity.level().getCraftServer().getPluginManager().callEvent(event);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren