diff --git a/src/me/TheBukor/SkStuff/SkStuff.java b/src/me/TheBukor/SkStuff/SkStuff.java index b05d7f1..95b8f96 100644 --- a/src/me/TheBukor/SkStuff/SkStuff.java +++ b/src/me/TheBukor/SkStuff/SkStuff.java @@ -93,7 +93,7 @@ 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(EffSetPathGoals.class, "add pathfind[er] goal leap at target to %livingentity% with [leap] height [of] %number%"); - Skript.registerEffect(EffSetPathGoals.class, "add pathfind[er] goal [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 players,[ ]radius %number%|12¦melee attack %entitydata%,[ ][at] speed %number%|13¦(move|go) indoors|14¦move thr(u|ough) village,[ ][at] speed %number%|15¦move to[wards] target,[ ][at] speed %number%,[ ]radius %number%|16¦attack nearest entity [of] type %entitydata%|17¦o(c|z)elot attack [chicken]|18¦open door[s]|19¦(panic|flee),[ ][at] speed %number%|20¦look around randomly|21¦(walk around randomly|wander),[ ][at] speed %number%,[ ][with] %integer% ticks between mov(e[ment]|ing)|22¦sit|23¦[creeper] swell)"); + Skript.registerEffect(EffSetPathGoals.class, "add pathfind[er] goal [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] %timespan% between mov(e[ment]|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/EffSetPathGoals.java b/src/me/TheBukor/SkStuff/effects/EffSetPathGoals.java index 3dd443f..b334c1a 100644 --- a/src/me/TheBukor/SkStuff/effects/EffSetPathGoals.java +++ b/src/me/TheBukor/SkStuff/effects/EffSetPathGoals.java @@ -2,7 +2,6 @@ package me.TheBukor.SkStuff.effects; import javax.annotation.Nullable; -import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -11,47 +10,36 @@ 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 EffSetPathGoals extends Effect { private Expression goalPriority; - private Expression> entityToAvoid; + private Expression> typeToAvoid; private Expression avoidRadius; private Expression avoidSpeed1; private Expression avoidSpeed2; private Expression breedSpeed; private Expression fleeSunSpeed; - @SuppressWarnings("unused") private Expression followOwnerSpeed; - @SuppressWarnings("unused") private Expression followAdultsSpeed; - @SuppressWarnings("unused") - private Expression> entitiesToFightBack; - @SuppressWarnings("unused") + private Expression> typesToFightBack; private Expression jumpOnBlockSpeed; - @SuppressWarnings("unused") private Expression leapHeight; - @SuppressWarnings("unused") + private Expression> lookType; private Expression lookRadius; - @SuppressWarnings("unused") private Expression> meleeTarget; - @SuppressWarnings("unused") private Expression meleeSpeed; - @SuppressWarnings("unused") - private Expression moveVillageSpeed; - @SuppressWarnings("unused") private Expression moveTargetSpeed; - @SuppressWarnings("unused") private Expression moveTargetRadius; - @SuppressWarnings("unused") private Expression> nearTarget; @SuppressWarnings("unused") private Expression panicSpeed; @SuppressWarnings("unused") private Expression randomWalkSpeed; @SuppressWarnings("unused") - private Expression randomWalkInterval; + private Expression randomWalkInterval; private Expression entity; private int mark; @@ -63,12 +51,24 @@ public class EffSetPathGoals extends Effect { private Class goalBreakDoor = ReflectionUtils.getNMSClass("PathfinderGoalBreakDoor", false); private Class goalEatGrass = ReflectionUtils.getNMSClass("PathfinderGoalEatTile", false); private Class goalFleeSun = ReflectionUtils.getNMSClass("PathfinderGoalFleeSun", false); - @SuppressWarnings("unused") + private Class goalFloat = ReflectionUtils.getNMSClass("PathfinderGoalFloat", false); + private Class goalFollowOwner = ReflectionUtils.getNMSClass("PathfinderGoalFollowOwner", false); + private Class goalFollowAdults = ReflectionUtils.getNMSClass("PathfinderGoalFollowParents", false); + private Class goalReactAttack = ReflectionUtils.getNMSClass("PathfinderGoalHurtByTarget", false); + private Class goalJumpOnBlock = ReflectionUtils.getNMSClass("PathfinderGoalJumpOnBlock", false); private Class goalLeapTarget = ReflectionUtils.getNMSClass("PathfinderGoalLeapAtTarget", false); + private Class goalLookEntities = ReflectionUtils.getNMSClass("PathfinderGoalLookAtPlayer", false); + private Class goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack", false); + private Class goalGotoTarget = ReflectionUtils.getNMSClass("PathfinderGoalMoveTowardsTarget", false); + private Class goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget", false); + private Class goalOcelotAttack = ReflectionUtils.getNMSClass("PathfinderGoalOcelotAttack", false); + private Class goalOpenDoors = ReflectionUtils.getNMSClass("PathfinderGoalOpenDoor", 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") @@ -77,11 +77,11 @@ public class EffSetPathGoals extends Effect { goalPriority = (Expression) expr[0]; mark = result.mark; if (mark == 0) { - entityToAvoid = (Expression>) expr[1]; + typeToAvoid = (Expression>) expr[1]; avoidRadius = (Expression) expr[2]; avoidSpeed1 = (Expression) expr[3]; avoidSpeed2 = (Expression) expr[4]; - } else if (mark == 2) { + } else if (mark == 2) { breedSpeed = (Expression) expr[5]; } else if (mark == 4) { fleeSunSpeed = (Expression) expr[6]; @@ -90,28 +90,27 @@ public class EffSetPathGoals extends Effect { } else if (mark == 7) { followAdultsSpeed = (Expression) expr[8]; } else if (mark == 8) { - entitiesToFightBack = (Expression>) expr[9]; + typesToFightBack = (Expression>) expr[9]; } else if (mark == 9) { jumpOnBlockSpeed = (Expression) expr[10]; } else if (mark == 10) { leapHeight = (Expression) expr[11]; } else if (mark == 11) { - lookRadius = (Expression) expr[12]; + lookType = (Expression>) expr[12]; + lookRadius = (Expression) expr[13]; } else if (mark == 12) { - meleeTarget = (Expression>) expr[13]; - meleeSpeed = (Expression) expr[14]; + meleeTarget = (Expression>) expr[14]; + meleeSpeed = (Expression) expr[15]; } else if (mark == 13) { - moveVillageSpeed = (Expression) expr[15]; - } else if (mark == 15) { moveTargetSpeed = (Expression) expr[16]; moveTargetRadius = (Expression) expr[17]; - } else if (mark == 16) { + } else if (mark == 14) { nearTarget = (Expression>) expr[18]; - } else if (mark == 19) { + } else if (mark == 17) { panicSpeed = (Expression) expr[19]; - } else if (mark == 21) { + } else if (mark == 19) { randomWalkSpeed = (Expression) expr[20]; - randomWalkInterval = (Expression) expr[21]; + randomWalkInterval = (Expression) expr[21]; } entity = (Expression) expr[22]; return true; @@ -140,15 +139,17 @@ public class EffSetPathGoals extends Effect { return; Object obcEnt = craftLivEnt.cast(ent); try { + boolean target = false; Object newGoal = null; Object nmsEnt = entInsent.cast(obcEnt.getClass().getMethod("getHandle").invoke(obcEnt)); Object goals = ReflectionUtils.getField("goalSelector", entInsent, nmsEnt); + Object targets = ReflectionUtils.getField("targetSelector", entInsent, nmsEnt); 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 = entityToAvoid.toString(e, false); + String exprInput = typeToAvoid.toString(e, false); if (exprInput.startsWith("the ")) { exprInput = exprInput.substring(4); } @@ -161,25 +162,115 @@ public class EffSetPathGoals extends Effect { if (nmsClass == null) return; newGoal = goalAvoid.getConstructor(entCreature, Class.class, float.class, double.class, double.class).newInstance(nmsEnt, nmsClass, radius, spd1, spd2); - newGoal = goalSelector.getMethod("a", int.class, goal).invoke(goals, priority, newGoal); } else if (mark == 1) { newGoal = goalBreakDoor.getConstructor(entInsent).newInstance(nmsEnt); - newGoal = goalSelector.getMethod("a", int.class, goal).invoke(goals, priority, newGoal); } 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); - newGoal = goalSelector.getMethod("a", int.class, goal).invoke(goals, priority, newGoal); } else if (mark == 3) { newGoal = goalEatGrass.getConstructor(entInsent).newInstance(nmsEnt); - newGoal = goalSelector.getMethod("a", int.class, goal).invoke(goals, priority, newGoal); } else if (mark == 4) { double spd = fleeSunSpeed.getSingle(e).doubleValue(); newGoal = goalFleeSun.getConstructor(entCreature, double.class).newInstance(nmsEnt, spd); - newGoal = goalSelector.getMethod("a", int.class, goal).invoke(goals, priority, newGoal); + } else if (mark == 5) { + newGoal = goalFloat.getConstructor(entInsent).newInstance(nmsEnt); + } 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); + } 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); + } else if (mark == 8) { + target = true; + 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 = ReflectionUtils.getNMSClass(className, false); + if (nmsClass == null) + return; + newGoal = goalReactAttack.getConstructor(entCreature, boolean.class, Class[].class).newInstance(nmsEnt, false, nmsClass); + } else if (mark == 9) { + double spd = jumpOnBlockSpeed.getSingle(e).doubleValue(); + if (nmsEnt.getClass() != entOcelot) + return; + newGoal = goalJumpOnBlock.getConstructor(entOcelot, double.class).newInstance(nmsEnt, spd); + } else if (mark == 10) { + float height = leapHeight.getSingle(e).floatValue(); + newGoal = goalLeapTarget.getConstructor(entInsent, float.class).newInstance(nmsEnt, height); + } 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); + } 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).newInstance(nmsEnt, nmsClass, spd); + } 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); + } else if (mark == 14) { + target = true; + 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); + } else if (mark == 15) { + newGoal = goalOcelotAttack.getConstructor(entInsent).newInstance(nmsEnt); + } else if (mark == 16) { + newGoal = goalOpenDoors.getConstructor(entInsent, boolean.class).newInstance(nmsEnt); + } + if (target) { + newGoal = goalSelector.getMethod("a", int.class, goal).invoke(targets, priority, newGoal); } else { - Bukkit.broadcastMessage("Not an Avoid, BreakDoor, Breed or FleeSun goal"); + newGoal = goalSelector.getMethod("a", int.class, goal).invoke(goals, priority, newGoal); } } catch (Exception ex) { ex.printStackTrace();