Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
entity removed from world paper event
and replace despawn event trigger with a modern one
- Loading branch information
1 parent
c41d90d
commit ec01855
Showing
3 changed files
with
72 additions
and
10 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
68 changes: 68 additions & 0 deletions
68
...rc/main/java/com/denizenscript/denizen/paper/events/EntityRemoveFromWorldScriptEvent.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,68 @@ | ||
package com.denizenscript.denizen.paper.events; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.scripts.ScriptEntryData; | ||
import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
public class EntityRemoveFromWorldScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// <entity> removed from world | ||
// | ||
// @Plugin Paper | ||
// | ||
// @Group Paper | ||
// | ||
// @Location true | ||
// | ||
// @Triggers any time an entity is removed from the world for any reason, including chunks unloading. | ||
// | ||
// @Context | ||
// <context.entity> returns the EntityTag that will be removed. Note that this entity will not necessarily be fully spawned at time of firing, so usage will be limited. | ||
// | ||
// --> | ||
|
||
public EntityRemoveFromWorldScriptEvent() { | ||
registerCouldMatcher("<entity> removed from world"); | ||
} | ||
|
||
public EntityTag entity; | ||
public EntityRemoveFromWorldEvent event; | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
if (!path.tryArgObject(0, entity)) { | ||
return false; | ||
} | ||
if (!runInCheck(path, entity.getLocation())) { | ||
return false; | ||
} | ||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData(null, null); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
return switch (name) { | ||
case "entity" -> entity; | ||
default -> super.getContext(name); | ||
}; | ||
} | ||
|
||
@EventHandler | ||
public void onPreCreatureSpawn(EntityRemoveFromWorldEvent event) { | ||
this.entity = new EntityTag(event.getEntity()); | ||
this.event = event; | ||
fire(event); | ||
} | ||
} |
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