package me.TheBukor.SkStuff.effects; import java.lang.reflect.InvocationTargetException; import javax.annotation.Nullable; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; 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; import me.TheBukor.SkStuff.util.ReflectionUtils; public class EffMakeJump extends Effect { private Expression entities; private Class entInsent = ReflectionUtils.getNMSClass("EntityInsentient"); private Class craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity"); @SuppressWarnings("unchecked") @Override public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { entities = (Expression) expr[0]; return true; } @Override public String toString(@Nullable Event e, boolean debug) { return "make " + entities.toString(e, debug) + " jump"; } @Override protected void execute(Event e) { LivingEntity[] ents = entities.getAll(e); for (Entity ent : ents) { if (!(ent == null || ent instanceof Player || ent instanceof ArmorStand)) { 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 (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ex) { ex.printStackTrace(); } } } } }