Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds MythicMobs Despawn Event (#403)
* Added MM Despawn Event + Updated pom + Added the MythicMobs Despawn Event * Updated MM Dependency Updated MM dependency from 5.0.2 --> 5.2.1 * Reverted pom change * Removed extra parentheses * Removed instance field.
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
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
64 changes: 64 additions & 0 deletions
64
...ain/java/com/denizenscript/depenizen/bukkit/events/mythicmobs/MythicMobsDespawnEvent.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,64 @@ | ||
package com.denizenscript.depenizen.bukkit.events.mythicmobs; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.depenizen.bukkit.objects.mythicmobs.MythicMobsMobTag; | ||
import io.lumine.mythic.bukkit.events.MythicMobDespawnEvent; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
|
||
public class MythicMobsDespawnEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// mythicmob <'mob'> despawns | ||
// | ||
// @Location true | ||
// | ||
// @Triggers when a MythicMob despawns. | ||
// | ||
// @Context | ||
// <context.mob> Returns the MythicMob that is despawning. | ||
// <context.entity> Returns the EntityTag for the MythicMob. | ||
// | ||
// @Plugin Depenizen, MythicMobs | ||
// | ||
// @Group Depenizen | ||
// | ||
// --> | ||
|
||
public MythicMobsDespawnEvent() { | ||
registerCouldMatcher("mythicmob <'mob'> despawns"); | ||
} | ||
|
||
public MythicMobDespawnEvent event; | ||
public MythicMobsMobTag mythicmob; | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
String mob = path.eventArgLowerAt(1); | ||
if (!mob.equals("mob") && !runGenericCheck(mob, mythicmob.getMobType().getInternalName())) { | ||
return false; | ||
} | ||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
return switch (name) { | ||
case "mob" -> mythicmob; | ||
case "entity" -> new EntityTag(event.getEntity()); | ||
default -> super.getContext(name); | ||
}; | ||
} | ||
@EventHandler | ||
public void onMythicMobDespawns(MythicMobDespawnEvent event) { | ||
mythicmob = new MythicMobsMobTag(event.getMob()); | ||
this.event = event; | ||
EntityTag.rememberEntity(event.getEntity()); | ||
fire(event); | ||
EntityTag.forgetEntity(event.getEntity()); | ||
} | ||
} |