From 1a3467e43e0fb6dfd72bdd215f9b1b2070862361 Mon Sep 17 00:00:00 2001 From: MCSamuel Date: Thu, 6 Nov 2025 20:28:45 -0800 Subject: [PATCH 1/4] Trial spawners and vaults compatibility --- .../denizen/paper/PaperModule.java | 3 + .../events/VaultChangeStateScriptEvent.java | 74 ++++ .../denizen/events/ScriptEventRegistry.java | 9 +- .../block/VaultDisplayItemScriptEvent.java | 73 ++++ .../objects/properties/PropertyRegistry.java | 3 + .../properties/material/MaterialMode.java | 335 ++++++------------ .../properties/material/MaterialOminous.java | 55 +++ 7 files changed, 325 insertions(+), 227 deletions(-) create mode 100644 paper/src/main/java/com/denizenscript/denizen/paper/events/VaultChangeStateScriptEvent.java create mode 100644 plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java create mode 100644 plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialOminous.java 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 58ff60ed66..3cf01c2b26 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/PaperModule.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/PaperModule.java @@ -100,6 +100,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..ca19263fb2 --- /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 state changes + // + // @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); + } +} \ No newline at end of file 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..5a24d17e47 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java @@ -80,8 +80,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 +101,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/VaultDisplayItemScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java new file mode 100644 index 0000000000..0930b671ae --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java @@ -0,0 +1,73 @@ +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, item) -> { + this.item = item; + evt.event.setDisplayItem(item.getItemStack()); + }); + } + + public LocationTag location; + public ItemTag item; + public VaultDisplayItemEvent event; + + @Override + public boolean matches(ScriptPath path) { + if (!runInCheck(path, location)) { + return false; + } + if (!path.tryArgObject(2, item)) { + return false; + } + return super.matches(path); + } + + @Override + public ObjectTag getContext(String name) { + return switch (name) { + case "item" -> item; + case "location" -> location; + default -> super.getContext(name); + }; + } + + @EventHandler + public void onVaultDisplayItemEvent(VaultDisplayItemEvent event) { + location = new LocationTag(event.getBlock().getLocation()); + item = new ItemTag(event.getDisplayItem()); + this.event = event; + fire(event); + } +} \ No newline at end of file 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/material/MaterialMode.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialMode.java index 3dfb61c2cc..dd3af9b92e 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 @@ -4,25 +4,36 @@ import com.denizenscript.denizen.nms.NMSVersion; import com.denizenscript.denizen.objects.MaterialTag; import com.denizenscript.denizencore.objects.Mechanism; -import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.Property; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import com.denizenscript.denizencore.utilities.CoreUtilities; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.*; -public class MaterialMode implements Property { - - public static boolean describes(ObjectTag material) { - if (!(material instanceof MaterialTag)) { - return false; - } - MaterialTag mat = (MaterialTag) material; - if (!mat.hasModernData()) { - return false; - } - BlockData data = mat.getModernData(); +public class MaterialMode extends MaterialProperty { + + // <--[tag] + // @object MaterialTag + // @name mode + // @input ElementTag + // @description + // Controls a block's mode. + // For comparators, values are COMPARE and SUBTRACT. + // For piston_heads, values are NORMAL and SHORT. + // For bubble_columns, values are NORMAL and DRAG. + // For structure_blocks, values are CORNER, DATA, LOAD, and SAVE. + // For sculk_sensors, values are ACTIVE, COOLDOWN, and INACTIVE. + // For daylight_detectors, values are INVERTED and NORMAL. + // For command_blocks, values are CONDITIONAL and NORMAL. + // For big_dripleafs, values are FULL, NONE, PARTIAL, and UNSTABLE. + // For sculk_catalysts, values are BLOOM and NORMAL. + // For sculk_shriekers, values are SHRIEKING and NORMAL. + // For tripwires, values are ARMED and DISARMED. + // For trial_spawners, values are ACTIVE, COOLDOWN, EJECTING_REWARD, INACTIVE, WAITING_FOR_PLAYERS, and WAITING_FOR_REWARD_EJECTION. + // For vaults, values are ACTIVE, EJECTING, INACTIVE, and UNLOCKING. + // --> + + public static boolean describes(MaterialTag material) { + BlockData data = material.getModernData(); return data instanceof Comparator || data instanceof PistonHead || data instanceof BubbleColumn @@ -33,242 +44,116 @@ public static boolean describes(ObjectTag material) { || data instanceof BigDripleaf || data instanceof Tripwire || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && (data instanceof SculkCatalyst - || data instanceof SculkShrieker)); + || data instanceof SculkShrieker)) + || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && (data instanceof TrialSpawner + || data instanceof Vault)); } - public static MaterialMode getFrom(ObjectTag _material) { - if (!describes(_material)) { - return null; + @Override + public ElementTag getPropertyValue() { + if (getBlockData() instanceof Comparator comparator) { + return new ElementTag(comparator.getMode().name(), true); } - else { - return new MaterialMode((MaterialTag) _material); + else if (getBlockData() instanceof BubbleColumn bubbleColumn) { + return new ElementTag(bubbleColumn.isDrag() ? "DRAG" : "NORMAL", true); } - } - - public static final String[] handledMechs = new String[] { - "mode" - }; - - public MaterialMode(MaterialTag _material) { - material = _material; - } - - public MaterialTag material; - - public static void register() { - - // <--[tag] - // @attribute - // @returns ElementTag - // @mechanism MaterialTag.mode - // @group properties - // @description - // Returns a block's mode. - // For comparators, output is COMPARE or SUBTRACT. - // For piston_heads, output is NORMAL or SHORT. - // For bubble_columns, output is NORMAL or DRAG. - // For structure_blocks, output is CORNER, DATA, LOAD, or SAVE. - // For sculk_sensors, output is ACTIVE, COOLDOWN, or INACTIVE. - // For daylight_detectors, output is INVERTED or NORMAL. - // For command_blocks, output is CONDITIONAL or NORMAL. - // For big_dripleafs, output is FULL, NONE, PARTIAL, or UNSTABLE. - // For sculk_catalysts, output is BLOOM or NORMAL. - // For sculk_shriekers, output is SHRIEKING or NORMAL. - // For tripwires, output is ARMED or DISARMED. - // --> - PropertyParser.registerStaticTag(MaterialMode.class, ElementTag.class, "mode", (attribute, material) -> { - return new ElementTag(material.getPropertyString()); - }); - } - - public boolean isComparator() { - return material.getModernData() instanceof Comparator; - } - - public boolean isPistonHead() { - return material.getModernData() instanceof PistonHead; - } - - public boolean isBubbleColumn() { - return material.getModernData() instanceof BubbleColumn; - } - - public boolean isStructureBlock() { - return material.getModernData() instanceof StructureBlock; - } - - public boolean isDaylightDetector() { - return material.getModernData() instanceof DaylightDetector; - } - - public boolean isCommandBlock() { - return material.getModernData() instanceof CommandBlock; - } - - public boolean isSculkSensor() { - return material.getModernData() instanceof SculkSensor; - } - - public boolean isBigDripleaf() { - return material.getModernData() instanceof BigDripleaf; - } - - public boolean isTripwire() { - return material.getModernData() instanceof Tripwire; - } - - public boolean isSculkCatalyst() { - return NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && material.getModernData() instanceof SculkCatalyst; - } - - public boolean isSculkShrieker() { - return NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && material.getModernData() instanceof SculkShrieker; - } - - public Comparator getComparator() { - return (Comparator) material.getModernData(); - } - - public PistonHead getPistonHead() { - return (PistonHead) material.getModernData(); - } - - public BubbleColumn getBubbleColumn() { - return (BubbleColumn) material.getModernData(); - } - - public StructureBlock getStructureBlock() { - return (StructureBlock) material.getModernData(); - } - - public DaylightDetector getDaylightDetector() { - return (DaylightDetector) material.getModernData(); - } - - public CommandBlock getCommandBlock() { - return (CommandBlock) material.getModernData(); - } - - public SculkSensor getSculkSensor() { - return (SculkSensor) material.getModernData(); - } - - public BigDripleaf getBigDripleaf() { - return (BigDripleaf) material.getModernData(); - } - - public Tripwire getTripwire() { - return (Tripwire) material.getModernData(); - } - - /*public SculkCatalyst getSculkCatalyst() { // TODO: 1.19 - return (SculkCatalyst) material.getModernData(); - } - - public SculkShrieker getSculkShrieker() { - return (SculkShrieker) material.getModernData(); - }*/ - - @Override - public String getPropertyString() { - if (isComparator()) { - return getComparator().getMode().name(); + else if (getBlockData() instanceof PistonHead pistonHead) { + return new ElementTag(pistonHead.isShort() ? "SHORT" : "NORMAL", true); } - else if (isBubbleColumn()) { - return getBubbleColumn().isDrag() ? "DRAG" : "NORMAL"; + else if (getBlockData() instanceof StructureBlock structureBlock) { + return new ElementTag(structureBlock.getMode().name(), true); } - else if (isPistonHead()) { - return getPistonHead().isShort() ? "SHORT" : "NORMAL"; + else if (getBlockData() instanceof DaylightDetector daylightDetector) { + return new ElementTag(daylightDetector.isInverted() ? "INVERTED" : "NORMAL", true); } - else if (isStructureBlock()) { - return getStructureBlock().getMode().name(); + else if (getBlockData() instanceof CommandBlock commandBlock) { + return new ElementTag(commandBlock.isConditional() ? "CONDITIONAL" : "NORMAL", true); } - else if (isDaylightDetector()) { - return getDaylightDetector().isInverted() ? "INVERTED" : "NORMAL"; + else if (getBlockData() instanceof SculkSensor sculkSensor) { + return new ElementTag(sculkSensor.getPhase().name(), true); } - else if (isCommandBlock()) { - return getCommandBlock().isConditional() ? "CONDITIONAL" : "NORMAL"; + else if (getBlockData() instanceof BigDripleaf bigDripleaf) { + return new ElementTag(bigDripleaf.getTilt().name(), true); } - else if (isSculkSensor()) { - return getSculkSensor().getPhase().name(); + else if (getBlockData() instanceof Tripwire tripwire) { + return new ElementTag(tripwire.isDisarmed() ? "DISARMED" : "ARMED", true); } - else if (isBigDripleaf()) { - return getBigDripleaf().getTilt().name(); + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && getBlockData() instanceof SculkCatalyst sculkCatalyst) { + return new ElementTag(sculkCatalyst.isBloom() ? "BLOOM" : "NORMAL", true); } - else if (isTripwire()) { - return getTripwire().isDisarmed() ? "DISARMED" : "ARMED"; + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && getBlockData() instanceof SculkShrieker sculkShrieker) { + return new ElementTag(sculkShrieker.isShrieking() ? "SHRIEKING" : "NORMAL", true); } - else if (isSculkCatalyst()) { - return ((SculkCatalyst) material.getModernData()).isBloom() ? "BLOOM" : "NORMAL"; // TODO: 1.19 + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof TrialSpawner trialSpawner) { + return new ElementTag(trialSpawner.getTrialSpawnerState().name(), true); } - else if (isSculkShrieker()) { - return ((SculkShrieker) material.getModernData()).isShrieking() ? "SHRIEKING" : "NORMAL"; // TODO: 1.19 + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof Vault vault) { + return new ElementTag(vault.getVaultState().name(), true); } return null; // Unreachable } @Override - public String getPropertyId() { - return "mode"; - } - - @Override - public void adjust(Mechanism mechanism) { - - // <--[mechanism] - // @object MaterialTag - // @name mode - // @input ElementTag - // @description - // Set a block's mode. - // For comparators, input is COMPARE or SUBTRACT. - // For piston_heads, input is NORMAL or SHORT. - // For bubble_columns, input is NORMAL or DRAG. - // For structure_blocks, input is CORNER, DATA, LOAD, or SAVE. - // For sculk_sensors, input is ACTIVE, COOLDOWN, or INACTIVE. - // For daylight_detectors, input is INVERTED or NORMAL. - // For command_blocks, input is CONDITIONAL or NORMAL. - // For big_dripleafs, input is FULL, NONE, PARTIAL, or UNSTABLE. - // For sculk_catalysts, input is BLOOM or NORMAL. - // For sculk_shriekers, input is SHRIEKING or NORMAL. - // For tripwires, input is ARMED or DISARMED. - // @tags - // - // --> - if (mechanism.matches("mode")) { - if (isComparator() && mechanism.requireEnum(Comparator.Mode.class)) { - getComparator().setMode(Comparator.Mode.valueOf(mechanism.getValue().asString().toUpperCase())); - } - else if (isBubbleColumn()) { - getBubbleColumn().setDrag(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "drag")); - } - else if (isPistonHead()) { - getPistonHead().setShort(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "short")); - } - else if (isStructureBlock() && mechanism.requireEnum(StructureBlock.Mode.class)) { - getStructureBlock().setMode(StructureBlock.Mode.valueOf(mechanism.getValue().asString().toUpperCase())); + public void setPropertyValue(ElementTag value, Mechanism mechanism) { + if (getBlockData() instanceof Comparator comparator) { + if (mechanism.requireEnum(Comparator.Mode.class)) { + comparator.setMode(value.asEnum(Comparator.Mode.class)); } - else if (isDaylightDetector()) { - getDaylightDetector().setInverted(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "inverted")); - } - else if (isCommandBlock()) { - getCommandBlock().setConditional(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "conditional")); - } - else if (isSculkSensor() && mechanism.requireEnum(SculkSensor.Phase.class)) { - getSculkSensor().setPhase(SculkSensor.Phase.valueOf(mechanism.getValue().asString().toUpperCase())); + } + else if (getBlockData() instanceof BubbleColumn bubbleColumn) { + bubbleColumn.setDrag(CoreUtilities.equalsIgnoreCase(value.toString(), "drag")); + } + else if (getBlockData() instanceof PistonHead pistonHead) { + pistonHead.setShort(CoreUtilities.equalsIgnoreCase(value.toString(), "short")); + } + else if (getBlockData() instanceof StructureBlock structureBlock) { + if (mechanism.requireEnum(StructureBlock.Mode.class)) { + structureBlock.setMode(value.asEnum(StructureBlock.Mode.class)); } - else if (isBigDripleaf() && mechanism.requireEnum(BigDripleaf.Tilt.class)) { - getBigDripleaf().setTilt(BigDripleaf.Tilt.valueOf(mechanism.getValue().asString().toUpperCase())); + } + else if (getBlockData() instanceof DaylightDetector daylightDetector) { + daylightDetector.setInverted(CoreUtilities.equalsIgnoreCase(value.toString(), "inverted")); + } + else if (getBlockData() instanceof CommandBlock commandBlock) { + commandBlock.setConditional(CoreUtilities.equalsIgnoreCase(value.toString(), "conditional")); + } + else if (getBlockData() instanceof SculkSensor sculkSensor) { + if (mechanism.requireEnum(SculkSensor.Phase.class)) { + sculkSensor.setPhase(value.asEnum(SculkSensor.Phase.class)); } - else if (isTripwire()) { - getTripwire().setDisarmed(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "disarmed")); + } + else if (getBlockData() instanceof BigDripleaf bigDripleaf) { + if (mechanism.requireEnum(BigDripleaf.Tilt.class)) { + bigDripleaf.setTilt(value.asEnum(BigDripleaf.Tilt.class)); } - else if (isSculkCatalyst()) { - ((SculkCatalyst) material.getModernData()).setBloom(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "bloom")); // TODO: 1.19 + } + else if (getBlockData() instanceof Tripwire tripwire) { + tripwire.setDisarmed(CoreUtilities.equalsIgnoreCase(value.toString(), "disarmed")); + } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && getBlockData() instanceof SculkCatalyst sculkCatalyst) { + sculkCatalyst.setBloom(CoreUtilities.equalsIgnoreCase(value.toString(), "bloom")); + } + else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && getBlockData() instanceof SculkShrieker sculkShrieker) { + sculkShrieker.setShrieking(CoreUtilities.equalsIgnoreCase(value.toString(), "shrieking")); + } + 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 (isSculkShrieker()) { - ((SculkShrieker) material.getModernData()).setShrieking(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "shrieking")); // TODO: 1.19 + } + 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 + public String getPropertyId() { + return "mode"; + } + + public static void register() { + autoRegister("mode", MaterialMode.class, ElementTag.class, false); + } } 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..0a7a87fd15 --- /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 { + + // <--[tag] + // @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); + } +} From 2fe9140b416c1429e7166f626e893deb5327195b Mon Sep 17 00:00:00 2001 From: MCSamuel Date: Thu, 6 Nov 2025 20:30:19 -0800 Subject: [PATCH 2/4] slight fixes --- .../denizen/paper/events/VaultChangeStateScriptEvent.java | 2 +- .../denizen/events/block/VaultDisplayItemScriptEvent.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 index ca19263fb2..6e06d79f61 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/events/VaultChangeStateScriptEvent.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/events/VaultChangeStateScriptEvent.java @@ -71,4 +71,4 @@ public void onVaultChangeStateEvent(VaultChangeStateEvent event) { this.event = event; fire(event); } -} \ No newline at end of file +} 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 index 0930b671ae..f768fce7fb 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java @@ -70,4 +70,4 @@ public void onVaultDisplayItemEvent(VaultDisplayItemEvent event) { this.event = event; fire(event); } -} \ No newline at end of file +} From 405bd9cbf442d47d1dce9f91be1c600041de5b21 Mon Sep 17 00:00:00 2001 From: MCSamuel Date: Thu, 8 Jan 2026 12:38:50 -0800 Subject: [PATCH 3/4] added BlockDispenseLootScriptEvent to accommodate vault loot dispensing --- .../denizen/events/ScriptEventRegistry.java | 3 + .../block/BlockDispenseLootScriptEvent.java | 89 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 plugin/src/main/java/com/denizenscript/denizen/events/block/BlockDispenseLootScriptEvent.java 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 5a24d17e47..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); 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..97adebd386 --- /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 + // to determine the new items that are outputted. + // + // --> + + public BlockDispenseLootScriptEvent() { + registerCouldMatcher("loot dispenses from "); + this.registerDetermination(null, ListTag.class, (evt, context, input) -> { + List items = new ArrayList<>(); + 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); + } +} From f9e83cc25a603efd007f2cb7b111ce289210a5d6 Mon Sep 17 00:00:00 2001 From: MCSamuel Date: Mon, 12 Jan 2026 16:50:43 -0800 Subject: [PATCH 4/4] minor changes --- .../events/VaultChangeStateScriptEvent.java | 2 +- .../block/BlockDispenseLootScriptEvent.java | 6 +++--- .../block/VaultDisplayItemScriptEvent.java | 11 ++++------ .../objects/properties/entity/EntityItem.java | 4 +++- .../properties/material/MaterialMode.java | 21 +++++++++---------- 5 files changed, 21 insertions(+), 23 deletions(-) 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 index 6e06d79f61..afe5f6d1b5 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/events/VaultChangeStateScriptEvent.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/events/VaultChangeStateScriptEvent.java @@ -24,7 +24,7 @@ public class VaultChangeStateScriptEvent extends BukkitScriptEvent implements Li // // @Location true // - // @Triggers when a vault block state changes + // @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. 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 index 97adebd386..1b15951a33 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/block/BlockDispenseLootScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/block/BlockDispenseLootScriptEvent.java @@ -35,14 +35,14 @@ public class BlockDispenseLootScriptEvent extends BukkitScriptEvent implements L // returns a LocationTag of the block that is dispensing the items. // // @Determine - // to determine the new items that are outputted. + // "LOOT:" to determine the new items that are outputted. // // --> public BlockDispenseLootScriptEvent() { registerCouldMatcher("loot dispenses from "); - this.registerDetermination(null, ListTag.class, (evt, context, input) -> { - List items = new ArrayList<>(); + 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()); } 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 index f768fce7fb..f17d165124 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java @@ -33,14 +33,12 @@ public class VaultDisplayItemScriptEvent extends BukkitScriptEvent implements Li public VaultDisplayItemScriptEvent() { registerCouldMatcher("vault displays "); - this.registerDetermination(null, ItemTag.class, (evt, context, item) -> { - this.item = item; - evt.event.setDisplayItem(item.getItemStack()); + this.registerDetermination(null, ItemTag.class, (evt, context, input) -> { + evt.event.setDisplayItem(input.getItemStack()); }); } public LocationTag location; - public ItemTag item; public VaultDisplayItemEvent event; @Override @@ -48,7 +46,7 @@ public boolean matches(ScriptPath path) { if (!runInCheck(path, location)) { return false; } - if (!path.tryArgObject(2, item)) { + if (!path.tryArgObject(2, new ItemTag(event.getDisplayItem()))) { return false; } return super.matches(path); @@ -57,7 +55,7 @@ public boolean matches(ScriptPath path) { @Override public ObjectTag getContext(String name) { return switch (name) { - case "item" -> item; + case "item" -> new ItemTag(event.getDisplayItem()); case "location" -> location; default -> super.getContext(name); }; @@ -66,7 +64,6 @@ public ObjectTag getContext(String name) { @EventHandler public void onVaultDisplayItemEvent(VaultDisplayItemEvent event) { location = new LocationTag(event.getBlock().getLocation()); - item = new ItemTag(event.getDisplayItem()); this.event = event; fire(event); } 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 dd3af9b92e..f772ac9fd7 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 @@ -5,7 +5,6 @@ import com.denizenscript.denizen.objects.MaterialTag; import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.utilities.CoreUtilities; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.*; @@ -44,7 +43,7 @@ public static boolean describes(MaterialTag material) { || data instanceof BigDripleaf || data instanceof Tripwire || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && (data instanceof SculkCatalyst - || data instanceof SculkShrieker)) + || data instanceof SculkShrieker)) || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && (data instanceof TrialSpawner || data instanceof Vault)); } @@ -85,10 +84,10 @@ else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && getBlockData() i return new ElementTag(sculkShrieker.isShrieking() ? "SHRIEKING" : "NORMAL", true); } else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof TrialSpawner trialSpawner) { - return new ElementTag(trialSpawner.getTrialSpawnerState().name(), true); + return new ElementTag(trialSpawner.getTrialSpawnerState()); } else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof Vault vault) { - return new ElementTag(vault.getVaultState().name(), true); + return new ElementTag(vault.getVaultState()); } return null; // Unreachable } @@ -101,10 +100,10 @@ public void setPropertyValue(ElementTag value, Mechanism mechanism) { } } else if (getBlockData() instanceof BubbleColumn bubbleColumn) { - bubbleColumn.setDrag(CoreUtilities.equalsIgnoreCase(value.toString(), "drag")); + bubbleColumn.setDrag(value.asLowerString().equals("drag")); } else if (getBlockData() instanceof PistonHead pistonHead) { - pistonHead.setShort(CoreUtilities.equalsIgnoreCase(value.toString(), "short")); + pistonHead.setShort(value.asLowerString().equals("short")); } else if (getBlockData() instanceof StructureBlock structureBlock) { if (mechanism.requireEnum(StructureBlock.Mode.class)) { @@ -112,10 +111,10 @@ else if (getBlockData() instanceof StructureBlock structureBlock) { } } else if (getBlockData() instanceof DaylightDetector daylightDetector) { - daylightDetector.setInverted(CoreUtilities.equalsIgnoreCase(value.toString(), "inverted")); + daylightDetector.setInverted(value.asLowerString().equals("inverted")); } else if (getBlockData() instanceof CommandBlock commandBlock) { - commandBlock.setConditional(CoreUtilities.equalsIgnoreCase(value.toString(), "conditional")); + commandBlock.setConditional(value.asLowerString().equals("conditional")); } else if (getBlockData() instanceof SculkSensor sculkSensor) { if (mechanism.requireEnum(SculkSensor.Phase.class)) { @@ -128,13 +127,13 @@ else if (getBlockData() instanceof BigDripleaf bigDripleaf) { } } else if (getBlockData() instanceof Tripwire tripwire) { - tripwire.setDisarmed(CoreUtilities.equalsIgnoreCase(value.toString(), "disarmed")); + tripwire.setDisarmed(value.asLowerString().equals("disarmed")); } else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && getBlockData() instanceof SculkCatalyst sculkCatalyst) { - sculkCatalyst.setBloom(CoreUtilities.equalsIgnoreCase(value.toString(), "bloom")); + sculkCatalyst.setBloom(value.asLowerString().equals("bloom")); } else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && getBlockData() instanceof SculkShrieker sculkShrieker) { - sculkShrieker.setShrieking(CoreUtilities.equalsIgnoreCase(value.toString(), "shrieking")); + sculkShrieker.setShrieking(value.asLowerString().equals("shrieking")); } else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof TrialSpawner trialSpawner) { if (mechanism.requireEnum(TrialSpawner.State.class)) {