Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
plugin/src/main/java/com/denizenscript/denizen/events/block/SpongeAbsorbsScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |