New effect, two more pathfinder goals. Still needing test.

This commit is contained in:
Richard
2016-02-07 22:49:09 -02:00
parent 10e2c64a92
commit bcf0a61121
5 changed files with 166 additions and 23 deletions
@@ -2,6 +2,7 @@ package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@@ -13,7 +14,7 @@ import ch.njol.util.Kleenean;
import me.TheBukor.SkStuff.util.ReflectionUtils;
public class EffMakeJump extends Effect {
private Expression<LivingEntity> entity;
private Expression<LivingEntity> entities;
private Class<?> entInsent = ReflectionUtils.getNMSClass("EntityInsentient", false);
private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity");
@@ -21,27 +22,29 @@ public class EffMakeJump extends Effect {
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
entity = (Expression<LivingEntity>) expr[0];
entities = (Expression<LivingEntity>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "make ent jump";
return "make " + entities.toString(e, false) + " jump";
}
@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 controllerJump = nmsEnt.getClass().getMethod("getControllerJump").invoke(nmsEnt);
controllerJump.getClass().getMethod("a").invoke(controllerJump);
} catch (Exception ex) {
ex.printStackTrace();
LivingEntity[] ents = entities.getAll(e);
for (Entity ent : ents) {
if (ent instanceof Player || ent == null)
continue;
Object obcEnt = craftLivEnt.cast(ent);
try {
Object nmsEnt = entInsent.cast(obcEnt.getClass().getMethod("getHandle").invoke(obcEnt));
Object controllerJump = nmsEnt.getClass().getMethod("getControllerJump").invoke(nmsEnt);
controllerJump.getClass().getMethod("a").invoke(controllerJump);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
@@ -5,6 +5,7 @@ import java.util.List;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@@ -44,7 +45,9 @@ public class EffRemovePathGoal extends Effect {
private Class<?> goalSit = ReflectionUtils.getNMSClass("PathfinderGoalSit", false);
private Class<?> goalSwell = ReflectionUtils.getNMSClass("PathfinderGoalSwell", false);
private Class<?> entBlaze = ReflectionUtils.getNMSClass("EntityBlaze", false);
private Class<?> entInsent = ReflectionUtils.getNMSClass("EntityInsentient", false);
private Class<?> entSquid = ReflectionUtils.getNMSClass("EntitySquid", false);
private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity");
@SuppressWarnings("unchecked")
@@ -116,7 +119,27 @@ public class EffRemovePathGoal extends Effect {
toRemove = goalSit;
} else if (mark == 21) {
toRemove = goalSwell;
} else if (mark == 22) {
Class<?>[] classes = entSquid.getDeclaredClasses();
for (Class<?> c : classes) {
Bukkit.broadcastMessage("\u00A79loop-class: \u00A7b" + c);
if (c.getSimpleName().equals("PathfinderGoalSquid")) {
toRemove = c;
break;
}
}
} else if (mark == 23) {
Class<?>[] classes = entBlaze.getDeclaredClasses();
for (Class<?> c : classes) {
Bukkit.broadcastMessage("\u00A79loop-class: \u00A7b" + c);
if (c.getSimpleName().equals("PathfinderGoalBlazeFireball")) {
toRemove = c;
break;
}
}
}
if (toRemove == null)
return;
Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", goalSelectorClass, goalSelector)).iterator();
Iterator<?> goalPriorities = ((List<?>) ReflectionUtils.getField("c", goalSelectorClass, goalSelector)).iterator();
while (goals.hasNext()) {
@@ -4,9 +4,12 @@ import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Blaze;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
import org.bukkit.entity.Squid;
import org.bukkit.entity.Tameable;
import org.bukkit.event.Event;
@@ -70,12 +73,11 @@ public class EffSetPathGoal extends Effect {
private Class<?> goalSit = ReflectionUtils.getNMSClass("PathfinderGoalSit", false);
private Class<?> goalSwell = ReflectionUtils.getNMSClass("PathfinderGoalSwell", false);
private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity");
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
@@ -145,10 +147,12 @@ public class EffSetPathGoal extends Effect {
if (ent instanceof Player || ent == null)
return;
Object obcEnt = craftLivEnt.cast(ent);
Object nmsEnt = null;
Class<?> clazz = null;
try {
boolean target = false;
Object newGoal = null;
Object nmsEnt = entInsent.cast(obcEnt.getClass().getMethod("getHandle").invoke(obcEnt));
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) {
@@ -217,9 +221,9 @@ public class EffSetPathGoal extends Effect {
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)
if (!(ent instanceof Ocelot))
return;
newGoal = goalJumpOnBlock.getConstructor(entOcelot, double.class).newInstance(nmsEnt, spd);
newGoal = goalJumpOnBlock.getConstructor(nmsEnt.getClass(), double.class).newInstance(nmsEnt, spd);
} else if (mark == 10) {
float height = leapHeight.getSingle(e).floatValue();
newGoal = goalLeapTarget.getConstructor(entInsent, float.class).newInstance(nmsEnt, height);
@@ -300,14 +304,67 @@ public class EffSetPathGoal extends Effect {
return;
}
newGoal = goalSwell.getConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
} else if (mark == 22) {
if (!(ent instanceof Squid)) {
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a squid - \u00A7e[DEBUG MESSAGE]");
return;
}
Class<?>[] classes = nmsEnt.getClass().getDeclaredClasses();
for (Class<?> c : classes) {
Bukkit.broadcastMessage("\u00A79loop-class: \u00A7b" + c);
if (c.getSimpleName().equals("PathfinderGoalSquid")) {
clazz = c;
clazz.getConstructor(nmsEnt.getClass()).setAccessible(true);
break;
}
}
if (clazz == null)
return;
newGoal = clazz.getConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
clazz.getConstructor(nmsEnt.getClass()).setAccessible(false);
} else if (mark == 23) {
if (!(ent instanceof Blaze)) {
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a blaze - \u00A7e[DEBUG MESSAGE]");
return;
}
Class<?>[] classes = nmsEnt.getClass().getDeclaredClasses();
for (Class<?> c : classes) {
Bukkit.broadcastMessage("\u00A79loop-class: \u00A7b" + c);
if (c.getSimpleName().equals("PathfinderGoalBlazeFireball")) {
clazz = c;
clazz.getConstructor(nmsEnt.getClass()).setAccessible(true);
break;
}
}
if (clazz == null)
return;
newGoal = clazz.getConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
clazz.getConstructor(nmsEnt.getClass()).setAccessible(false);
} else if (mark == 24) {
// TODO: Add more goal/target selectors
/* Classes that have their own pathfinder goals:
* Enderman, 3 goals, place blocks, pickup blocks and player who looked (?).
* Ghast, 3 goals, all copy of existing ones, but adapted to a flying ghast.
* Rabbit, 3 goals, 2 adapted copies, 1 new (eat carrot crops)
* Silverfish, 2 goals, hide in block and wake other silverfish blocks.
* Slime, 4 goals, random jump, go to near player, go in random direction and idle.
* Spider, 2 goals, adapted copies of melee and nearest attackable.
*/
}
if (target) {
newGoal = goalSelector.getMethod("a", int.class, goal).invoke(targets, priority, newGoal);
} else {
newGoal = goalSelector.getMethod("a", int.class, goal).invoke(goals, priority, newGoal);
}
} catch (Exception ex) {
ex.printStackTrace();
} catch (Exception ex1) {
if (clazz != null)
try {
clazz.getConstructor(nmsEnt.getClass()).setAccessible(true);
} catch (SecurityException | NoSuchMethodException ex2) {
ex2.printStackTrace();
}
ex1.printStackTrace();
}
}
}
@@ -0,0 +1,57 @@
package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;
import org.bukkit.EntityEffect;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
public class EffShowEntityEffect extends Effect {
private Expression<Entity> entity;
private int mark;
private String toStringMark;
private EntityEffect effect;
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
entity = (Expression<Entity>) expr[0];
mark = result.mark;
if (mark == 0) {
effect = EntityEffect.FIREWORK_EXPLODE;
toStringMark = "fireworks explosion";
} else if (mark == 1) {
effect = EntityEffect.HURT;
toStringMark = "hurt";
} else if (mark == 2) {
effect = EntityEffect.IRON_GOLEM_ROSE;
toStringMark = "iron golem offer rose";
} else if (mark == 3) {
effect = EntityEffect.SHEEP_EAT;
toStringMark = "sheep eat grass";
} else if (mark == 4) {
effect = EntityEffect.WOLF_SHAKE;
toStringMark = "wolf shake";
}
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "play entity effect " + toStringMark + "at" + entity.toString(e, false);
}
@Override
protected void execute(Event e) {
Entity ent = entity.getSingle(e);
if (ent != null)
ent.playEffect(effect);
}
}