Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 'on tnt primes' event, paper only
- Loading branch information
1 parent
ab0d5c5
commit af712e9
Showing
3 changed files
with
93 additions
and
18 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
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
89 changes: 89 additions & 0 deletions
89
paper/src/main/java/com/denizenscript/denizen/paper/events/TNTPrimesScriptEvent.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,89 @@ | ||
package com.denizenscript.denizen.paper.events; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.objects.LocationTag; | ||
import com.denizenscript.denizen.objects.PlayerTag; | ||
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.scripts.ScriptEntryData; | ||
import com.destroystokyo.paper.event.block.TNTPrimeEvent; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
public class TNTPrimesScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// tnt primes | ||
// | ||
// @Regex ^on tnt primes$ | ||
// | ||
// @Switch in <area> | ||
// | ||
// @Plugin Paper | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when TNT is activated and will soon explode. | ||
// | ||
// @Context | ||
// <context.entity> returns the entity that primed the TNT, if any. | ||
// <context.location> returns the location of the TNT block being primed. | ||
// <context.reason> returns the reason the TNT was primed. Refer to <@link url https://papermc.io/javadocs/paper/com/destroystokyo/paper/event/block/TNTPrimeEvent.PrimeReason.html> | ||
// --> | ||
|
||
public TNTPrimesScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static TNTPrimesScriptEvent instance; | ||
public TNTPrimeEvent event; | ||
public LocationTag location; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptPath path) { | ||
return path.eventLower.startsWith("tnt primes"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
if (!runInCheck(path, location)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "TNTPrimes"; | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData(event.getPrimerEntity() instanceof Player ? new PlayerTag((Player) event.getPrimerEntity()) : null, null); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
if (name.equals("entity") && event.getPrimerEntity() != null) { | ||
return new EntityTag(event.getPrimerEntity()); | ||
} | ||
else if (name.equals("location")) { | ||
return location; | ||
} | ||
else if (name.equals("reason")) { | ||
return new ElementTag(event.getReason().name()); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void tntPrimeEvent(TNTPrimeEvent event) { | ||
this.event = event; | ||
location = new LocationTag(event.getBlock().getLocation()); | ||
fire(event); | ||
} | ||
} |