diff --git a/paper/src/main/java/com/denizenscript/denizen/paper/PaperModule.java b/paper/src/main/java/com/denizenscript/denizen/paper/PaperModule.java index 016e6b9694..8c6a62a0dd 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/PaperModule.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/PaperModule.java @@ -103,6 +103,9 @@ public static void init() { ScriptEvent.registerScriptEvent(TNTPrimesScriptEvent.class); } ScriptEvent.registerScriptEvent(UnknownCommandScriptEvent.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + ScriptEvent.registerScriptEvent(VaultChangeStateScriptEvent.class); + } if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) { ScriptEvent.registerScriptEvent(WardenChangesAngerLevelScriptEvent.class); } diff --git a/paper/src/main/java/com/denizenscript/denizen/paper/events/VaultChangeStateScriptEvent.java b/paper/src/main/java/com/denizenscript/denizen/paper/events/VaultChangeStateScriptEvent.java new file mode 100644 index 0000000000..afe5f6d1b5 --- /dev/null +++ b/paper/src/main/java/com/denizenscript/denizen/paper/events/VaultChangeStateScriptEvent.java @@ -0,0 +1,74 @@ +package com.denizenscript.denizen.paper.events; + +import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.objects.LocationTag; +import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.scripts.ScriptEntryData; +import io.papermc.paper.event.block.VaultChangeStateEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class VaultChangeStateScriptEvent extends BukkitScriptEvent implements Listener { + + // <--[event] + // @Events + // vault changes state + // + // @Plugin Paper + // + // @Group Block + // + // @Cancellable true + // + // @Location true + // + // @Triggers when a vault block's state changes. A list of states can be found at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/TrialSpawner.State.html>. + // + // @Context + // returns the LocationTag of the vault block. + // returns the vault state before the change. + // returns the vault state after the change. + // + // @Player when the entity who triggered the change is a player. + // + // --> + + public VaultChangeStateScriptEvent() { + registerCouldMatcher("vault changes state"); + } + + public LocationTag location; + public VaultChangeStateEvent event; + + @Override + public boolean matches(ScriptPath path) { + if (!runInCheck(path, location)) { + return false; + } + return super.matches(path); + } + + @Override + public ScriptEntryData getScriptEntryData() { + return new BukkitScriptEntryData(event.getPlayer()); + } + + @Override + public ObjectTag getContext(String name) { + return switch (name) { + case "old_state" -> new ElementTag(event.getCurrentState()); + case "new_state" -> new ElementTag(event.getNewState()); + case "location" -> location; + default -> super.getContext(name); + }; + } + + @EventHandler + public void onVaultChangeStateEvent(VaultChangeStateEvent event) { + location = new LocationTag(event.getBlock().getLocation()); + this.event = event; + fire(event); + } +} diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java b/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java index a3e71d4ec1..16cf10467b 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java @@ -68,6 +68,9 @@ public static void registerMainEvents() { ScriptEvent.registerScriptEvent(BlockBurnsScriptEvent.class); ScriptEvent.registerScriptEvent(BlockCooksSmeltsItemScriptEvent.class); ScriptEvent.registerScriptEvent(BlockDestroyedByExplosionEvent.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + ScriptEvent.registerScriptEvent(BlockDispenseLootScriptEvent.class); + } ScriptEvent.registerScriptEvent(BlockDispensesScriptEvent.class); ScriptEvent.registerScriptEvent(BlockEquipsItemScriptEvent.class); ScriptEvent.registerScriptEvent(BlockExplodesScriptEvent.class); @@ -80,8 +83,14 @@ public static void registerMainEvents() { ScriptEvent.registerScriptEvent(BlockShearEntityScriptEvent.class); ScriptEvent.registerScriptEvent(BlockSpreadsScriptEvent.class); ScriptEvent.registerScriptEvent(BrewingStandFueledScriptEvent.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) { + ScriptEvent.registerScriptEvent(BrewingStartsScriptEvent.class); + } ScriptEvent.registerScriptEvent(BrewsScriptEvent.class); ScriptEvent.registerScriptEvent(CauldronLevelChangeScriptEvent.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + ScriptEvent.registerScriptEvent(CrafterCraftsScriptEvent.class); + } ScriptEvent.registerScriptEvent(DragonEggMovesScriptEvent.class); ScriptEvent.registerScriptEvent(FurnaceBurnsItemScriptEvent.class); ScriptEvent.registerScriptEvent(FurnaceStartsSmeltingScriptEvent.class); @@ -95,11 +104,10 @@ public static void registerMainEvents() { ScriptEvent.registerScriptEvent(RedstoneScriptEvent.class); ScriptEvent.registerScriptEvent(SpongeAbsorbsScriptEvent.class); if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) { - ScriptEvent.registerScriptEvent(BrewingStartsScriptEvent.class); ScriptEvent.registerScriptEvent(TNTPrimesScriptEvent.class); } if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { - ScriptEvent.registerScriptEvent(CrafterCraftsScriptEvent.class); + ScriptEvent.registerScriptEvent(VaultDisplayItemScriptEvent.class); } // Entity events diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/block/BlockDispenseLootScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/block/BlockDispenseLootScriptEvent.java new file mode 100644 index 0000000000..1b15951a33 --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/events/block/BlockDispenseLootScriptEvent.java @@ -0,0 +1,89 @@ +package com.denizenscript.denizen.events.block; + +import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.objects.*; +import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; +import com.denizenscript.denizencore.objects.ObjectTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.denizencore.scripts.ScriptEntryData; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockDispenseLootEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public class BlockDispenseLootScriptEvent extends BukkitScriptEvent implements Listener { + + // <--[event] + // @Events + // loot dispenses from + // + // @Group Block + // + // @Location true + // + // @Cancellable true + // + // @Player Always. + // + // @Triggers when a block dispenses loot containing multiple items. + // + // @Context + // returns a ListTag(ItemTag) of outcome items. + // returns a LocationTag of the block that is dispensing the items. + // + // @Determine + // "LOOT:" to determine the new items that are outputted. + // + // --> + + public BlockDispenseLootScriptEvent() { + registerCouldMatcher("loot dispenses from "); + this.registerDetermination("loot", ListTag.class, (evt, context, input) -> { + List items = new ArrayList<>(input.size()); + for (ItemTag item : input.filter(ItemTag.class, context)) { + items.add(item.getItemStack()); + } + evt.event.setDispensedLoot(items); + }); + } + + public MaterialTag block; + public LocationTag location; + public BlockDispenseLootEvent event; + + @Override + public boolean matches(ScriptPath path) { + if (!path.tryArgObject(3, block)) { + return false; + } + if (!runInCheck(path, location)) { + return false; + } + return super.matches(path); + } + + @Override + public ScriptEntryData getScriptEntryData() { + return new BukkitScriptEntryData(new PlayerTag(event.getPlayer()), null); + } + + @Override + public ObjectTag getContext(String name) { + return switch (name) { + case "loot" -> new ListTag(event.getDispensedLoot(), ItemTag::new); + case "location" -> location; + default -> super.getContext(name); + }; + } + + @EventHandler + public void onBlockLootDispense(BlockDispenseLootEvent event) { + block = new MaterialTag(event.getBlock().getType()); + location = new LocationTag(event.getBlock().getLocation()); + this.event = event; + fire(event); + } +} diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java new file mode 100644 index 0000000000..f17d165124 --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java @@ -0,0 +1,70 @@ +package com.denizenscript.denizen.events.block; + +import com.denizenscript.denizen.events.BukkitScriptEvent; +import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizen.objects.LocationTag; +import com.denizenscript.denizencore.objects.ObjectTag; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.VaultDisplayItemEvent; + +public class VaultDisplayItemScriptEvent extends BukkitScriptEvent implements Listener { + + // <--[event] + // @Events + // vault displays + // + // @Group Block + // + // @Location true + // + // @Cancellable true + // + // @Triggers when a vault block displays an item. + // + // @Context + // returns the LocationTag of the vault block. + // returns the ItemTag being displayed. + // + // @Determine + // ItemTag to set the item being displayed. + // + // --> + + public VaultDisplayItemScriptEvent() { + registerCouldMatcher("vault displays "); + this.registerDetermination(null, ItemTag.class, (evt, context, input) -> { + evt.event.setDisplayItem(input.getItemStack()); + }); + } + + public LocationTag location; + public VaultDisplayItemEvent event; + + @Override + public boolean matches(ScriptPath path) { + if (!runInCheck(path, location)) { + return false; + } + if (!path.tryArgObject(2, new ItemTag(event.getDisplayItem()))) { + return false; + } + return super.matches(path); + } + + @Override + public ObjectTag getContext(String name) { + return switch (name) { + case "item" -> new ItemTag(event.getDisplayItem()); + case "location" -> location; + default -> super.getContext(name); + }; + } + + @EventHandler + public void onVaultDisplayItemEvent(VaultDisplayItemEvent event) { + location = new LocationTag(event.getBlock().getLocation()); + this.event = event; + fire(event); + } +} diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java index 477c8bb129..5d4a9c7c04 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java @@ -296,6 +296,9 @@ public static void registerMainProperties() { PropertyParser.registerProperty(MaterialLightable.class, MaterialTag.class); PropertyParser.registerProperty(MaterialMode.class, MaterialTag.class); PropertyParser.registerProperty(MaterialNote.class, MaterialTag.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) { + PropertyParser.registerProperty(MaterialOminous.class, MaterialTag.class); + } PropertyParser.registerProperty(MaterialPersistent.class, MaterialTag.class); PropertyParser.registerProperty(MaterialPower.class, MaterialTag.class); PropertyParser.registerProperty(MaterialShape.class, MaterialTag.class); diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityItem.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityItem.java index 36fa15c2f7..4195133ad1 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityItem.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityItem.java @@ -30,6 +30,7 @@ public class EntityItem implements Property { // - an eye-of-ender's item, which is both displayed and dropped. // - a fireball's display item. // - an item display's display item. + // - an ominous item's display item. // --> public static boolean describes(ObjectTag object) { @@ -42,7 +43,8 @@ public static boolean describes(ObjectTag object) { || entity instanceof SizedFireball || entity instanceof ThrowableProjectile || entity instanceof EnderSignal - || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && entity instanceof ItemDisplay); + || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && entity instanceof ItemDisplay) + || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && entity instanceof OminousItemSpawner); } public static EntityItem getFrom(ObjectTag entity) { diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialMode.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialMode.java index d9dcb0f0c9..ef1cb09642 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialMode.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialMode.java @@ -28,6 +28,8 @@ public class MaterialMode extends MaterialProperty { // For sculk_shriekers, modes are SHRIEKING and NORMAL. // For tripwires, modes are ARMED and DISARMED. // For creaking_hearts, modes are AWAKE, DORMANT, and UPROOTED. + // For trial_spawners, modes are ACTIVE, COOLDOWN, EJECTING_REWARD, INACTIVE, WAITING_FOR_PLAYERS, and WAITING_FOR_REWARD_EJECTION. + // For vaults, modes are ACTIVE, EJECTING, INACTIVE, and UNLOCKING. // --> public static boolean describes(MaterialTag material) { @@ -42,8 +44,10 @@ public static boolean describes(MaterialTag material) { || data instanceof BigDripleaf || data instanceof Tripwire || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && (data instanceof SculkCatalyst - || data instanceof SculkShrieker)) - || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && data instanceof CreakingHeart); + || data instanceof SculkShrieker)) + || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && (data instanceof CreakingHeart + || data instanceof TrialSpawner + || data instanceof Vault)); } @Override @@ -84,6 +88,12 @@ else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && getBlockData() i else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof CreakingHeart creakingHeart) { return new ElementTag(creakingHeart.getCreakingHeartState()); } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof TrialSpawner trialSpawner) { + return new ElementTag(trialSpawner.getTrialSpawnerState()); + } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof Vault vault) { + return new ElementTag(vault.getVaultState()); + } return null; } @@ -135,6 +145,16 @@ else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() i creakingHeart.setCreakingHeartState(value.asEnum(CreakingHeart.State.class)); } } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof TrialSpawner trialSpawner) { + if (mechanism.requireEnum(TrialSpawner.State.class)) { + trialSpawner.setTrialSpawnerState(value.asEnum(TrialSpawner.State.class)); + } + } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof Vault vault) { + if (mechanism.requireEnum(Vault.State.class)) { + vault.setVaultState(value.asEnum(Vault.State.class)); + } + } } @Override diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialOminous.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialOminous.java new file mode 100644 index 0000000000..dcdf4a56d2 --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialOminous.java @@ -0,0 +1,55 @@ +package com.denizenscript.denizen.objects.properties.material; + +import com.denizenscript.denizen.objects.MaterialTag; +import com.denizenscript.denizencore.objects.Mechanism; +import com.denizenscript.denizencore.objects.core.ElementTag; +import org.bukkit.block.data.type.TrialSpawner; +import org.bukkit.block.data.type.Vault; + +public class MaterialOminous extends MaterialProperty { + + // <--[property] + // @object MaterialTag + // @name ominous + // @input ElementTag(Boolean) + // @description + // Controls whether a trial spawner or vault is in ominous mode. + // --> + + public static boolean describes(MaterialTag material) { + return material.getModernData() instanceof TrialSpawner + || material.getModernData() instanceof Vault; + } + + @Override + public ElementTag getPropertyValue() { + if (getBlockData() instanceof TrialSpawner trialSpawner) { + return new ElementTag(trialSpawner.isOminous()); + } + else if (getBlockData() instanceof Vault vault) { + return new ElementTag(vault.isOminous()); + } + return null; + } + + @Override + public void setPropertyValue(ElementTag value, Mechanism mechanism) { + if (mechanism.requireBoolean()) { + if (getBlockData() instanceof TrialSpawner trialSpawner) { + trialSpawner.setOminous(value.asBoolean()); + } + else if (getBlockData() instanceof Vault vault) { + vault.setOminous(value.asBoolean()); + } + } + } + + @Override + public String getPropertyId() { + return "ominous"; + } + + public static void register() { + autoRegister("ominous", MaterialOminous.class, ElementTag.class, false); + } +}