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 5ec5022a9f..70a0ff03b4 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/ScriptEventRegistry.java @@ -89,6 +89,7 @@ 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); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/block/BrewingStartsScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/block/BrewingStartsScriptEvent.java new file mode 100644 index 0000000000..9e428d20e9 --- /dev/null +++ b/plugin/src/main/java/com/denizenscript/denizen/events/block/BrewingStartsScriptEvent.java @@ -0,0 +1,64 @@ +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 com.denizenscript.denizencore.objects.core.DurationTag; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BrewingStartEvent; + +public class BrewingStartsScriptEvent extends BukkitScriptEvent implements Listener { + + // <--[event] + // @Events + // brewing starts + // + // @Group Block + // + // @Location true + // + // @Triggers when a brewing stand starts brewing a potion. + // + // @Context + // returns an ItemTag of the used ingredient to brew potions. + // returns a LocationTag of the brewing stand's location. + // returns a DurationTag of the total time it will take to brew the potion. + // + // @Determine + // "BREW_TIME:DurationTag" to set the total time for the potion being brewed. + // + // --> + + public BrewingStartsScriptEvent() { + registerCouldMatcher("brewing starts"); + this.registerDetermination("brew_time", DurationTag.class, (evt, context, time) -> evt.event.setTotalBrewTime(time.getTicksAsInt())); + } + + public BrewingStartEvent event; + + @Override + public boolean matches(ScriptPath path) { + if (!runInCheck(path, event.getBlock().getLocation())) { + return false; + } + return super.matches(path); + } + + @Override + public ObjectTag getContext(String name) { + return switch (name) { + case "item" -> new ItemTag(event.getSource()); + case "location" -> new LocationTag(event.getBlock().getLocation()); + case "brew_time" -> new DurationTag((long) event.getTotalBrewTime()); + default -> super.getContext(name); + }; + } + + @EventHandler + public void onBrewingStart(BrewingStartEvent event) { + this.event = event; + fire(event); + } +}