diff --git a/src/me/TheBukor/SkStuff/SkStuff.java b/src/me/TheBukor/SkStuff/SkStuff.java index f9fbd66..a6146af 100644 --- a/src/me/TheBukor/SkStuff/SkStuff.java +++ b/src/me/TheBukor/SkStuff/SkStuff.java @@ -93,8 +93,8 @@ public class SkStuff extends JavaPlugin { getLogger().info("Trying to register version specific stuff..."); Skript.registerEffect(EffClearPathGoals.class, "(clear|delete) [all] pathfind[er] goals (of|from) %livingentity%"); - Skript.registerEffect(EffRemovePathGoal.class, "remove pathfind[er] goal (0¦(avoid|run away from) %entitydata%,[ ]radius %number%,[ ][at] speed %number%,[ ][at] speed if close %number%|1¦break door[s]|2¦breed,[ ][move to[wards] lover at] speed %number%|3¦eat grass|4¦(flee from the sun|seek shad(e|ow)),[ ][at] speed %number%|5¦float (in[side]|on) water|6¦follow (owner|tamer),[ ][at] speed %number%|7¦follow (adult[s]|parent[s]),[ ][at] speed %number%|8¦(fight back|react to|target) (damager|attacker) [[of] type %entitydata%]|9¦o(c|z)elot jump on blocks,[ ][at] speed %number%|10¦leap at target height %number%|11¦look at %entitydata%,[ ]radius %number%|12¦melee attack %entitydata%,[ ][at] speed %number%|13¦move to[wards] target,[ ][at] speed %number%,[ ]radius %number%|14¦attack nearest entity [of] type %entitydata%|15¦o(c|z)elot attack [chicken]|16¦open door[s]|17¦(panic|flee),[ ][at] speed %number%|18¦look around randomly|19¦(walk around randomly|wander),[ ][at] speed %number%,[ ][with] %-timespan% between mov(e[ment]|ing)|20¦sit|21¦[creeper] swell) from %livingentity%"); - Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %entitydata%,[ ]radius %number%,[ ][at] speed %number%,[ ][at] speed if close %number%|1¦break door[s]|2¦breed,[ ][move to[wards] lover at] speed %number%|3¦eat grass|4¦(flee from the sun|seek shad(e|ow)),[ ][at] speed %number%|5¦float (in[side]|on) water|6¦follow (owner|tamer),[ ][at] speed %number%|7¦follow (adult[s]|parent[s]),[ ][at] speed %number%|8¦(fight back|react to|target) (damager|attacker) [[of] type %entitydata%]|9¦o(c|z)elot jump on blocks,[ ][at] speed %number%|10¦leap at target height %number%|11¦look at %entitydata%,[ ]radius %number%|12¦melee attack %entitydata%,[ ][at] speed %number%|13¦move to[wards] target,[ ][at] speed %number%,[ ]radius %number%|14¦attack nearest entity [of] type %entitydata%|15¦o(c|z)elot attack [chicken]|16¦open door[s]|17¦(panic|flee),[ ][at] speed %number%|18¦look around randomly|19¦(walk around randomly|wander),[ ][at] speed %number%,[ ][with] min[imum] [of] %-timespan% between mov(e[ment][s]|ing)|20¦sit|21¦[creeper] swell) to %livingentity%"); + Skript.registerEffect(EffRemovePathGoal.class, "remove pathfind[er] goal (0¦(avoid|run away from) entit(y|ies)|1¦break door[s]|2¦breed|3¦eat grass|4¦(flee from the sun|seek shad(e|ow))|5¦float (in[side]|on) water|6¦follow (owner|tamer)|7¦follow (adult|parent)[s]|8¦(fight back|react to|target) (damager|attacker)|9¦o(c|z)elot jump on blocks|10¦leap at target|11¦look at entit(y|ies)|12¦melee attack entit(y|ies)|13¦move to[wards] target|14¦attack nearest entity|15¦o(c|z)elot attack [chicken[s]]|16¦open door[s]|17¦(panic|flee)|18¦look around randomly|19¦(walk around randomly|wander)|20¦sit|21¦[creeper] swell) from %livingentity%"); + Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %entitydata%,[ ]radius %number%,[ ][at] speed %number%,[ ][at] speed if close %number%|1¦break door[s]|2¦breed,[ ][move to[wards] lover at] speed %number%|3¦eat grass|4¦(flee from the sun|seek shad(e|ow)),[ ][at] speed %number%|5¦float (in[side]|on) water|6¦follow (owner|tamer),[ ][at] speed %number%|7¦follow (adult|parent)[s],[ ][at] speed %number%|8¦(fight back|react to|target) (damager|attacker) [[of] type] %entitydata%|9¦o(c|z)elot jump on blocks,[ ][at] speed %number%|10¦leap at target [with [leap]] height %number%|11¦look at %entitydata%,[ ]radius %number%|12¦melee attack %entitydata%,[ ][at] speed %number%|13¦move to[wards] target,[ ][at] speed %number%,[ ]radius %number%|14¦attack nearest [entity [of] type] %entitydata%|15¦o(c|z)elot attack [chicken]|16¦open door[s]|17¦(panic|flee),[ ][at] speed %number%|18¦look around randomly|19¦(walk around randomly|wander),[ ][at] speed %number%,[ ][with] min[imum] [of] %-timespan% between mov(e[ment][s]|ing)|20¦sit|21¦[creeper] swell) to %livingentity%"); Skript.registerEffect(EffMakeJump.class, "make %livingentity% jump"); Skript.registerExpression(ExprNBTOf.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]"); Skript.registerExpression(ExprItemNBT.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); diff --git a/src/me/TheBukor/SkStuff/effects/EffRemovePathGoal.java b/src/me/TheBukor/SkStuff/effects/EffRemovePathGoal.java index 7f2a6ae..bea9679 100644 --- a/src/me/TheBukor/SkStuff/effects/EffRemovePathGoal.java +++ b/src/me/TheBukor/SkStuff/effects/EffRemovePathGoal.java @@ -5,42 +5,17 @@ import java.util.List; import javax.annotation.Nullable; -import org.bukkit.Bukkit; -import org.bukkit.entity.Creeper; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Event; -import ch.njol.skript.entity.EntityData; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; -import ch.njol.skript.util.Timespan; import ch.njol.util.Kleenean; import me.TheBukor.SkStuff.util.ReflectionUtils; public class EffRemovePathGoal extends Effect { - private Expression> typeToAvoid; - private Expression avoidRadius; - private Expression avoidSpeed1; - private Expression avoidSpeed2; - private Expression breedSpeed; - private Expression fleeSunSpeed; - private Expression followOwnerSpeed; - private Expression followAdultsSpeed; - private Expression> typesToFightBack; - private Expression jumpOnBlockSpeed; - private Expression leapHeight; - private Expression> lookType; - private Expression lookRadius; - private Expression> meleeTarget; - private Expression meleeSpeed; - private Expression moveTargetSpeed; - private Expression moveTargetRadius; - private Expression> nearTarget; - private Expression panicSpeed; - private Expression randomWalkSpeed; - private Expression randomWalkInterval; private Expression entity; private int mark; @@ -69,54 +44,14 @@ public class EffRemovePathGoal extends Effect { private Class goalSit = ReflectionUtils.getNMSClass("PathfinderGoalSit", false); private Class goalSwell = ReflectionUtils.getNMSClass("PathfinderGoalSwell", false); - private Class entAnimal = ReflectionUtils.getNMSClass("EntityAnimal", false); - private Class entCreature = ReflectionUtils.getNMSClass("EntityCreature", false); private Class entInsent = ReflectionUtils.getNMSClass("EntityInsentient", false); - private Class entOcelot = ReflectionUtils.getNMSClass("EntityOcelot", false); - private Class entTameable = ReflectionUtils.getNMSClass("EntityTameableAnimal", false); private Class craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity"); @SuppressWarnings("unchecked") @Override public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { mark = result.mark; - if (mark == 0) { - typeToAvoid = (Expression>) expr[0]; - avoidRadius = (Expression) expr[1]; - avoidSpeed1 = (Expression) expr[2]; - avoidSpeed2 = (Expression) expr[3]; - } else if (mark == 2) { - breedSpeed = (Expression) expr[4]; - } else if (mark == 4) { - fleeSunSpeed = (Expression) expr[5]; - } else if (mark == 6) { - followOwnerSpeed = (Expression) expr[6]; - } else if (mark == 7) { - followAdultsSpeed = (Expression) expr[7]; - } else if (mark == 8) { - typesToFightBack = (Expression>) expr[8]; - } else if (mark == 9) { - jumpOnBlockSpeed = (Expression) expr[9]; - } else if (mark == 10) { - leapHeight = (Expression) expr[10]; - } else if (mark == 11) { - lookType = (Expression>) expr[11]; - lookRadius = (Expression) expr[12]; - } else if (mark == 12) { - meleeTarget = (Expression>) expr[13]; - meleeSpeed = (Expression) expr[14]; - } else if (mark == 13) { - moveTargetSpeed = (Expression) expr[15]; - moveTargetRadius = (Expression) expr[16]; - } else if (mark == 14) { - nearTarget = (Expression>) expr[17]; - } else if (mark == 17) { - panicSpeed = (Expression) expr[18]; - } else if (mark == 19) { - randomWalkSpeed = (Expression) expr[19]; - randomWalkInterval = (Expression) expr[20]; - } - entity = (Expression) expr[21]; + entity = (Expression) expr[0]; return true; } @@ -125,7 +60,7 @@ public class EffRemovePathGoal extends Effect { return "remove pathfind goal of " + entity.toString(e, false); } - @SuppressWarnings({ "unused", "deprecation" }) + @SuppressWarnings({ "unused" }) @Override protected void execute(Event e) { LivingEntity ent = entity.getSingle(e); @@ -136,160 +71,60 @@ public class EffRemovePathGoal extends Effect { Object nmsEnt = entInsent.cast(obcEnt.getClass().getMethod("getHandle").invoke(obcEnt)); Object goalSelector = ReflectionUtils.getField("goalSelector", entInsent, nmsEnt); Object targetSelector = ReflectionUtils.getField("targetSelector", entInsent, nmsEnt); - Object newGoal = null; Object toRemove = null; if (mark == 0) { - float radius = avoidRadius.getSingle(e).floatValue(); - double spd1 = avoidSpeed1.getSingle(e).doubleValue(); - double spd2 = avoidSpeed2.getSingle(e).doubleValue(); - EntityData entityData; - String exprInput = typeToAvoid.toString(e, false); - if (exprInput.startsWith("the ")) { - exprInput = exprInput.substring(4); - } - entityData = EntityData.parseWithoutIndefiniteArticle(exprInput); - String className = entityData.getType().getSimpleName(); - if (className.equals("HumanEntity")) - className = "Human"; - className = "Entity" + className; - Class nmsClass = ReflectionUtils.getNMSClass(className, false); - if (nmsClass == null) - return; - newGoal = goalAvoid.getConstructor(entCreature, Class.class, float.class, double.class, double.class).newInstance(nmsEnt, nmsClass, radius, spd1, spd2); + toRemove = goalAvoid; } else if (mark == 1) { - newGoal = goalBreakDoor.getConstructor(entInsent).newInstance(nmsEnt); + toRemove = goalBreakDoor; } else if (mark == 2) { - double spd = breedSpeed.getSingle(e).doubleValue(); - if (!(nmsEnt.getClass().isAssignableFrom(entAnimal))) - return; - newGoal = goalBreed.getConstructor(entAnimal, double.class).newInstance(nmsEnt, spd); + toRemove = goalBreed; } else if (mark == 3) { - newGoal = goalEatGrass.getConstructor(entInsent).newInstance(nmsEnt); + toRemove = goalEatGrass; } else if (mark == 4) { - double spd = fleeSunSpeed.getSingle(e).doubleValue(); - newGoal = goalFleeSun.getConstructor(entCreature, double.class).newInstance(nmsEnt, spd); + toRemove = goalFleeSun; } else if (mark == 5) { - newGoal = goalFloat.getConstructor(entInsent).newInstance(nmsEnt); + toRemove = goalFloat; } else if (mark == 6) { - double spd = followOwnerSpeed.getSingle(e).doubleValue(); - if (!(nmsEnt.getClass().isAssignableFrom(entTameable))) - return; - newGoal = goalFollowOwner.getConstructor(entTameable, double.class, float.class, float.class).newInstance(nmsEnt, spd, 20.0F, 5.0F); + toRemove = goalFollowOwner; } else if (mark == 7) { - double spd = followAdultsSpeed.getSingle(e).doubleValue(); - if (!(nmsEnt.getClass().isAssignableFrom(entAnimal))) - return; - newGoal = goalFollowAdults.getConstructor(entAnimal, double.class).newInstance(nmsEnt, spd); + toRemove = goalFollowAdults; } else if (mark == 8) { - EntityData entityData; - String exprInput = typesToFightBack.toString(e, false); - if (exprInput.startsWith("the ")) { - exprInput = exprInput.substring(4); - } - entityData = EntityData.parseWithoutIndefiniteArticle(exprInput); - String className = entityData.getType().getSimpleName(); - if (className.equals("HumanEntity")) - className = "Human"; - className = "Entity" + className; - Class[] nmsClass = new Class[] { ReflectionUtils.getNMSClass(className, false) }; - if (nmsClass[0] == null) - return; - newGoal = goalReactAttack.getConstructor(entCreature, boolean.class, Class[].class).newInstance(nmsEnt, false, nmsClass[0]); + toRemove = goalReactAttack; } else if (mark == 9) { - double spd = jumpOnBlockSpeed.getSingle(e).doubleValue(); - if (nmsEnt.getClass() != entOcelot) - return; - newGoal = goalJumpOnBlock.getConstructor(entOcelot, double.class).newInstance(nmsEnt, spd); + toRemove = goalJumpOnBlock; } else if (mark == 10) { - float height = leapHeight.getSingle(e).floatValue(); - newGoal = goalLeapTarget.getConstructor(entInsent, float.class).newInstance(nmsEnt, height); + toRemove = goalLeapTarget; } else if (mark == 11) { - EntityData entityData; - String exprInput = lookType.toString(e, false); - if (exprInput.startsWith("the ")) { - exprInput = exprInput.substring(4); - } - entityData = EntityData.parseWithoutIndefiniteArticle(exprInput); - String className = entityData.getType().getSimpleName(); - if (className.equals("HumanEntity")) - className = "Human"; - className = "Entity" + className; - Class nmsClass = ReflectionUtils.getNMSClass(className, false); - if (nmsClass == null) - return; - float radius = lookRadius.getSingle(e).floatValue(); - newGoal = goalLookEntities.getConstructor(entInsent, Class.class, float.class).newInstance(nmsEnt, nmsClass, radius); + toRemove = goalLookEntities; } else if (mark == 12) { - EntityData entityData; - String exprInput = meleeTarget.toString(e, false); - if (exprInput.startsWith("the ")) { - exprInput = exprInput.substring(4); - } - entityData = EntityData.parseWithoutIndefiniteArticle(exprInput); - String className = entityData.getType().getSimpleName(); - if (className.equals("HumanEntity")) - className = "Human"; - className = "Entity" + className; - Class nmsClass = ReflectionUtils.getNMSClass(className, false); - if (nmsClass == null) - return; - double spd = meleeSpeed.getSingle(e).doubleValue(); - newGoal = goalMeleeAttack.getConstructor(entCreature, Class.class, double.class, boolean.class).newInstance(nmsEnt, nmsClass, spd, false); + toRemove = goalMeleeAttack; } else if (mark == 13) { - double spd = moveTargetSpeed.getSingle(e).doubleValue(); - float radius = moveTargetRadius.getSingle(e).floatValue(); - newGoal = goalGotoTarget.getConstructor(entCreature, double.class, float.class).newInstance(nmsEnt, spd, radius); + toRemove = goalGotoTarget; } else if (mark == 14) { - EntityData entityData; - String exprInput = nearTarget.toString(e, false); - if (exprInput.startsWith("the ")) { - exprInput = exprInput.substring(4); - } - entityData = EntityData.parseWithoutIndefiniteArticle(exprInput); - String className = entityData.getType().getSimpleName(); - if (className.equals("HumanEntity")) - className = "Human"; - className = "Entity" + className; - Class nmsClass = ReflectionUtils.getNMSClass(className, false); - if (nmsClass == null) - return; - newGoal = goalNearTarget.getConstructor(entCreature, Class.class, boolean.class).newInstance(nmsEnt, nmsClass, false); + toRemove = goalNearTarget; } else if (mark == 15) { - newGoal = goalOcelotAttack.getConstructor(entInsent).newInstance(nmsEnt); + toRemove = goalOcelotAttack; } else if (mark == 16) { - newGoal = goalOpenDoors.getConstructor(entInsent, boolean.class).newInstance(nmsEnt, false); + toRemove = goalOpenDoors; } else if (mark == 17) { - double spd = panicSpeed.getSingle(e).doubleValue(); - newGoal = goalPanic.getConstructor(entCreature, double.class).newInstance(nmsEnt, spd); + toRemove = goalPanic; } else if (mark == 18) { - newGoal = goalRandomLook.getConstructor(entInsent).newInstance(nmsEnt); + toRemove = goalRandomLook; } else if (mark == 19) { - double spd = randomWalkSpeed.getSingle(e).doubleValue(); - int interval = randomWalkInterval.getSingle(e).getTicks(); - newGoal = goalWander.getConstructor(entCreature, double.class, int.class).newInstance(nmsEnt, spd, interval); + toRemove = goalWander; } else if (mark == 20) { - if (!(nmsEnt.getClass().isAssignableFrom(entTameable))) { - Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a tameable animal - \u00A7e[DEBUG MESSAGE]"); - return; - } - newGoal = goalSit.getConstructor(entTameable).newInstance(nmsEnt); + toRemove = goalSit; } else if (mark == 21) { - if (!(ent instanceof Creeper)) { - Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a creeper - \u00A7e[DEBUG MESSAGE]"); - return; - } - newGoal = goalSwell.getConstructor(nmsEnt.getClass()).newInstance(nmsEnt); + toRemove = goalSwell; } Iterator goals = ((List) ReflectionUtils.getField("b", goalSelectorClass, goalSelector)).iterator(); + Iterator goalPriorities = ((List) ReflectionUtils.getField("c", goalSelectorClass, goalSelector)).iterator(); while (goals.hasNext()) { Object o = goals.next(); - Bukkit.broadcastMessage("\u00A7eClass from \'a\' field of iterated goal: \u00A76" + ReflectionUtils.getField("a", o.getClass(), o).getClass()); - Bukkit.broadcastMessage("\u00A7eClass from \'newGoal\': \u00A76" + newGoal.getClass()); - Bukkit.broadcastMessage("\n\u00A79String form of \'a\' field of iterated goal: \u00A7b" + ReflectionUtils.getField("a", o.getClass(), o)); - Bukkit.broadcastMessage("\u00A79String form of \'newGoal\': \u00A7b" + newGoal); - if (ReflectionUtils.getField("a", o.getClass(), o).getClass() == newGoal.getClass()) { + goalPriorities.next(); + if (ReflectionUtils.getField("a", o.getClass(), o).getClass() == toRemove) { goals.remove(); - Bukkit.broadcastMessage("\u00A7aClasses were the same. Just need to know how to check values"); + goalPriorities.remove(); break; } } diff --git a/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java b/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java index 998de1c..7011540 100644 --- a/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java +++ b/src/me/TheBukor/SkStuff/effects/EffSetPathGoal.java @@ -3,9 +3,11 @@ package me.TheBukor.SkStuff.effects; import javax.annotation.Nullable; import org.bukkit.Bukkit; +import org.bukkit.entity.Animals; import org.bukkit.entity.Creeper; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Tameable; import org.bukkit.event.Event; import ch.njol.skript.entity.EntityData; @@ -171,7 +173,7 @@ public class EffSetPathGoal extends Effect { newGoal = goalBreakDoor.getConstructor(entInsent).newInstance(nmsEnt); } else if (mark == 2) { double spd = breedSpeed.getSingle(e).doubleValue(); - if (!(nmsEnt.getClass().isAssignableFrom(entAnimal))) { + if (!(ent instanceof Animals)) { Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not an animal - \u00A7e[DEBUG MESSAGE]"); return; } @@ -185,14 +187,14 @@ public class EffSetPathGoal extends Effect { newGoal = goalFloat.getConstructor(entInsent).newInstance(nmsEnt); } else if (mark == 6) { double spd = followOwnerSpeed.getSingle(e).doubleValue(); - if (!(nmsEnt.getClass().isAssignableFrom(entTameable))) { + if (!(ent instanceof Tameable)) { Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a tameable animal - \u00A7e[DEBUG MESSAGE]"); return; } newGoal = goalFollowOwner.getConstructor(entTameable, double.class, float.class, float.class).newInstance(nmsEnt, spd, 20.0F, 5.0F); } else if (mark == 7) { double spd = followAdultsSpeed.getSingle(e).doubleValue(); - if (!(nmsEnt.getClass().isAssignableFrom(entAnimal))) { + if (!(ent instanceof Animals)) { Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not an animal - \u00A7e[DEBUG MESSAGE]"); return; } @@ -287,7 +289,7 @@ public class EffSetPathGoal extends Effect { int interval = randomWalkInterval.getSingle(e).getTicks(); newGoal = goalWander.getConstructor(entCreature, double.class, int.class).newInstance(nmsEnt, spd, interval); } else if (mark == 20) { - if (!(nmsEnt.getClass().isAssignableFrom(entTameable))) { + if (!(ent instanceof Tameable)) { Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a tameable animal - \u00A7e[DEBUG MESSAGE]"); return; }