diff --git a/src/main/java/com/fortlisa/mythicsk/MythicSk.java b/src/main/java/com/fortlisa/mythicsk/MythicSk.java index c8fb4a3..224177e 100644 --- a/src/main/java/com/fortlisa/mythicsk/MythicSk.java +++ b/src/main/java/com/fortlisa/mythicsk/MythicSk.java @@ -3,9 +3,6 @@ import ch.njol.skript.Skript; import ch.njol.skript.SkriptAddon; import com.fortlisa.mythicsk.api.MythicListener; -import com.fortlisa.mythicsk.skript.skillMetadata.types.Types; -import io.lumine.mythic.bukkit.events.MythicMechanicLoadEvent; -import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; diff --git a/src/main/java/com/fortlisa/mythicsk/api/MythicListener.java b/src/main/java/com/fortlisa/mythicsk/api/MythicListener.java index f4d4ade..352173e 100644 --- a/src/main/java/com/fortlisa/mythicsk/api/MythicListener.java +++ b/src/main/java/com/fortlisa/mythicsk/api/MythicListener.java @@ -5,16 +5,19 @@ import com.fortlisa.mythicsk.MythicSk; import com.fortlisa.mythicsk.api.mechanics.SkriptFunctionMechanic; import com.fortlisa.mythicsk.api.targets.SkriptFunctionEntityTargeter; +import com.fortlisa.mythicsk.api.events.MythicMobSpawnEvent; import io.lumine.mythic.api.config.MythicLineConfig; -import io.lumine.mythic.api.skills.SkillManager; import io.lumine.mythic.bukkit.MythicBukkit; import io.lumine.mythic.bukkit.events.MythicMechanicLoadEvent; import io.lumine.mythic.bukkit.events.MythicTargeterLoadEvent; +import io.lumine.mythic.core.mobs.ActiveMob; import io.lumine.mythic.core.skills.SkillExecutor; -import io.lumine.mythic.core.skills.targeters.LocationTargeter; +import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.scheduler.BukkitRunnable; public class MythicListener implements Listener { public static void register() { @@ -25,6 +28,27 @@ public MythicListener() { MythicSk.instance.getServer().getPluginManager().registerEvents(this, MythicSk.instance); } + @EventHandler + public void onCreatureSpawnEvent(CreatureSpawnEvent e) { + if (e.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CUSTOM) && !e.isCancelled()) { + Entity bukkitEntity = e.getEntity(); + new BukkitRunnable() { + @Override + public void run() { + if (!(MythicBukkit.inst().getAPIHelper().isMythicMob(bukkitEntity))) return; + ActiveMob activeMob = MythicBukkit.inst().getAPIHelper().getMythicMobInstance(bukkitEntity); + //TODO : implement logic related to spawner +// if (activeMob.getSpawner()!=null) { +// mmMythicSpawnerSpawnEvent e = new mmMythicSpawnerSpawnEvent(am.getSpawner(), am); +// Bukkit.getServer().getPluginManager().callEvent(e); +// } + MythicMobSpawnEvent e = new MythicMobSpawnEvent(activeMob); + Bukkit.getServer().getPluginManager().callEvent(e); + } + }.runTaskLater(MythicSk.instance, 1); + } + } + @EventHandler public void onMythicMobsCustomMechanicsLoad(MythicMechanicLoadEvent e) { switch(e.getMechanicName().toLowerCase()) { diff --git a/src/main/java/com/fortlisa/mythicsk/api/events/MythicMobSpawnEvent.java b/src/main/java/com/fortlisa/mythicsk/api/events/MythicMobSpawnEvent.java new file mode 100644 index 0000000..63ab23a --- /dev/null +++ b/src/main/java/com/fortlisa/mythicsk/api/events/MythicMobSpawnEvent.java @@ -0,0 +1,33 @@ +package com.fortlisa.mythicsk.api.events; + +import io.lumine.mythic.core.mobs.ActiveMob; +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class MythicMobSpawnEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + private ActiveMob activeMob; + + public MythicMobSpawnEvent(ActiveMob activeMob) { + this.activeMob = activeMob; + } + + public ActiveMob getActiveMob() { + return this.activeMob; + } + + public Entity getEntity() { + return this.activeMob.getEntity().getBukkitEntity(); + } + + @Override + public @NotNull HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/com/fortlisa/mythicsk/api/mechanics/SkriptFunctionMechanic.java b/src/main/java/com/fortlisa/mythicsk/api/mechanics/SkriptFunctionMechanic.java index 015722a..7bf9c0f 100644 --- a/src/main/java/com/fortlisa/mythicsk/api/mechanics/SkriptFunctionMechanic.java +++ b/src/main/java/com/fortlisa/mythicsk/api/mechanics/SkriptFunctionMechanic.java @@ -17,8 +17,6 @@ public class SkriptFunctionMechanic extends SkillMechanic implements INoTargetSk private static final int LOCATION_POS=2; Function function; String name; - Object[][] parameters; - int dataPos,locationPos,entityPos; public SkriptFunctionMechanic(SkillExecutor se, String skill, MythicLineConfig mlc) { super(se, skill, mlc); @@ -26,24 +24,7 @@ public SkriptFunctionMechanic(SkillExecutor se, String skill, MythicLineConfig m this.name=mlc.getString("name",""); this.function=Functions.getFunction(name); - if(function!=null) { -// parameters = new Object[function.getParameters().length][]; -// for (int i = 0; i < function.getParameters().length; i++) { -// String type = function.getParameter(i).getType().getCodeName(); -// switch (type) { -// case "skilldata": -// dataPos = i; -// break; -// case "location": -// locationPos = i; -// break; -// case "entity": -// entityPos = i; -// break; -// } -// } - } - else { + if(function==null) { Bukkit.getLogger().warning("Cant find function "+name); } } @@ -51,11 +32,9 @@ public SkriptFunctionMechanic(SkillExecutor se, String skill, MythicLineConfig m @Override public SkillResult cast(SkillMetadata skillMetadata) { Bukkit.getLogger().info("entityTargets"+skillMetadata.getEntityTargets().toString()); -// Bukkit.getLogger().info(parameters.toString()); this.function.execute(new Object[][] { {skillMetadata}, }); - return SkillResult.SUCCESS; } diff --git a/src/main/java/com/fortlisa/mythicsk/api/targets/SkriptFunctionEntityTargeter.java b/src/main/java/com/fortlisa/mythicsk/api/targets/SkriptFunctionEntityTargeter.java index 0bd456a..857bac7 100644 --- a/src/main/java/com/fortlisa/mythicsk/api/targets/SkriptFunctionEntityTargeter.java +++ b/src/main/java/com/fortlisa/mythicsk/api/targets/SkriptFunctionEntityTargeter.java @@ -1,7 +1,6 @@ package com.fortlisa.mythicsk.api.targets; import ch.njol.skript.lang.function.Function; -import ch.njol.skript.util.Task; import com.fortlisa.mythicsk.MythicSk; import io.lumine.mythic.api.adapters.AbstractEntity; import io.lumine.mythic.api.config.MythicLineConfig; @@ -11,18 +10,11 @@ import io.lumine.mythic.core.skills.targeters.IEntitySelector; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; -import org.bukkit.scheduler.BukkitScheduler; - -import java.util.Arrays; -import java.util.Collection; import java.util.HashSet; import java.util.concurrent.ExecutionException; public class SkriptFunctionEntityTargeter extends IEntitySelector { Function function; - Object[][]parameters; - - private static BukkitScheduler scheduler; public SkriptFunctionEntityTargeter(SkillExecutor se, MythicLineConfig mlc, Function skriptFunction) { super(se, mlc); @@ -41,12 +33,9 @@ public HashSet getEntities(SkillMetadata skillMetadata) { }); if(result!=null) { for(int i=0;i getEntities(SkillMetadata skillMetadata) { } catch (ExecutionException e) { throw new RuntimeException(e); } - -// Task.callSync(() -> function.execute(new Object[][] { -// {skillMetadata}, -// }), MythicSk.instance); - -// Object[] result = -// Task.callSync(() -> function.execute(new Object[][] { -// {skillMetadata}, -// })); - -// HashSet targets = new HashSet<>(); -// if(result!=null) { -// for(int i=0;i(ActiveMob.class, "activemob") + .user("activemob") + .name("activemob") + .defaultExpression(new EventValueExpression<>(ActiveMob.class)) + .parser(new Parser() { + @Override + public String toString(ActiveMob activeMob, int i) { + return activeMob.getType().getInternalName(); + } + + @Override + public String toVariableNameString(ActiveMob activeMob) { + return activeMob.getUniqueId().toString(); + } + + @Override + public ActiveMob parse(String string, ParseContext context) { + return null; + } + }) + ); } } diff --git a/src/main/java/com/fortlisa/mythicsk/skript/events/SimpleEvents.java b/src/main/java/com/fortlisa/mythicsk/skript/events/SimpleEvents.java new file mode 100644 index 0000000..5a6b072 --- /dev/null +++ b/src/main/java/com/fortlisa/mythicsk/skript/events/SimpleEvents.java @@ -0,0 +1,34 @@ +package com.fortlisa.mythicsk.skript.events; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.util.SimpleEvent; +import ch.njol.skript.registrations.EventValues; +import ch.njol.skript.util.Getter; +import com.fortlisa.mythicsk.api.events.MythicMobSpawnEvent; +import io.lumine.mythic.core.mobs.ActiveMob; +import org.bukkit.entity.Entity; + +import javax.annotation.Nullable; + +public class SimpleEvents { + static { + //MythicMob spawn event + Skript.registerEvent("MythicMob spawn", SimpleEvent.class, MythicMobSpawnEvent.class, + "mythicmob spawn") + .description("Called when a mythicMob spawn.") + .examples(""); + EventValues.registerEventValue(MythicMobSpawnEvent.class, ActiveMob.class, new Getter() { + @Override + public @Nullable ActiveMob get(MythicMobSpawnEvent event) { + return event.getActiveMob(); + } + }, 0); + + EventValues.registerEventValue(MythicMobSpawnEvent.class, Entity.class, new Getter() { + @Override + @Nullable + public Entity get(MythicMobSpawnEvent e) { + return e.getEntity(); + }}, 0); + } +}