Skip to content

Commit

Permalink
Adds the SpongeAbsorbEvent (#2490)
Browse files Browse the repository at this point in the history
* Adds the SpongeAbsorbEvent

* Make Alphabetical

* Import Cleanup

* Remove Variables

* Add Working RateLimit

Rate Limiting the script does not work, but Rate Limiting the sponge itself does

* ListTag(LocationTag)

* Add a newline to the end of the file

* Use convertor constructor

* Correct ListTag Constructor

* Correct NewLine
  • Loading branch information
FireML committed Jul 1, 2023
1 parent 5af07fe commit 18b7270
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Expand Up @@ -86,6 +86,7 @@ public static void registerMainEvents() {
ScriptEvent.registerScriptEvent(PistonExtendsScriptEvent.class);
ScriptEvent.registerScriptEvent(PistonRetractsScriptEvent.class);
ScriptEvent.registerScriptEvent(RedstoneScriptEvent.class);
ScriptEvent.registerScriptEvent(SpongeAbsorbsScriptEvent.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
ScriptEvent.registerScriptEvent(TNTPrimesScriptEvent.class);
}
Expand Down
@@ -0,0 +1,53 @@
package com.denizenscript.denizen.events.block;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SpongeAbsorbEvent;

public class SpongeAbsorbsScriptEvent extends BukkitScriptEvent implements Listener {

// <--[event]
// @Events
// sponge absorbs
//
// @Location true
//
// @Group Block
//
// @Warning this event may in some cases double-fire, requiring usage of the 'ratelimit' command (like 'ratelimit <context.location> 1t') to prevent doubling actions.
//
// @Cancellable true
//
// @Triggers when Sponge absorbs water.
//
// @Context
// <context.location> returns the location of the Sponge.
// <context.blocks> returns a ListTag(LocationTag) of blocks that are being removed.
//
// -->

public SpongeAbsorbsScriptEvent() {
registerCouldMatcher("sponge absorbs");
}

public SpongeAbsorbEvent event;

@Override
public ObjectTag getContext(String name) {
return switch (name) {
case "location" -> new LocationTag(event.getBlock().getLocation());
case "blocks" -> new ListTag(event.getBlocks(), block -> new LocationTag(block.getLocation()));
default -> super.getContext(name);
};
}

@EventHandler
public void onSpongeAbsorbEvent(SpongeAbsorbEvent event) {
this.event = event;
fire(event);
}
}

0 comments on commit 18b7270

Please sign in to comment.