New expression! Close to the release! WOOOOO!!! (Still needs more tests)

Fixed ExprNoClip being version dependant (1.8.4 - 1.8.8).
Add support for list of entities in ExprFireProof and ExprNoClip.
This commit is contained in:
Richard 2016-02-17 21:15:11 -02:00
parent db72d5bc38
commit a9467540f4
6 changed files with 284 additions and 63 deletions

View File

@ -51,6 +51,7 @@ import me.TheBukor.SkStuff.events.WorldEditChangeHandler;
import me.TheBukor.SkStuff.expressions.ExprChangedBlocksSession;
import me.TheBukor.SkStuff.expressions.ExprClickedInventory;
import me.TheBukor.SkStuff.expressions.ExprEditSessionLimit;
import me.TheBukor.SkStuff.expressions.ExprEndermanBlocks;
import me.TheBukor.SkStuff.expressions.ExprFileNBT;
import me.TheBukor.SkStuff.expressions.ExprFireProof;
import me.TheBukor.SkStuff.expressions.ExprItemNBT;
@ -98,17 +99,17 @@ 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) 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] (explode|inflate|swell)|22¦squid (swim|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦(wake other silverfish[es]|[silverfish] call (help|reinforcement|other [hidden] silverfish[es]))|26¦[enderm(a|e)n] pick[[ ]up] block[s]|27¦[enderm(a|e)n] place block[s]|28¦[enderman] attack player (staring|looking) [at eye[s]]|29¦ghast move to[wards] target|30¦ghast (idle move[ment]|wander|random fl(ight|y[ing]))|31¦(tempt to|follow players (holding|with)) [a[n]] item|32¦target [random] entity (if|when) (not tamed|untamed)) from %livingentity%");
Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %entitydata%,[ ]radius %number%,[ ][at] speed %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] (explode|inflate|swell)|22¦squid (swim|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦(wake other silverfish[es]|[silverfish] call (help|reinforcement|other [hidden] silverfish[es]))|26¦[enderm(a|e)n] pick[[ ]up] block[s]|27¦[enderm(a|e)n] place block[s]|28¦[enderman] attack player (staring|looking) [at eye[s]]|29¦ghast move to[wards] target|30¦ghast (idle move[ment]|wander|random fl(ight|y[ing]))|31¦(tempt to|follow players (holding|with)) %-itemstack%, [at] speed %number%|32¦target [random] %entitydata% (if|when) (not tamed|untamed)) 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¦target 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] (explode|inflate|swell)|22¦squid (swim|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦(wake other silverfish[es]|[silverfish] call (help|reinforcement|other [hidden] silverfish[es]))|26¦[enderm(a|e)n] pick[[ ]up] block[s]|27¦[enderm(a|e)n] place block[s]|28¦[enderman] attack player (staring|looking) [at eye[s]]|29¦ghast move to[wards] target|30¦ghast (idle move[ment]|wander|random fl(ight|y[ing]))|31¦(tempt to|follow players (holding|with)) [a[n]] item|32¦target [random] entity (if|when) (not tamed|untamed)|33¦guardian attack [entity]|34¦[z[ombie[ ]]pig[man]] attack [player[s]] (if|when) angry|35¦[z[ombie[ ]]pig[man]] (react to|fight back|target) (attacker|damager) (if|when) angry|36¦[rabbit] eat carrot crops|37¦[killer] rabbit [melee] attack|38¦slime [random] jump|39¦slime change (direction|facing) randomly|40¦slime (idle move[ment]|wander)) from %livingentity%");
Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %entitydata%,[ ]radius %number%,[ ][at] speed %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¦target 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] (explode|inflate|swell)|22¦squid (swim|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦(wake other silverfish[es]|[silverfish] call (help|reinforcement|other [hidden] silverfish[es]))|26¦[enderm(a|e)n] pick[[ ]up] block[s]|27¦[enderm(a|e)n] place block[s]|28¦[enderman] attack player (staring|looking) [at eye[s]]|29¦ghast move to[wards] target|30¦ghast (idle move[ment]|wander|random fl(ight|y[ing]))|31¦(tempt to|follow players (holding|with)) %-itemstack%, [at] speed %number%|32¦target [random] %entitydata% (if|when) (not tamed|untamed)|33¦guardian attack [entity]|34¦[z[ombie[ ]]pig[man]] attack [player[s]] (if|when) angry|35¦[z[ombie[ ]]pig[man]] (react to|fight back|target) (attacker|damager) (if|when) angry|36¦[rabbit] eat carrot crops|37¦[killer] rabbit [melee] attack|38¦slime [random] jump|39¦slime change (direction|facing) randomly|40¦slime (idle move[ment]|wander)) to %livingentity%");
Skript.registerEffect(EffMakeJump.class, "make %livingentities% jump", "force %livingentities% to jump");
Skript.registerEffect(EffShowEntityEffect.class, "(display|play|show) entity effect (0¦firework[s] explo(de|sion)|1¦hurt|2¦[[iron] golem] (give|offer) (rose|poppy)|3¦[sheep] eat grass|4¦wolf shake) at %entity%");
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(ExprTagOf.class, Object.class, ExpressionType.PROPERTY, "[nbt[ ]]tag %string% of [[nbt] compound] %compound%");
Skript.registerExpression(ExprFileNBT.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%");
Skript.registerExpression(ExprNoClip.class, Boolean.class, ExpressionType.PROPERTY, "no[( |-)]clip (state|mode) of %entity%", "%entity%'s no[( |-)]clip (state|mode)");
Skript.registerExpression(ExprFireProof.class, Boolean.class, ExpressionType.PROPERTY, "fire[ ]proof (state|mode) of %entity%", "%entity%'s fire[ ]proof (state|mode)");
//Skript.registerExpression(ExprEndermanBlocks.class, ItemStack.class, ExpressionType.PROPERTY, "blocks that [enderman] %entity% can (carry|hold|grab)");
Skript.registerExpression(ExprNoClip.class, Boolean.class, ExpressionType.PROPERTY, "no[( |-)]clip (state|mode) of %entities%", "%entities%'s no[( |-)]clip (state|mode)");
Skript.registerExpression(ExprFireProof.class, Boolean.class, ExpressionType.PROPERTY, "fire[ ]proof (state|mode) of %entities%", "%entities%'s fire[ ]proof (state|mode)");
Skript.registerExpression(ExprEndermanBlocks.class, ItemStack.class, ExpressionType.PROPERTY, "blocks that %entity% can (carry|hold|grab|steal)");
Classes.registerClass(new ClassInfo<Object>((Class<Object>) nbtClass, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<Object>() {

View File

@ -5,11 +5,11 @@ import java.util.List;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.entity.Blaze;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit;
import org.bukkit.entity.Spider;
import org.bukkit.event.Event;
@ -24,7 +24,6 @@ public class EffRemovePathGoal extends Effect {
private int mark;
private Class<?> entInsent = ReflectionUtils.getNMSClass("EntityInsentient", false);
private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity");
@ -54,8 +53,13 @@ public class EffRemovePathGoal extends Effect {
Object toRemove = null;
boolean target = false;
if (mark == 0) {
Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget", false);
toRemove = goalAvoid;
if (ent instanceof Rabbit) {
Class<?> goalRabbitAvoid = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalRabbitAvoidTarget", false);
toRemove = goalRabbitAvoid;
} else {
Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget", false);
toRemove = goalAvoid;
}
} else if (mark == 1) {
Class<?> goalBreakDoor = ReflectionUtils.getNMSClass("PathfinderGoalBreakDoor", false);
toRemove = goalBreakDoor;
@ -122,8 +126,13 @@ public class EffRemovePathGoal extends Effect {
Class<?> goalOpenDoors = ReflectionUtils.getNMSClass("PathfinderGoalOpenDoor", false);
toRemove = goalOpenDoors;
} else if (mark == 17) {
Class<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic", false);
toRemove = goalPanic;
if (ent instanceof Rabbit) {
Class<?> goalRabbitPanic = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalRabbitPanic", false);
toRemove = goalRabbitPanic;
} else {
Class<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic", false);
toRemove = goalPanic;
}
} else if (mark == 18) {
Class<?> goalRandomLook = ReflectionUtils.getNMSClass("PathfinderGoalRandomLookaround", false);
toRemove = goalRandomLook;
@ -176,6 +185,32 @@ public class EffRemovePathGoal extends Effect {
target = true;
Class<?> goalTargetNonTamed = ReflectionUtils.getNMSClass("PathfinderGoalRandomTargetNonTamed", false);
toRemove = goalTargetNonTamed;
} else if (mark == 33) {
Class<?> goalGuardianAttack = ReflectionUtils.getNMSClass("EntityGuardian$PathfinderGoalGuardianAttack", false);
toRemove = goalGuardianAttack;
} else if (mark == 34) {
target = true;
Class<?> goalAnger = ReflectionUtils.getNMSClass("EntityPigZombie$PathfinderGoalAnger", false);
toRemove = goalAnger;
} else if (mark == 35) {
target = true;
Class<?> goalAngerOther = ReflectionUtils.getNMSClass("EntityPigZombie$PathfinderGoalAngerOther", false);
toRemove = goalAngerOther;
} else if (mark == 36) {
Class<?> goalEatCarrots = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalEatCarrots", false);
toRemove = goalEatCarrots;
} else if (mark == 37) {
Class<?> goalRabbitAttack = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalKillerRabbitMeleeAttack", false);
toRemove = goalRabbitAttack;
} else if (mark == 38) {
Class<?> goalJump = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeRandomJump", false);
toRemove = goalJump;
} else if (mark == 39) {
Class<?> goalRandomDir = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeRandomDirection", false);
toRemove = goalRandomDir;
} else if (mark == 40) {
Class<?> goalSlimeWander = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeIdle", false);
toRemove = goalSlimeWander;
}
if (toRemove == null)
return;
@ -184,9 +219,7 @@ public class EffRemovePathGoal extends Effect {
Iterator<?> targets = ((List<?>) ReflectionUtils.getField("b", goalSelectorClass, targetSelector)).iterator();
while (targets.hasNext()) {
Object o = targets.next();
Bukkit.broadcastMessage("Class: \u00A7a" + ReflectionUtils.getField("a", o.getClass(), o).getClass().getSimpleName());
if (ReflectionUtils.getField("a", o.getClass(), o).getClass() == toRemove) {
Bukkit.broadcastMessage("\u00A72Is same class");
targets.remove();
}
}
@ -194,9 +227,7 @@ public class EffRemovePathGoal extends Effect {
Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", goalSelectorClass, goalSelector)).iterator();
while (goals.hasNext()) {
Object o = goals.next();
Bukkit.broadcastMessage("Class: \u00A7a" + ReflectionUtils.getField("a", o.getClass(), o).getClass().getSimpleName());
if (ReflectionUtils.getField("a", o.getClass(), o).getClass() == toRemove) {
Bukkit.broadcastMessage("\u00A72Is same class");
goals.remove();
}
}

View File

@ -4,16 +4,21 @@ import java.lang.reflect.Constructor;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Blaze;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Guardian;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit;
import org.bukkit.entity.Silverfish;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Spider;
import org.bukkit.entity.Squid;
import org.bukkit.entity.Tameable;
@ -148,7 +153,6 @@ public class EffSetPathGoal extends Effect {
Object goals = ReflectionUtils.getField("goalSelector", entInsent, nmsEnt);
Object targets = ReflectionUtils.getField("targetSelector", entInsent, nmsEnt);
if (mark == 0) {
Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget", false);
float radius = avoidRadius.getSingle(e).floatValue();
double spd = avoidSpeed.getSingle(e).doubleValue();
EntityData<?> entityData;
@ -169,7 +173,13 @@ public class EffSetPathGoal extends Effect {
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, spd, spd);
if (ent instanceof Rabbit) {
Class<?> goalRabbitAvoid = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalRabbitAvoidTarget", false);
newGoal = goalRabbitAvoid.getDeclaredConstructor(nmsEnt.getClass(), Class.class, float.class, double.class, double.class).newInstance(nmsEnt, nmsClass, radius, spd, spd);
} else {
Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget", false);
newGoal = goalAvoid.getConstructor(entCreature, Class.class, float.class, double.class, double.class).newInstance(nmsEnt, nmsClass, radius, spd, spd);
}
} else if (mark == 1) {
Class<?> goalBreakDoor = ReflectionUtils.getNMSClass("PathfinderGoalBreakDoor", false);
newGoal = goalBreakDoor.getConstructor(entInsent).newInstance(nmsEnt);
@ -289,10 +299,12 @@ public class EffSetPathGoal extends Effect {
} else if (mark == 14) {
target = true;
EntityData<?> entityData;
EntityData<?> test = nearTarget.getSingle(e);
String exprInput = nearTarget.toString(e, false);
if (exprInput.startsWith("the ")) {
exprInput = exprInput.substring(4);
}
Bukkit.broadcastMessage("Unconverted expression to string: \u00A7a" + exprInput + "\n\u00A7rConverted expression to string: \u00A72" + test);
entityData = EntityData.parseWithoutIndefiniteArticle(exprInput);
if (!LivingEntity.class.isAssignableFrom(entityData.getType()))
return;
@ -321,9 +333,15 @@ public class EffSetPathGoal extends Effect {
Class<?> goalOpenDoors = ReflectionUtils.getNMSClass("PathfinderGoalOpenDoor", false);
newGoal = goalOpenDoors.getConstructor(entInsent, boolean.class).newInstance(nmsEnt, false);
} else if (mark == 17) {
Class<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic", false);
double spd = panicSpeed.getSingle(e).doubleValue();
newGoal = goalPanic.getConstructor(entCreature, double.class).newInstance(nmsEnt, spd);
if (ent instanceof Rabbit) {
Class<?> goalRabbitPanic = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalRabbitPanic", false);
newGoal = goalRabbitPanic.getDeclaredConstructor(nmsEnt.getClass(), double.class).newInstance(nmsEnt, spd);
} else {
Class<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic", false);
newGoal = goalPanic.getConstructor(entCreature, double.class).newInstance(nmsEnt, spd);
}
} else if (mark == 18) {
Class<?> goalRandomLook = ReflectionUtils.getNMSClass("PathfinderGoalRandomLookaround", false);
newGoal = goalRandomLook.getConstructor(entInsent).newInstance(nmsEnt);
@ -445,16 +463,47 @@ public class EffSetPathGoal extends Effect {
return;
newGoal = goalTargetNonTamed.getConstructor(entTameable, Class.class, boolean.class, Predicate.class).newInstance(nmsEnt, nmsClass, false, Predicates.alwaysTrue());
} else if (mark == 33) {
// TODO: Add more goal/target selectors
/* Classes that have their own pathfinder goals:
* Guardian, 1 goal, guardian attack.
* Rabbit, 3 goals, 2 adapted copies, 1 new (eat carrot crops)
* Slime, 4 goals, random jump, go to near player, go in random direction and idle.
* ZPigMan, 2 goals, anger and anger other (adapted HurtByTarget to work with Anger tag)
*/
if (!(ent instanceof Guardian))
return;
Class<?> goalGuardianAttack = ReflectionUtils.getNMSClass("EntityGuardian$PathfinderGoalGuardianAttack", false);
newGoal = goalGuardianAttack.getDeclaredConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
} else if (mark == 34) {
if (!(ent instanceof PigZombie))
return;
target = true;
Class<?> goalAnger = ReflectionUtils.getNMSClass("EntityPigZombie$PathfinderGoalAnger", false);
newGoal = goalAnger.getDeclaredConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
} else if (mark == 35) {
if (!(ent instanceof PigZombie))
return;
target = true;
Class<?> goalAngerOther = ReflectionUtils.getNMSClass("EntityPigZombie$PathfinderGoalAngerOther", false);
newGoal = goalAngerOther.getDeclaredConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
} else if (mark == 36) {
if (!(ent instanceof Rabbit))
return;
Class<?> goalEatCarrots = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalEatCarrots", false);
newGoal = goalEatCarrots.getDeclaredConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
} else if (mark == 37) {
if (!(ent instanceof Rabbit))
return;
Class<?> goalRabbitAttack = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalKillerRabbitMeleeAttack", false);
newGoal = goalRabbitAttack.getDeclaredConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
} else if (mark == 38) {
if (!(ent instanceof Slime))
return;
Class<?> goalJump = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeRandomJump", false);
newGoal = goalJump.getDeclaredConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
} else if (mark == 39) {
if (!(ent instanceof Slime))
return;
Class<?> goalRandomDir = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeRandomDirection", false);
newGoal = goalRandomDir.getDeclaredConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
} else if (mark == 40) {
if (!(ent instanceof Slime))
return;
Class<?> goalSlimeWander = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeIdle", false);
newGoal = goalSlimeWander.getDeclaredConstructor(nmsEnt.getClass()).newInstance(nmsEnt);
}
if (newGoal == null)
return;

View File

@ -0,0 +1,110 @@
package me.TheBukor.SkStuff.expressions;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprEndermanBlocks extends SimpleExpression<ItemStack> {
private Expression<Entity> entity;
private Class<?> nmsBlockClass = ReflectionUtils.getNMSClass("Block", false);
private Class<?> endermanClass = ReflectionUtils.getNMSClass("EntityEnderman", false);
private Class<?> nmsIBlockData = ReflectionUtils.getNMSClass("IBlockData", false);
private Class<?> nmsItemClass = ReflectionUtils.getNMSClass("ItemStack", false);
private Class<?> craftEntClass = ReflectionUtils.getOBCClass("entity.CraftEntity");
private Class<?> craftItemClass = ReflectionUtils.getOBCClass("inventory.CraftItemStack");
@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}
@Override
public boolean isSingle() {
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
entity = (Expression<Entity>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "blocks that " + entity.toString(e, debug) + " can carry";
}
@SuppressWarnings("unchecked")
@Override
@Nullable
protected ItemStack[] get(Event e) {
Entity ent = entity.getSingle(e);
if (ent == null || !(ent instanceof Enderman))
return null;
Object nmsEnt = null;
try {
nmsEnt = craftEntClass.getMethod("getHandle").invoke(ent);
} catch (Exception ex) {
ex.printStackTrace();
}
Set<Object> nmsBlocks = (Set<Object>) ReflectionUtils.getField("c", endermanClass, nmsEnt);
List<ItemStack> items = new ArrayList<ItemStack>();
for (Object nmsBlock : nmsBlocks) {
Object nmsBlockData;
try {
nmsBlockData = nmsBlockClass.getMethod("getBlockData").invoke(nmsBlock);
int dataValue = (int) nmsBlockClass.getMethod("toLegacyData", nmsIBlockData).invoke(nmsBlock, nmsBlockData);
Object nmsItem = nmsItemClass.getConstructor(nmsBlockClass, int.class, int.class).newInstance(nmsBlock, 1, dataValue);
ItemStack bukkitItem = (ItemStack) craftItemClass.getMethod("asCraftMirror", nmsItemClass).invoke(null, nmsItem);
items.add(bukkitItem);
} catch (Exception ex) {
ex.printStackTrace();;
}
}
return (ItemStack[]) items.toArray();
}
@SuppressWarnings("unused")
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
if (mode == ChangeMode.SET) {
ItemStack[] toSet = (ItemStack[]) delta;
// TODO Convert bukkit items to NMS items (blocks). Then clear the list and add the delta items.
} else if (mode == ChangeMode.REMOVE) {
ItemStack[] toRemove = (ItemStack[]) delta;
// TODO The code.
} else if (mode == ChangeMode.ADD) {
ItemStack[] toAdd = (ItemStack[]) delta;
// TODO The code.
} else if (mode == ChangeMode.RESET) {
// TODO The code.
}
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.SET || mode == ChangeMode.REMOVE || mode == ChangeMode.ADD || mode == ChangeMode.RESET) {
return CollectionUtils.array(ItemStack[].class);
}
return null;
}
}

View File

@ -1,5 +1,8 @@
package me.TheBukor.SkStuff.expressions;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import org.bukkit.entity.Entity;
@ -14,7 +17,7 @@ import ch.njol.util.coll.CollectionUtils;
import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprFireProof extends SimpleExpression<Boolean> {
private Expression<Entity> entity;
private Expression<Entity> entities;
private Class<?> craftEntClass = ReflectionUtils.getOBCClass("entity.CraftEntity");
@Override
@ -30,46 +33,50 @@ public class ExprFireProof extends SimpleExpression<Boolean> {
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
entity = (Expression<Entity>) expr[0];
entities = (Expression<Entity>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "fireproof state of " + entity.toString(e, debug);
return "fireproof state of " + entities.toString(e, debug);
}
@Override
@Nullable
protected Boolean[] get(Event e) {
Entity ent = entity.getSingle(e);
if (ent == null)
Entity[] ents = entities.getAll(e);
if (ents == null)
return null;
Object nmsEnt;
Boolean fireProof = null;
try {
nmsEnt = craftEntClass.getMethod("getHandle").invoke(ent);
fireProof = (Boolean) nmsEnt.getClass().getMethod("isFireProof").invoke(nmsEnt);
} catch (Exception ex) {
ex.printStackTrace();
List<Boolean> fireProofStates = new ArrayList<Boolean>();
for (Entity ent : ents) {
Object nmsEnt = null;
try {
nmsEnt = craftEntClass.getMethod("getHandle").invoke(ent);
} catch (Exception ex) {
ex.printStackTrace();
}
fireProofStates.add((Boolean) ReflectionUtils.getField("fireProof", nmsEnt.getClass(), nmsEnt));
}
return new Boolean[] { fireProof };
return (Boolean[]) fireProofStates.toArray();
}
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
Entity ent = entity.getSingle(e);
if (ent == null)
Entity[] ents = entities.getAll(e);
if (ents == null)
return;
Object nmsEnt = null;
try {
nmsEnt = craftEntClass.getMethod("getHandle").invoke(ent);
} catch (Exception ex) {
ex.printStackTrace();
}
if (mode == ChangeMode.SET) {
Boolean newValue = (Boolean) delta[0];
ReflectionUtils.setField("fireProof", nmsEnt.getClass(), nmsEnt, newValue);
for (Entity ent : ents) {
Object nmsEnt = null;
try {
nmsEnt = craftEntClass.getMethod("getHandle").invoke(ent);
} catch (Exception ex) {
ex.printStackTrace();
}
ReflectionUtils.setField("fireProof", nmsEnt.getClass(), nmsEnt, newValue);
}
}
}

View File

@ -1,8 +1,10 @@
package me.TheBukor.SkStuff.expressions;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
@ -12,9 +14,12 @@ import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprNoClip extends SimpleExpression<Boolean> {
private Expression<Entity> entity;
private Expression<Entity> entities;
private Class<?> craftEntClass = ReflectionUtils.getOBCClass("entity.CraftEntity");
@Override
public Class<? extends Boolean> getReturnType() {
@ -23,38 +28,56 @@ public class ExprNoClip extends SimpleExpression<Boolean> {
@Override
public boolean isSingle() {
return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
entity = (Expression<Entity>) expr[0];
entities = (Expression<Entity>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "no clip state of " + entity.toString(e, debug);
return "the no clip state of " + entities.toString(e, debug);
}
@Override
@Nullable
protected Boolean[] get(Event e) {
Entity ent = entity.getSingle(e);
if (ent == null)
Entity[] ents = entities.getAll(e);
if (ents == null)
return null;
return new Boolean[] { ((CraftEntity) ent).getHandle().noclip };
List<Boolean> noClipStates = new ArrayList<Boolean>();
for (Entity ent : ents) {
Object nmsEnt = null;
try {
nmsEnt = craftEntClass.getMethod("getHandle").invoke(ent);
} catch (Exception ex) {
ex.printStackTrace();
}
noClipStates.add((Boolean) ReflectionUtils.getField("noclip", nmsEnt.getClass(), nmsEnt));
}
return (Boolean[]) noClipStates.toArray();
}
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
Entity ent = entity.getSingle(e);
if (ent == null)
Entity[] ents = entities.getAll(e);
if (ents == null)
return;
if (mode == ChangeMode.SET) {
Boolean newValue = (Boolean) delta[0];
((CraftEntity) ent).getHandle().noclip = newValue;
for (Entity ent : ents) {
Object nmsEnt = null;
try {
nmsEnt = craftEntClass.getMethod("getHandle").invoke(ent);
} catch (Exception ex) {
ex.printStackTrace();
}
ReflectionUtils.setField("noclip", nmsEnt.getClass(), nmsEnt, newValue);
}
}
}