Close to a release, still needs more testing.
This commit is contained in:
parent
679cdef6dd
commit
0c5cbc44f6
@ -36,9 +36,10 @@ import me.TheBukor.SkStuff.effects.EffMakeSphere;
|
|||||||
import me.TheBukor.SkStuff.effects.EffMakeWalls;
|
import me.TheBukor.SkStuff.effects.EffMakeWalls;
|
||||||
import me.TheBukor.SkStuff.effects.EffNaturalize;
|
import me.TheBukor.SkStuff.effects.EffNaturalize;
|
||||||
import me.TheBukor.SkStuff.effects.EffRememberChanges;
|
import me.TheBukor.SkStuff.effects.EffRememberChanges;
|
||||||
|
import me.TheBukor.SkStuff.effects.EffRemovePathGoal;
|
||||||
import me.TheBukor.SkStuff.effects.EffReplaceBlocksWE;
|
import me.TheBukor.SkStuff.effects.EffReplaceBlocksWE;
|
||||||
import me.TheBukor.SkStuff.effects.EffSetBlocksWE;
|
import me.TheBukor.SkStuff.effects.EffSetBlocksWE;
|
||||||
import me.TheBukor.SkStuff.effects.EffSetPathGoals;
|
import me.TheBukor.SkStuff.effects.EffSetPathGoal;
|
||||||
import me.TheBukor.SkStuff.effects.EffSimulateSnow;
|
import me.TheBukor.SkStuff.effects.EffSimulateSnow;
|
||||||
import me.TheBukor.SkStuff.effects.EffToggleVanish;
|
import me.TheBukor.SkStuff.effects.EffToggleVanish;
|
||||||
import me.TheBukor.SkStuff.effects.EffUndoRedoSession;
|
import me.TheBukor.SkStuff.effects.EffUndoRedoSession;
|
||||||
@ -92,8 +93,8 @@ public class SkStuff extends JavaPlugin {
|
|||||||
|
|
||||||
getLogger().info("Trying to register version specific stuff...");
|
getLogger().info("Trying to register version specific stuff...");
|
||||||
Skript.registerEffect(EffClearPathGoals.class, "(clear|delete) [all] pathfind[er] goals (of|from) %livingentity%");
|
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(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(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(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(EffMakeJump.class, "make %livingentity% jump");
|
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(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%");
|
Skript.registerExpression(ExprItemNBT.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%");
|
||||||
|
300
src/me/TheBukor/SkStuff/effects/EffRemovePathGoal.java
Normal file
300
src/me/TheBukor/SkStuff/effects/EffRemovePathGoal.java
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
package me.TheBukor.SkStuff.effects;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
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<EntityData<?>> typeToAvoid;
|
||||||
|
private Expression<Number> avoidRadius;
|
||||||
|
private Expression<Number> avoidSpeed1;
|
||||||
|
private Expression<Number> avoidSpeed2;
|
||||||
|
private Expression<Number> breedSpeed;
|
||||||
|
private Expression<Number> fleeSunSpeed;
|
||||||
|
private Expression<Number> followOwnerSpeed;
|
||||||
|
private Expression<Number> followAdultsSpeed;
|
||||||
|
private Expression<EntityData<?>> typesToFightBack;
|
||||||
|
private Expression<Number> jumpOnBlockSpeed;
|
||||||
|
private Expression<Number> leapHeight;
|
||||||
|
private Expression<EntityData<?>> lookType;
|
||||||
|
private Expression<Number> lookRadius;
|
||||||
|
private Expression<EntityData<?>> meleeTarget;
|
||||||
|
private Expression<Number> meleeSpeed;
|
||||||
|
private Expression<Number> moveTargetSpeed;
|
||||||
|
private Expression<Number> moveTargetRadius;
|
||||||
|
private Expression<EntityData<?>> nearTarget;
|
||||||
|
private Expression<Number> panicSpeed;
|
||||||
|
private Expression<Number> randomWalkSpeed;
|
||||||
|
private Expression<Timespan> randomWalkInterval;
|
||||||
|
private Expression<LivingEntity> entity;
|
||||||
|
|
||||||
|
private int mark;
|
||||||
|
|
||||||
|
private Class<?> goalSelectorClass = ReflectionUtils.getNMSClass("PathfinderGoalSelector", false);
|
||||||
|
private Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget", false);
|
||||||
|
private Class<?> goalBreed = ReflectionUtils.getNMSClass("PathfinderGoalBreed", false);
|
||||||
|
private Class<?> goalBreakDoor = ReflectionUtils.getNMSClass("PathfinderGoalBreakDoor", false);
|
||||||
|
private Class<?> goalEatGrass = ReflectionUtils.getNMSClass("PathfinderGoalEatTile", false);
|
||||||
|
private Class<?> goalFleeSun = ReflectionUtils.getNMSClass("PathfinderGoalFleeSun", false);
|
||||||
|
private Class<?> goalFloat = ReflectionUtils.getNMSClass("PathfinderGoalFloat", false);
|
||||||
|
private Class<?> goalFollowOwner = ReflectionUtils.getNMSClass("PathfinderGoalFollowOwner", false);
|
||||||
|
private Class<?> goalFollowAdults = ReflectionUtils.getNMSClass("PathfinderGoalFollowParent", 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<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic", false);
|
||||||
|
private Class<?> goalRandomLook = ReflectionUtils.getNMSClass("PathfinderGoalRandomLookaround", false);
|
||||||
|
private Class<?> goalWander = ReflectionUtils.getNMSClass("PathfinderGoalRandomStroll", false);
|
||||||
|
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<EntityData<?>>) expr[0];
|
||||||
|
avoidRadius = (Expression<Number>) expr[1];
|
||||||
|
avoidSpeed1 = (Expression<Number>) expr[2];
|
||||||
|
avoidSpeed2 = (Expression<Number>) expr[3];
|
||||||
|
} else if (mark == 2) {
|
||||||
|
breedSpeed = (Expression<Number>) expr[4];
|
||||||
|
} else if (mark == 4) {
|
||||||
|
fleeSunSpeed = (Expression<Number>) expr[5];
|
||||||
|
} else if (mark == 6) {
|
||||||
|
followOwnerSpeed = (Expression<Number>) expr[6];
|
||||||
|
} else if (mark == 7) {
|
||||||
|
followAdultsSpeed = (Expression<Number>) expr[7];
|
||||||
|
} else if (mark == 8) {
|
||||||
|
typesToFightBack = (Expression<EntityData<?>>) expr[8];
|
||||||
|
} else if (mark == 9) {
|
||||||
|
jumpOnBlockSpeed = (Expression<Number>) expr[9];
|
||||||
|
} else if (mark == 10) {
|
||||||
|
leapHeight = (Expression<Number>) expr[10];
|
||||||
|
} else if (mark == 11) {
|
||||||
|
lookType = (Expression<EntityData<?>>) expr[11];
|
||||||
|
lookRadius = (Expression<Number>) expr[12];
|
||||||
|
} else if (mark == 12) {
|
||||||
|
meleeTarget = (Expression<EntityData<?>>) expr[13];
|
||||||
|
meleeSpeed = (Expression<Number>) expr[14];
|
||||||
|
} else if (mark == 13) {
|
||||||
|
moveTargetSpeed = (Expression<Number>) expr[15];
|
||||||
|
moveTargetRadius = (Expression<Number>) expr[16];
|
||||||
|
} else if (mark == 14) {
|
||||||
|
nearTarget = (Expression<EntityData<?>>) expr[17];
|
||||||
|
} else if (mark == 17) {
|
||||||
|
panicSpeed = (Expression<Number>) expr[18];
|
||||||
|
} else if (mark == 19) {
|
||||||
|
randomWalkSpeed = (Expression<Number>) expr[19];
|
||||||
|
randomWalkInterval = (Expression<Timespan>) expr[20];
|
||||||
|
}
|
||||||
|
entity = (Expression<LivingEntity>) expr[21];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(@Nullable Event e, boolean arg1) {
|
||||||
|
return "remove pathfind goal of " + entity.toString(e, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "unused", "deprecation" })
|
||||||
|
@Override
|
||||||
|
protected void execute(Event e) {
|
||||||
|
LivingEntity ent = entity.getSingle(e);
|
||||||
|
if (ent instanceof Player || ent == null)
|
||||||
|
return;
|
||||||
|
Object obcEnt = craftLivEnt.cast(ent);
|
||||||
|
try {
|
||||||
|
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);
|
||||||
|
} else if (mark == 1) {
|
||||||
|
newGoal = goalBreakDoor.getConstructor(entInsent).newInstance(nmsEnt);
|
||||||
|
} 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);
|
||||||
|
} else if (mark == 3) {
|
||||||
|
newGoal = goalEatGrass.getConstructor(entInsent).newInstance(nmsEnt);
|
||||||
|
} else if (mark == 4) {
|
||||||
|
double spd = fleeSunSpeed.getSingle(e).doubleValue();
|
||||||
|
newGoal = goalFleeSun.getConstructor(entCreature, double.class).newInstance(nmsEnt, spd);
|
||||||
|
} 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) {
|
||||||
|
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]);
|
||||||
|
} 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, boolean.class).newInstance(nmsEnt, nmsClass, spd, false);
|
||||||
|
} 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) {
|
||||||
|
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, false);
|
||||||
|
} else if (mark == 17) {
|
||||||
|
double spd = panicSpeed.getSingle(e).doubleValue();
|
||||||
|
newGoal = goalPanic.getConstructor(entCreature, double.class).newInstance(nmsEnt, spd);
|
||||||
|
} else if (mark == 18) {
|
||||||
|
newGoal = goalRandomLook.getConstructor(entInsent).newInstance(nmsEnt);
|
||||||
|
} 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);
|
||||||
|
} 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);
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", 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()) {
|
||||||
|
goals.remove();
|
||||||
|
Bukkit.broadcastMessage("\u00A7aClasses were the same. Just need to know how to check values");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,8 @@ package me.TheBukor.SkStuff.effects;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Creeper;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@ -14,7 +16,7 @@ import ch.njol.skript.util.Timespan;
|
|||||||
import ch.njol.util.Kleenean;
|
import ch.njol.util.Kleenean;
|
||||||
import me.TheBukor.SkStuff.util.ReflectionUtils;
|
import me.TheBukor.SkStuff.util.ReflectionUtils;
|
||||||
|
|
||||||
public class EffSetPathGoals extends Effect {
|
public class EffSetPathGoal extends Effect {
|
||||||
private Expression<Integer> goalPriority;
|
private Expression<Integer> goalPriority;
|
||||||
private Expression<EntityData<?>> typeToAvoid;
|
private Expression<EntityData<?>> typeToAvoid;
|
||||||
private Expression<Number> avoidRadius;
|
private Expression<Number> avoidRadius;
|
||||||
@ -34,11 +36,8 @@ public class EffSetPathGoals extends Effect {
|
|||||||
private Expression<Number> moveTargetSpeed;
|
private Expression<Number> moveTargetSpeed;
|
||||||
private Expression<Number> moveTargetRadius;
|
private Expression<Number> moveTargetRadius;
|
||||||
private Expression<EntityData<?>> nearTarget;
|
private Expression<EntityData<?>> nearTarget;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private Expression<Number> panicSpeed;
|
private Expression<Number> panicSpeed;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private Expression<Number> randomWalkSpeed;
|
private Expression<Number> randomWalkSpeed;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private Expression<Timespan> randomWalkInterval;
|
private Expression<Timespan> randomWalkInterval;
|
||||||
private Expression<LivingEntity> entity;
|
private Expression<LivingEntity> entity;
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ public class EffSetPathGoals extends Effect {
|
|||||||
private Class<?> goalFleeSun = ReflectionUtils.getNMSClass("PathfinderGoalFleeSun", false);
|
private Class<?> goalFleeSun = ReflectionUtils.getNMSClass("PathfinderGoalFleeSun", false);
|
||||||
private Class<?> goalFloat = ReflectionUtils.getNMSClass("PathfinderGoalFloat", false);
|
private Class<?> goalFloat = ReflectionUtils.getNMSClass("PathfinderGoalFloat", false);
|
||||||
private Class<?> goalFollowOwner = ReflectionUtils.getNMSClass("PathfinderGoalFollowOwner", false);
|
private Class<?> goalFollowOwner = ReflectionUtils.getNMSClass("PathfinderGoalFollowOwner", false);
|
||||||
private Class<?> goalFollowAdults = ReflectionUtils.getNMSClass("PathfinderGoalFollowParents", false);
|
private Class<?> goalFollowAdults = ReflectionUtils.getNMSClass("PathfinderGoalFollowParent", false);
|
||||||
private Class<?> goalReactAttack = ReflectionUtils.getNMSClass("PathfinderGoalHurtByTarget", false);
|
private Class<?> goalReactAttack = ReflectionUtils.getNMSClass("PathfinderGoalHurtByTarget", false);
|
||||||
private Class<?> goalJumpOnBlock = ReflectionUtils.getNMSClass("PathfinderGoalJumpOnBlock", false);
|
private Class<?> goalJumpOnBlock = ReflectionUtils.getNMSClass("PathfinderGoalJumpOnBlock", false);
|
||||||
private Class<?> goalLeapTarget = ReflectionUtils.getNMSClass("PathfinderGoalLeapAtTarget", false);
|
private Class<?> goalLeapTarget = ReflectionUtils.getNMSClass("PathfinderGoalLeapAtTarget", false);
|
||||||
@ -63,6 +62,11 @@ public class EffSetPathGoals extends Effect {
|
|||||||
private Class<?> goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget", false);
|
private Class<?> goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget", false);
|
||||||
private Class<?> goalOcelotAttack = ReflectionUtils.getNMSClass("PathfinderGoalOcelotAttack", false);
|
private Class<?> goalOcelotAttack = ReflectionUtils.getNMSClass("PathfinderGoalOcelotAttack", false);
|
||||||
private Class<?> goalOpenDoors = ReflectionUtils.getNMSClass("PathfinderGoalOpenDoor", false);
|
private Class<?> goalOpenDoors = ReflectionUtils.getNMSClass("PathfinderGoalOpenDoor", false);
|
||||||
|
private Class<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic", false);
|
||||||
|
private Class<?> goalRandomLook = ReflectionUtils.getNMSClass("PathfinderGoalRandomLookaround", false);
|
||||||
|
private Class<?> goalWander = ReflectionUtils.getNMSClass("PathfinderGoalRandomStroll", false);
|
||||||
|
private Class<?> goalSit = ReflectionUtils.getNMSClass("PathfinderGoalSit", false);
|
||||||
|
private Class<?> goalSwell = ReflectionUtils.getNMSClass("PathfinderGoalSwell", false);
|
||||||
|
|
||||||
private Class<?> entAnimal = ReflectionUtils.getNMSClass("EntityAnimal", false);
|
private Class<?> entAnimal = ReflectionUtils.getNMSClass("EntityAnimal", false);
|
||||||
private Class<?> entCreature = ReflectionUtils.getNMSClass("EntityCreature", false);
|
private Class<?> entCreature = ReflectionUtils.getNMSClass("EntityCreature", false);
|
||||||
@ -121,6 +125,7 @@ public class EffSetPathGoals extends Effect {
|
|||||||
return "add pathfinder goal to ent";
|
return "add pathfinder goal to ent";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
protected void execute(Event e) {
|
protected void execute(Event e) {
|
||||||
int priority = 0;
|
int priority = 0;
|
||||||
@ -166,8 +171,10 @@ public class EffSetPathGoals extends Effect {
|
|||||||
newGoal = goalBreakDoor.getConstructor(entInsent).newInstance(nmsEnt);
|
newGoal = goalBreakDoor.getConstructor(entInsent).newInstance(nmsEnt);
|
||||||
} else if (mark == 2) {
|
} else if (mark == 2) {
|
||||||
double spd = breedSpeed.getSingle(e).doubleValue();
|
double spd = breedSpeed.getSingle(e).doubleValue();
|
||||||
if (!(nmsEnt.getClass().isAssignableFrom(entAnimal)))
|
if (!(nmsEnt.getClass().isAssignableFrom(entAnimal))) {
|
||||||
|
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not an animal - \u00A7e[DEBUG MESSAGE]");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
newGoal = goalBreed.getConstructor(entAnimal, double.class).newInstance(nmsEnt, spd);
|
newGoal = goalBreed.getConstructor(entAnimal, double.class).newInstance(nmsEnt, spd);
|
||||||
} else if (mark == 3) {
|
} else if (mark == 3) {
|
||||||
newGoal = goalEatGrass.getConstructor(entInsent).newInstance(nmsEnt);
|
newGoal = goalEatGrass.getConstructor(entInsent).newInstance(nmsEnt);
|
||||||
@ -178,13 +185,17 @@ public class EffSetPathGoals extends Effect {
|
|||||||
newGoal = goalFloat.getConstructor(entInsent).newInstance(nmsEnt);
|
newGoal = goalFloat.getConstructor(entInsent).newInstance(nmsEnt);
|
||||||
} else if (mark == 6) {
|
} else if (mark == 6) {
|
||||||
double spd = followOwnerSpeed.getSingle(e).doubleValue();
|
double spd = followOwnerSpeed.getSingle(e).doubleValue();
|
||||||
if (!(nmsEnt.getClass().isAssignableFrom(entTameable)))
|
if (!(nmsEnt.getClass().isAssignableFrom(entTameable))) {
|
||||||
|
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a tameable animal - \u00A7e[DEBUG MESSAGE]");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
newGoal = goalFollowOwner.getConstructor(entTameable, double.class, float.class, float.class).newInstance(nmsEnt, spd, 20.0F, 5.0F);
|
newGoal = goalFollowOwner.getConstructor(entTameable, double.class, float.class, float.class).newInstance(nmsEnt, spd, 20.0F, 5.0F);
|
||||||
} else if (mark == 7) {
|
} else if (mark == 7) {
|
||||||
double spd = followAdultsSpeed.getSingle(e).doubleValue();
|
double spd = followAdultsSpeed.getSingle(e).doubleValue();
|
||||||
if (!(nmsEnt.getClass().isAssignableFrom(entAnimal)))
|
if (!(nmsEnt.getClass().isAssignableFrom(entAnimal))) {
|
||||||
|
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not an animal - \u00A7e[DEBUG MESSAGE]");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
newGoal = goalFollowAdults.getConstructor(entAnimal, double.class).newInstance(nmsEnt, spd);
|
newGoal = goalFollowAdults.getConstructor(entAnimal, double.class).newInstance(nmsEnt, spd);
|
||||||
} else if (mark == 8) {
|
} else if (mark == 8) {
|
||||||
target = true;
|
target = true;
|
||||||
@ -198,10 +209,10 @@ public class EffSetPathGoals extends Effect {
|
|||||||
if (className.equals("HumanEntity"))
|
if (className.equals("HumanEntity"))
|
||||||
className = "Human";
|
className = "Human";
|
||||||
className = "Entity" + className;
|
className = "Entity" + className;
|
||||||
Class<?> nmsClass = ReflectionUtils.getNMSClass(className, false);
|
Class<?>[] nmsClass = new Class<?>[] { ReflectionUtils.getNMSClass(className, false) };
|
||||||
if (nmsClass == null)
|
if (nmsClass[0] == null)
|
||||||
return;
|
return;
|
||||||
newGoal = goalReactAttack.getConstructor(entCreature, boolean.class, Class[].class).newInstance(nmsEnt, false, nmsClass);
|
newGoal = goalReactAttack.getConstructor(entCreature, boolean.class, Class[].class).newInstance(nmsEnt, false, nmsClass[0]);
|
||||||
} else if (mark == 9) {
|
} else if (mark == 9) {
|
||||||
double spd = jumpOnBlockSpeed.getSingle(e).doubleValue();
|
double spd = jumpOnBlockSpeed.getSingle(e).doubleValue();
|
||||||
if (nmsEnt.getClass() != entOcelot)
|
if (nmsEnt.getClass() != entOcelot)
|
||||||
@ -241,7 +252,7 @@ public class EffSetPathGoals extends Effect {
|
|||||||
if (nmsClass == null)
|
if (nmsClass == null)
|
||||||
return;
|
return;
|
||||||
double spd = meleeSpeed.getSingle(e).doubleValue();
|
double spd = meleeSpeed.getSingle(e).doubleValue();
|
||||||
newGoal = goalMeleeAttack.getConstructor(entCreature, Class.class, double.class).newInstance(nmsEnt, nmsClass, spd);
|
newGoal = goalMeleeAttack.getConstructor(entCreature, Class.class, double.class, boolean.class).newInstance(nmsEnt, nmsClass, spd, false);
|
||||||
} else if (mark == 13) {
|
} else if (mark == 13) {
|
||||||
double spd = moveTargetSpeed.getSingle(e).doubleValue();
|
double spd = moveTargetSpeed.getSingle(e).doubleValue();
|
||||||
float radius = moveTargetRadius.getSingle(e).floatValue();
|
float radius = moveTargetRadius.getSingle(e).floatValue();
|
||||||
@ -265,7 +276,28 @@ public class EffSetPathGoals extends Effect {
|
|||||||
} else if (mark == 15) {
|
} else if (mark == 15) {
|
||||||
newGoal = goalOcelotAttack.getConstructor(entInsent).newInstance(nmsEnt);
|
newGoal = goalOcelotAttack.getConstructor(entInsent).newInstance(nmsEnt);
|
||||||
} else if (mark == 16) {
|
} else if (mark == 16) {
|
||||||
newGoal = goalOpenDoors.getConstructor(entInsent, boolean.class).newInstance(nmsEnt);
|
newGoal = goalOpenDoors.getConstructor(entInsent, boolean.class).newInstance(nmsEnt, false);
|
||||||
|
} else if (mark == 17) {
|
||||||
|
double spd = panicSpeed.getSingle(e).doubleValue();
|
||||||
|
newGoal = goalPanic.getConstructor(entCreature, double.class).newInstance(nmsEnt, spd);
|
||||||
|
} else if (mark == 18) {
|
||||||
|
newGoal = goalRandomLook.getConstructor(entInsent).newInstance(nmsEnt);
|
||||||
|
} 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);
|
||||||
|
} 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);
|
||||||
|
} 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);
|
||||||
}
|
}
|
||||||
if (target) {
|
if (target) {
|
||||||
newGoal = goalSelector.getMethod("a", int.class, goal).invoke(targets, priority, newGoal);
|
newGoal = goalSelector.getMethod("a", int.class, goal).invoke(targets, priority, newGoal);
|
@ -3,7 +3,6 @@ package me.TheBukor.SkStuff.util;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.fusesource.jansi.Ansi;
|
|
||||||
|
|
||||||
public class ReflectionUtils {
|
public class ReflectionUtils {
|
||||||
|
|
||||||
@ -11,12 +10,12 @@ public class ReflectionUtils {
|
|||||||
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + ".";
|
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + ".";
|
||||||
String name = "net.minecraft.server." + version + classString;
|
String name = "net.minecraft.server." + version + classString;
|
||||||
if (isArray)
|
if (isArray)
|
||||||
name = "[L" + name;
|
name = "[L" + name + ";";
|
||||||
Class<?> nmsClass = null;
|
Class<?> nmsClass = null;
|
||||||
try {
|
try {
|
||||||
nmsClass = Class.forName(name);
|
nmsClass = Class.forName(name);
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
Bukkit.getLogger().warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Unable to get NMS class! You are probably running an unsupported version!" + Ansi.ansi().fgBright(Ansi.Color.DEFAULT));
|
Bukkit.getLogger().warning("Unable to get NMS class \'" + name + "\'! You are probably running an unsupported version!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return nmsClass;
|
return nmsClass;
|
||||||
@ -29,7 +28,7 @@ public class ReflectionUtils {
|
|||||||
try {
|
try {
|
||||||
obcClass = Class.forName(name);
|
obcClass = Class.forName(name);
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
Bukkit.getLogger().warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Unable to get OBC class! You are probably running an unsupported version!" + Ansi.ansi().fgBright(Ansi.Color.DEFAULT));
|
Bukkit.getLogger().warning("Unable to get OBC class \'" + name + "\'! You are probably running an unsupported version!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return obcClass;
|
return obcClass;
|
||||||
|
Loading…
Reference in New Issue
Block a user