Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but the event is called changes and this says change.


// <--[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>.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vault block

TrialSpawner.State

//
// @Context
// <context.location> returns the LocationTag of the vault block.
// <context.old_state> returns the vault state before the change.
// <context.new_state> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the class name usually matches the Denizen name over the bukkit name, so that it's easier to spot in code for us.


// <--[event]
// @Events
// loot dispenses from <block>
//
// @Group Block
//
// @Location true
//
// @Cancellable true
//
// @Player Always.
//
// @Triggers when a block dispenses loot containing multiple items.
//
// @Context
// <context.loot> returns a ListTag(ItemTag) of outcome items.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outcome here sounds a little weird imo? I'd just say loot items maybe, or something like items being dispensed if you want to be more explicit.

// <context.location> returns a LocationTag of the block that is dispensing the items.
//
// @Determine
// "LOOT:<ListTag(ItemTag)>" to determine the new items that are outputted.
//
// -->

public BlockDispenseLootScriptEvent() {
registerCouldMatcher("loot dispenses from <block>");
this.<BlockDispenseLootScriptEvent, ListTag>registerDetermination("loot", ListTag.class, (evt, context, input) -> {
List<ItemStack> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <item>
//
// @Group Block
//
// @Location true
//
// @Cancellable true
//
// @Triggers when a vault block displays an item.
//
// @Context
// <context.location> returns the LocationTag of the vault block.
// <context.item> returns the ItemTag being displayed.
//
// @Determine
// ItemTag to set the item being displayed.
//
// -->

public VaultDisplayItemScriptEvent() {
registerCouldMatcher("vault displays <item>");
this.<VaultDisplayItemScriptEvent, ItemTag>registerDetermination(null, ItemTag.class, (evt, context, input) -> {
evt.event.setDisplayItem(input.getItemStack());
});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally prefixed determinations are preferred - easier to read/work with in code, and easier to manage for us when more get added.

}

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()))) {
Copy link
Copy Markdown
Member

@tal5 tal5 Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be put in a field for matches optimization (getContext should still access it directly though).

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Comment thread
tal5 marked this conversation as resolved.
}

public static EntityItem getFrom(ObjectTag entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class MaterialMode extends MaterialProperty<ElementTag> {
// 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) {
Expand All @@ -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
Expand Down Expand Up @@ -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());
}
Comment thread
tal5 marked this conversation as resolved.
return null;
}

Expand Down Expand Up @@ -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
Expand Down
Loading