Skip to content

Conversation

@MC-Samuel
Copy link
Contributor

@MC-Samuel MC-Samuel commented Nov 7, 2025

Replaces #2771
Additions:

  • BlockDispenseLootScriptEvent
  • VaultChangeStateScriptEvent (Paper only)
  • VaultDisplayItemScriptEvent
  • MaterialTag.ominous for when a trial spawner or vault should be set to ominous/hard mode.
    Updates:
  • Alphabetized a couple events in the Spigot script registry
  • Modernized MaterialTag.mode and added trial spawners and vaults to it

Some of this was copied from @MrMaleficus's earlier PR, so credit to them for the events.

//
// @Location true
//
// @Triggers when a vault block state changes
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be block's or block changes state.
Also . at the end.

public BlockDispenseLootScriptEvent() {
registerCouldMatcher("loot dispenses from <block>");
this.<BlockDispenseLootScriptEvent, ListTag>registerDetermination(null, ListTag.class, (evt, context, input) -> {
List<ItemStack> items = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick, but can initialize to input.size().

@Override
public ObjectTag getContext(String name) {
return switch (name) {
case "item" -> item;
Copy link
Member

Choose a reason for hiding this comment

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

This has the same issue with the context potentially becoming outdated due to another plugin accessing it (e.g. if you - wait a bit in a script and then read it) - need to dynamically get the item here, but can keep the field for matches optimization.


public BlockDispenseLootScriptEvent() {
registerCouldMatcher("loot dispenses from <block>");
this.<BlockDispenseLootScriptEvent, ListTag>registerDetermination(null, ListTag.class, (evt, context, input) -> {
Copy link
Member

Choose a reason for hiding this comment

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

Just in general, prefixed determinations (to match their context counterparts) are usually preferred as they're easier to understand in scripts & look cleaner if the event ever gets more than one determination.

|| data instanceof Tripwire
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && (data instanceof SculkCatalyst
|| data instanceof SculkShrieker));
|| data instanceof SculkShrieker))
Copy link
Member

Choose a reason for hiding this comment

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

Double space.

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);
Copy link
Member

Choose a reason for hiding this comment

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

Can use the enum constructor for these

//
// @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
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

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class VaultChangeStateScriptEvent extends BukkitScriptEvent implements Listener {
Copy link
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.

if (!runInCheck(path, location)) {
return false;
}
if (!path.tryArgObject(2, new ItemTag(event.getDisplayItem()))) {
Copy link
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).

Comment on lines 36 to 38
this.<VaultDisplayItemScriptEvent, ItemTag>registerDetermination(null, ItemTag.class, (evt, context, input) -> {
evt.event.setDisplayItem(input.getItemStack());
});
Copy link
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.

// @Triggers when a block dispenses loot containing multiple items.
//
// @Context
// <context.loot> returns a ListTag(ItemTag) of outcome items.
Copy link
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.

import java.util.ArrayList;
import java.util.List;

public class BlockDispenseLootScriptEvent extends BukkitScriptEvent implements Listener {
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants