Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.denizenscript.denizen.paper.events;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
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
// <context.location> returns the LocationTag of the vault block.
// <context.current_state> returns the ElementTag of the vault state on change.
// <context.new_state> returns the ElementTag of the new vault state.
//
// @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 ObjectTag getContext(String name) {
return switch (name) {
case "current_state" -> new ElementTag(event.getCurrentState().toString().toLowerCase());
case "new_state" -> new ElementTag(event.getNewState().toString().toLowerCase());
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 @@ -17,6 +17,7 @@
import com.denizenscript.denizen.utilities.depends.Depends;
import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.events.ScriptEventCouldMatcher;
import org.bukkit.event.entity.TrialSpawnerSpawnEvent;

import java.util.Arrays;

Expand Down Expand Up @@ -100,6 +101,8 @@ public static void registerMainEvents() {
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) {
ScriptEvent.registerScriptEvent(CrafterCraftsScriptEvent.class);
ScriptEvent.registerScriptEvent(EntityTrialSpawnerSpawnScriptEvent.class);
ScriptEvent.registerScriptEvent(VaultDisplayItemScriptEvent.class);
}

// Entity events
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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
// "ITEM:<ItemTag>" to set the item being displayed.
//
// -->

public VaultDisplayItemScriptEvent() {
registerCouldMatcher("vault displays <item>");
this.<VaultDisplayItemScriptEvent, ItemTag>registerDetermination("item", ItemTag.class, (evt, context, item) -> {
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" -> new ItemTag(event.getDisplayItem());
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.denizenscript.denizen.events.entity;

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.TrialSpawnerSpawnEvent;

public class EntityTrialSpawnerSpawnScriptEvent extends BukkitScriptEvent implements Listener {

// <--[event]
// @Events
// trial_spawner spawns <entity>
//
// @Group Entity
//
// @Location true
//
// @Cancellable true
//
// @Triggers when an entity spawns from a trial spawner.
//
// @Switch spawner:<location> to only process the event if the trial spawner's location matches.
//
// @Context
// <context.entity> returns the EntityTag that spawned.
// <context.location> returns the LocationTag the entity will spawn at.
// <context.spawner_location> returns the LocationTag of the trial spawner.
//
// -->

public EntityTrialSpawnerSpawnScriptEvent() {
registerCouldMatcher("trial_spawner spawns <entity>");
registerSwitches("spawner");
}

private EntityTag entity;
private LocationTag location;
private LocationTag trialSpawnerLocation;

@Override
public boolean matches(ScriptPath path) {
if (!path.tryArgObject(2, entity)) {
return false;
}
if (!path.tryObjectSwitch("spawner", trialSpawnerLocation)) {
return false;
}
if (!runInCheck(path, location)) {
return false;
}
return super.matches(path);
}

@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(entity);
}

@Override
public ObjectTag getContext(String name) {
return switch (name) {
case "entity" -> entity;
case "location" -> location;
case "spawner_location" -> trialSpawnerLocation;
default -> super.getContext(name);
};
}

@EventHandler
public void onTrialSpawnerSpawn(TrialSpawnerSpawnEvent event) {
Entity entity = event.getEntity();
this.entity = new EntityTag(entity);
location = new LocationTag(event.getLocation());
trialSpawnerLocation = new LocationTag(event.getTrialSpawner().getLocation());
EntityTag.rememberEntity(entity);
fire(event);
EntityTag.forgetEntity(entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,19 @@ 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);
PropertyParser.registerProperty(MaterialSides.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSnowable.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSwitchable.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialUnstable.class, MaterialTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21)) {
PropertyParser.registerProperty(MaterialVaultState.class, MaterialTag.class);
}
PropertyParser.registerProperty(MaterialWaterlogged.class, MaterialTag.class);

// register core TradeTag properties
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.denizenscript.denizen.objects.properties.material;

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 org.bukkit.block.data.type.TrialSpawner;
import org.bukkit.block.data.type.Vault;

public class MaterialOminous implements Property {
Copy link
Contributor

Choose a reason for hiding this comment

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

should use the new format, which extends MaterialProperty, example commit 0559148


public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& (((MaterialTag) material).getModernData() instanceof Vault
|| ((MaterialTag) material).getModernData() instanceof TrialSpawner);
}

public static MaterialOminous getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
} else {
return new MaterialOminous((MaterialTag) _material);
}
}

public static final String[] handledMechs = new String[]{
"ominous"
};

public MaterialOminous(MaterialTag _material) {
material = _material;
}

MaterialTag material;

public static void register() {

// <--[tag]
// @attribute <MaterialTag.is_ominous>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.ominous
// @group properties
// @description
// Returns whether the block is ominous or not.
// Currently supports Vault and Trial Spawner blocks.
// -->
PropertyParser.registerStaticTag(MaterialOminous.class, ElementTag.class, "is_ominous", (attribute, material) -> {
return new ElementTag(material.getOminous());
});
}

public boolean getOminous() {
if (material.getModernData() instanceof Vault) {
return ((Vault) material.getModernData()).isOminous();
} else if (material.getModernData() instanceof TrialSpawner) {
return ((TrialSpawner) material.getModernData()).isOminous();
}
return false;
}

public void setOminous(boolean ominous) {
if (material.getModernData() instanceof Vault vault) {
vault.setOminous(ominous);
} else if (material.getModernData() instanceof TrialSpawner spawner) {
spawner.setOminous(ominous);
}
}

@Override
public String getPropertyString() {
return String.valueOf(getOminous());
}

@Override
public String getPropertyId() {
return "ominous";
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name ominous
// @input ElementTag(Boolean)
// @description
// Sets the ominousness of the block (trial spawner or vault).
// @tags
// <MaterialTag.is_ominous>
// -->
if (mechanism.matches("ominous") && mechanism.requireBoolean()) {
setOminous(mechanism.getValue().asBoolean());
}
}
}
Loading