Skip to content

Commit

Permalink
Adds MythicMobs Despawn Event (#403)
Browse files Browse the repository at this point in the history
* 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
heypr committed Mar 20, 2023
1 parent 52f75a0 commit 949deae
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -222,7 +222,7 @@
<dependency>
<groupId>io.lumine.xikage</groupId>
<artifactId>mythicmobs</artifactId>
<version>5.0.2</version>
<version>5.2.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MythicMobs.jar</systemPath>
</dependency>
Expand Down
Expand Up @@ -16,6 +16,7 @@
import com.denizenscript.depenizen.bukkit.commands.mythicmobs.MythicSpawnCommand;
import com.denizenscript.depenizen.bukkit.commands.mythicmobs.MythicThreatCommand;
import com.denizenscript.depenizen.bukkit.events.mythicmobs.MythicMobsDeathEvent;
import com.denizenscript.depenizen.bukkit.events.mythicmobs.MythicMobsDespawnEvent;
import com.denizenscript.depenizen.bukkit.events.mythicmobs.MythicMobsSpawnEvent;
import com.denizenscript.depenizen.bukkit.objects.mythicmobs.MythicMobsMobTag;
import com.denizenscript.depenizen.bukkit.objects.mythicmobs.MythicSpawnerTag;
Expand Down Expand Up @@ -49,6 +50,7 @@ public void init() {
PropertyParser.registerProperty(MythicMobsPlayerProperties.class, PlayerTag.class);
ScriptEvent.registerScriptEvent(MythicMobsDeathEvent.class);
ScriptEvent.registerScriptEvent(MythicMobsSpawnEvent.class);
ScriptEvent.registerScriptEvent(MythicMobsDespawnEvent.class);
DenizenCore.commandRegistry.registerCommand(MythicSpawnCommand.class);
DenizenCore.commandRegistry.registerCommand(MythicThreatCommand.class);
DenizenCore.commandRegistry.registerCommand(MythicSignalCommand.class);
Expand Down
@@ -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());
}
}

0 comments on commit 949deae

Please sign in to comment.