Stuff. Dropped support for 1.8.0-1.8.3.

This commit is contained in:
TheBukor 2016-03-17 20:50:07 -03:00
parent 0b4cb17ca1
commit 5fa301ab0b
6 changed files with 190 additions and 1087 deletions

View File

@ -84,8 +84,6 @@ import me.TheBukor.SkStuff.expressions.ExprVanishState;
import me.TheBukor.SkStuff.expressions.ExprWordsToUpperCase; import me.TheBukor.SkStuff.expressions.ExprWordsToUpperCase;
import me.TheBukor.SkStuff.util.NMSInterface; import me.TheBukor.SkStuff.util.NMSInterface;
import me.TheBukor.SkStuff.util.NMS_v1_7_R4; import me.TheBukor.SkStuff.util.NMS_v1_7_R4;
import me.TheBukor.SkStuff.util.NMS_v1_8_R1;
import me.TheBukor.SkStuff.util.NMS_v1_8_R2;
import me.TheBukor.SkStuff.util.NMS_v1_8_R3; import me.TheBukor.SkStuff.util.NMS_v1_8_R3;
import me.TheBukor.SkStuff.util.NMS_v1_9_R1; import me.TheBukor.SkStuff.util.NMS_v1_9_R1;
import me.TheBukor.SkStuff.util.ReflectionUtils; import me.TheBukor.SkStuff.util.ReflectionUtils;
@ -134,8 +132,8 @@ public class SkStuff extends JavaPlugin {
if (setupNMSVersion()) { if (setupNMSVersion()) {
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) %livingentities%"); Skript.registerEffect(EffClearPathGoals.class, "(clear|delete) [all] pathfind[er] goals (of|from) %livingentities%");
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 %livingentities%"); 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)|41¦follow [entity]) from %livingentities%");
Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %*entitydatas%[, radius %-number%[, speed %-number%[, speed (if|when) (close|near) %-number%]]]|1¦break door[s]|2¦breed[,[move[ment]] speed %-number%]|3¦eat grass|4¦(flee from the sun|seek shad(e|ow))[, [move[ment]] speed %-number%]|5¦(float (in[side]|on) water|swim)|6¦follow (owner|tamer)[, speed %-number%[, min[imum] distance %-number%[, max[imum] distance %-number%]]]|7¦follow (adult|parent)[s][, [move[ment]] speed %-number%]|8¦(fight back|react to|target) (damager|attacker) [[of] type] %*entitydatas%[, call ([for] help|reinforcement) %-boolean%]|9¦o(c|z)elot jump on blocks[, [move[ment]] speed %-number%]|10¦leap at target[, [leap] height %-number%]|11¦look at %*entitydatas%[, (radius|max[imum] distance) %-number%]|12¦melee attack %*entitydatas%[, [move[ment]] speed %-number%[, (memorize|do('nt| not) forget) target [for [a] long[er] time] %-boolean%]]|13¦move to[wards] target[, [move[ment]] speed %-number%[, (radius|max[imum] distance) %-number%]]|14¦target nearest [entity [of] type] %*entitydatas%[, check sight %-boolean%]|15¦o(c|z)elot attack|16¦open door[s]|17¦(panic|flee)[, [move[ment]] speed %-number%]|18¦look around randomly|19¦(walk around randomly|wander)[, [move[ment]] speed %-number%[, min[imum] [of] %-timespan% between mov(e[ment][s]|ing)]]|20¦sit|21¦[creeper] (explode|inflate|swell)|22¦squid (swim around|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦((call|summon|wake) [other] [hidden] silverfish[es])|26¦[enderman] pick[[ ]up] block[s]|27¦[enderman] place block[s]|28¦[enderman] attack player (staring|looking) at [their] 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%[, [move[ment]] speed %number%[, scared of player movement %-boolean%]]|32¦target [random] %*entitydatas% (if|when) (not |un)tamed|33¦guardian attack [entities]|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 %livingentities%"); Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %*entitydatas%[, radius %-number%[, speed %-number%[, speed (if|when) (close|near) %-number%]]]|1¦break door[s]|2¦breed[,[move[ment]] speed %-number%]|3¦eat grass|4¦(flee from the sun|seek shad(e|ow))[, [move[ment]] speed %-number%]|5¦(float (in[side]|on) water|swim)|6¦follow (owner|tamer)[, speed %-number%[, min[imum] distance %-number%[, max[imum] distance %-number%]]]|7¦follow (adult|parent)[s][, [move[ment]] speed %-number%]|8¦(fight back|react to|target) (damager|attacker) [[of] type] %*entitydatas%[, call ([for] help|reinforcement) %-boolean%]|9¦o(c|z)elot jump on blocks[, [move[ment]] speed %-number%]|10¦leap at target[, [leap] height %-number%]|11¦look at %*entitydatas%[, (radius|max[imum] distance) %-number%]|12¦melee attack %*entitydatas%[, [move[ment]] speed %-number%[, (memorize|do('nt| not) forget) target [for [a] long[er] time] %-boolean%]]|13¦move to[wards] target[, [move[ment]] speed %-number%[, (radius|max[imum] distance) %-number%]]|14¦target nearest [entity [of] type] %*entitydatas%[, check sight %-boolean%]|15¦o(c|z)elot attack|16¦open door[s]|17¦(panic|flee)[, [move[ment]] speed %-number%]|18¦look around randomly|19¦(walk around randomly|wander)[, [move[ment]] speed %-number%[, min[imum] [of] %-timespan% between mov(e[ment][s]|ing)]]|20¦sit|21¦[creeper] (explode|inflate|swell)|22¦squid (swim around|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦((call|summon|wake) [other] [hidden] silverfish[es])|26¦[enderman] pick[[ ]up] block[s]|27¦[enderman] place block[s]|28¦[enderman] attack player (staring|looking) at [their] 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%[, [move[ment]] speed %number%[, scared of player movement %-boolean%]]|32¦target [random] %*entitydatas% (if|when) (not |un)tamed|33¦guardian attack [entities]|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)|41¦follow %*entitydatas%[, radius %-number%[, speed %-number%[, [custom[ ]]name[d] %-string%]]]) to %livingentities%");
Skript.registerEffect(EffMakeJump.class, "make %livingentities% jump", "force %livingentities% to jump"); Skript.registerEffect(EffMakeJump.class, "make %livingentities% jump", "force %livingentities% to jump");
Skript.registerEffect(EffGZipFile.class, "create [a] gzip[ped] file [at] [path] %string%"); Skript.registerEffect(EffGZipFile.class, "create [a] gzip[ped] file [at] [path] %string%");
Skript.registerExpression(ExprNBTOf.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %~object%", "%~object%'s nbt[[ ]tag[s]]"); Skript.registerExpression(ExprNBTOf.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %~object%", "%~object%'s nbt[[ ]tag[s]]");
@ -264,13 +262,12 @@ public class SkStuff extends JavaPlugin {
} }
})); }));
typeAmount += 2;
} else { } else {
Skript.registerExpression(ExprFlagOfWGRegion.class, String.class, ExpressionType.PROPERTY, "[skstuff] [w[orld[ ]]g[uard]] flag %flag% of %protectedregion%"); Skript.registerExpression(ExprFlagOfWGRegion.class, String.class, ExpressionType.PROPERTY, "[skstuff] [w[orld[ ]]g[uard]] flag %flag% of %protectedregion%");
Skript.registerExpression(ExprFlagsOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "[skstuff] [all] [w[orld[ ]]g[uard]] flags of %protectedregion%"); Skript.registerExpression(ExprFlagsOfWGRegion.class, Flag.class, ExpressionType.PROPERTY, "[skstuff] [all] [w[orld[ ]]g[uard]] flags of %protectedregion%");
} }
exprAmount += 2; exprAmount += 2;
if (registerNewTypes)
typeAmount += 2;
} }
} }
if (Bukkit.getPluginManager().getPlugin("VanishNoPacket") != null) { if (Bukkit.getPluginManager().getPlugin("VanishNoPacket") != null) {
@ -292,18 +289,12 @@ public class SkStuff extends JavaPlugin {
if (version.equals("v1_7_R4.")) { if (version.equals("v1_7_R4.")) {
nmsMethods = new NMS_v1_7_R4(); nmsMethods = new NMS_v1_7_R4();
getLogger().info("It looks like you're running 1.7.10!"); getLogger().info("It looks like you're running 1.7.10!");
} else if (version.equals("v1_8_R1.")) {
nmsMethods = new NMS_v1_8_R1();
getLogger().info("It looks like you're running 1.8.0!");
} else if (version.equals("v1_8_R2.")) {
nmsMethods = new NMS_v1_8_R2();
getLogger().info("It looks like you're running 1.8.3!");
} else if (version.equals("v1_8_R3.")) { } else if (version.equals("v1_8_R3.")) {
nmsMethods = new NMS_v1_8_R3(); nmsMethods = new NMS_v1_8_R3();
getLogger().info("It looks like you're either running 1.8.7, 1.8.8 or 1.8.9!"); getLogger().info("It looks like you're either running 1.8.4, 1.8.7, 1.8.8 or 1.8.9!");
} else if (version.equals("v1_9_R1.")) { } else if (version.equals("v1_9_R1.")) {
nmsMethods = new NMS_v1_9_R1(); nmsMethods = new NMS_v1_9_R1();
getLogger().info("It looks like you're running 1.9.0!"); getLogger().info("It looks like you're running 1.9!");
} else { } else {
getLogger().warning("It looks like you're running an unsupported server version, some features will not be available :("); getLogger().warning("It looks like you're running an unsupported server version, some features will not be available :(");
} }

View File

@ -38,7 +38,10 @@ import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Timespan; import ch.njol.skript.util.Timespan;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import me.TheBukor.SkStuff.SkStuff; import me.TheBukor.SkStuff.SkStuff;
import me.TheBukor.SkStuff.pathfinders.PathfinderGoalFollow_v1_8_R3;
import me.TheBukor.SkStuff.pathfinders.PathfinderGoalFollow_v1_9_R1;
import me.TheBukor.SkStuff.util.ReflectionUtils; import me.TheBukor.SkStuff.util.ReflectionUtils;
import net.minecraft.server.v1_8_R3.EntityCreature;
public class EffSetPathGoal extends Effect { public class EffSetPathGoal extends Effect {
private Expression<Integer> goalPriority; private Expression<Integer> goalPriority;
@ -72,6 +75,10 @@ public class EffSetPathGoal extends Effect {
private Expression<Number> temptSpeed; private Expression<Number> temptSpeed;
private Expression<Boolean> temptScared; private Expression<Boolean> temptScared;
private Expression<? extends EntityData<?>> nonTamedTarget; private Expression<? extends EntityData<?>> nonTamedTarget;
private Expression<? extends EntityData<?>> followedTypes;
private Expression<Number> followedRadius;
private Expression<Number> followedSpeed;
private Expression<String> followedName;
private Expression<LivingEntity> entities; private Expression<LivingEntity> entities;
private int mark; private int mark;
@ -135,8 +142,13 @@ public class EffSetPathGoal extends Effect {
temptScared = (Expression<Boolean>) expr[29]; temptScared = (Expression<Boolean>) expr[29];
} else if (mark == 32) { } else if (mark == 32) {
nonTamedTarget = (Expression<EntityData<?>>) expr[30]; nonTamedTarget = (Expression<EntityData<?>>) expr[30];
} else if (mark == 41) {
followedTypes = (Expression<EntityData<?>>) expr[31];
followedRadius = (Expression<Number>) expr[32];
followedSpeed = (Expression<Number>) expr[33];
followedName = (Expression<String>) expr[34];
} }
entities = (Expression<LivingEntity>) expr[31]; entities = (Expression<LivingEntity>) expr[35];
return true; return true;
} }
@ -174,7 +186,7 @@ public class EffSetPathGoal extends Effect {
Class<?> goalRabbitAvoid = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalRabbitAvoidTarget"); Class<?> goalRabbitAvoid = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalRabbitAvoidTarget");
for (EntityData<?> entData : types) { for (EntityData<?> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType())) if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return; continue;
String className = entData.getType().getSimpleName(); String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) { if (className.equals("HumanEntity")) {
className = "Human"; className = "Human";
@ -188,7 +200,7 @@ public class EffSetPathGoal extends Effect {
Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget"); Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget");
for (EntityData<?> entData : types) { for (EntityData<?> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType())) if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return; continue;
String className = entData.getType().getSimpleName(); String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) { if (className.equals("HumanEntity")) {
className = "Human"; className = "Human";
@ -239,7 +251,7 @@ public class EffSetPathGoal extends Effect {
List<Class<?>> typesClasses = new ArrayList<Class<?>>(); List<Class<?>> typesClasses = new ArrayList<Class<?>>();
for (EntityData<?> entData : types) { for (EntityData<?> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType())) if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return; continue;
String className = entData.getType().getSimpleName(); String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) { if (className.equals("HumanEntity")) {
className = "Human"; className = "Human";
@ -268,7 +280,7 @@ public class EffSetPathGoal extends Effect {
Class<?> goalLookEntities = ReflectionUtils.getNMSClass("PathfinderGoalLookAtPlayer"); Class<?> goalLookEntities = ReflectionUtils.getNMSClass("PathfinderGoalLookAtPlayer");
for (EntityData<?> entData : types) { for (EntityData<?> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType())) if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return; continue;
String className = entData.getType().getSimpleName(); String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) { if (className.equals("HumanEntity")) {
className = "Human"; className = "Human";
@ -284,7 +296,7 @@ public class EffSetPathGoal extends Effect {
Class<?> goalSpiderMelee = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderMeleeAttack"); Class<?> goalSpiderMelee = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderMeleeAttack");
for (EntityData<?> entData : types) { for (EntityData<?> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType())) if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return; continue;
String className = entData.getType().getSimpleName(); String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) { if (className.equals("HumanEntity")) {
className = "Human"; className = "Human";
@ -312,7 +324,7 @@ public class EffSetPathGoal extends Effect {
Class<?> goalSpiderNearTarget = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderNearestAttackableTarget"); Class<?> goalSpiderNearTarget = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderNearestAttackableTarget");
for (EntityData<?> entData : types) { for (EntityData<?> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType())) if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return; continue;
String className = entData.getType().getSimpleName(); String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) { if (className.equals("HumanEntity")) {
className = "Human"; className = "Human";
@ -327,7 +339,7 @@ public class EffSetPathGoal extends Effect {
Class<?> goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget"); Class<?> goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget");
for (EntityData<?> entData : types) { for (EntityData<?> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType())) if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return; continue;
String className = entData.getType().getSimpleName(); String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) { if (className.equals("HumanEntity")) {
className = "Human"; className = "Human";
@ -438,7 +450,7 @@ public class EffSetPathGoal extends Effect {
Class<?> goalTargetNonTamed = ReflectionUtils.getNMSClass("PathfinderGoalRandomTargetNonTamed"); Class<?> goalTargetNonTamed = ReflectionUtils.getNMSClass("PathfinderGoalRandomTargetNonTamed");
for (EntityData<?> entData : types) { for (EntityData<?> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType())) if (!LivingEntity.class.isAssignableFrom(entData.getType()))
return; continue;
String className = entData.getType().getSimpleName(); String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) { if (className.equals("HumanEntity")) {
className = "Human"; className = "Human";
@ -490,7 +502,31 @@ public class EffSetPathGoal extends Effect {
return; return;
Class<?> goalSlimeWander = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeIdle"); Class<?> goalSlimeWander = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeIdle");
newGoals.add(ReflectionUtils.getConstructor(goalSlimeWander, nmsEnt.getClass()).newInstance(nmsEnt)); newGoals.add(ReflectionUtils.getConstructor(goalSlimeWander, nmsEnt.getClass()).newInstance(nmsEnt));
} else if (mark == 41) {
String version = ReflectionUtils.getVersion();
EntityData<?>[] types = followedTypes.getAll(e);
float radius = (followedRadius == null ? 32 : followedRadius.getSingle(e).floatValue());
double spd = (followedSpeed == null ? 1 : followedSpeed.getSingle(e).doubleValue());
boolean usesName = followedName != null;
String customName = (usesName ? followedName.getSingle(e) : null);
for (EntityData<?> entData : types) {
if (!LivingEntity.class.isAssignableFrom(entData.getType()))
continue;
String className = entData.getType().getSimpleName();
if (className.equals("HumanEntity")) {
className = "Human";
} else if (className.equals("EntityLiving")) {
className = "Living";
} }
Class<?> nmsClass = ReflectionUtils.getNMSClass("Entity" + className);
if (version.equals("v1_8_R3.")) {
newGoals.add(new PathfinderGoalFollow_v1_8_R3((EntityCreature) nmsEnt, nmsClass, radius, spd, usesName, customName));
} else if (version.equals("v1_9_R1.")) {
newGoals.add(new PathfinderGoalFollow_v1_9_R1((net.minecraft.server.v1_9_R1.EntityCreature) nmsEnt, nmsClass, radius, spd, usesName, customName));
}
}
}
if (newGoals.size() == 0) if (newGoals.size() == 0)
return; return;
for (Object goal : newGoals) { for (Object goal : newGoals) {

View File

@ -0,0 +1,70 @@
package me.TheBukor.SkStuff.pathfinders;
import java.util.List;
import net.minecraft.server.v1_8_R3.Entity;
import net.minecraft.server.v1_8_R3.EntityCreature;
import net.minecraft.server.v1_8_R3.EntityLiving;
import net.minecraft.server.v1_8_R3.PathfinderGoal;
public class PathfinderGoalFollow_v1_8_R3 extends PathfinderGoal {
private EntityCreature follower;
private EntityLiving followed;
private Class<?> followedClass;
private float radius;
private double speed;
private boolean isByName;
private String customName;
public PathfinderGoalFollow_v1_8_R3(EntityCreature follower, Class<?> followedClass, float radius, double speed, boolean isByName, String customName) {
this.follower = follower;
this.followedClass = followedClass;
this.radius = radius;
this.speed = speed;
this.isByName = isByName;
this.customName = customName;
}
// a() is shouldExecute()
@SuppressWarnings("unchecked")
@Override
public boolean a() {
if (followed == null) {
List<?> list = follower.world.a((Class<? extends Entity>) followedClass, follower.getBoundingBox().grow(radius, 4.0D, radius));
if (list.isEmpty()) {
return false;
}
if (isByName) {
for (Object entity : list) {
if (((EntityLiving) entity).getCustomName().equals(customName)) {
followed = (EntityLiving) entity;
return true;
}
}
} else {
followed = (EntityLiving) list.get(0);
return true;
}
}
return false;
}
// b() is shouldContinueExecuting()
@Override
public boolean b() {
if (followed.dead) {
return false;
} else if (isByName) {
if (!followed.getCustomName().equals(customName)) {
return false;
}
}
return !follower.getNavigation().m(); // m() means hasNoPath()
}
// c() is execute()
@Override
public void c() {
follower.getNavigation().a(followed, speed);
}
}

View File

@ -0,0 +1,70 @@
package me.TheBukor.SkStuff.pathfinders;
import java.util.List;
import net.minecraft.server.v1_9_R1.Entity;
import net.minecraft.server.v1_9_R1.EntityCreature;
import net.minecraft.server.v1_9_R1.EntityLiving;
import net.minecraft.server.v1_9_R1.PathfinderGoal;
public class PathfinderGoalFollow_v1_9_R1 extends PathfinderGoal {
private EntityCreature follower;
private EntityLiving followed;
private Class<?> followedClass;
private float radius;
private double speed;
private boolean isByName;
private String customName;
public PathfinderGoalFollow_v1_9_R1(EntityCreature follower, Class<?> followedClass, float radius, double speed, boolean isByName, String customName) {
this.follower = follower;
this.followedClass = followedClass;
this.radius = radius;
this.speed = speed;
this.isByName = isByName;
this.customName = customName;
}
// a() is shouldExecute()
@SuppressWarnings("unchecked")
@Override
public boolean a() {
if (followed == null) {
List<?> list = follower.world.a((Class<? extends Entity>) followedClass, follower.getBoundingBox().grow(radius, 4.0D, radius));
if (list.isEmpty()) {
return false;
}
if (isByName) {
for (Object entity : list) {
if (((EntityLiving) entity).getCustomName().equals(customName)) {
followed = (EntityLiving) entity;
return true;
}
}
} else {
followed = (EntityLiving) list.get(0);
return true;
}
}
return false;
}
// b() is shouldContinueExecuting()
@Override
public boolean b() {
if (followed.dead) {
return false;
} else if (isByName) {
if (!followed.getCustomName().equals(customName)) {
return false;
}
}
return !follower.getNavigation().n(); // n() means hasNoPath()
}
// c() is execute()
@Override
public void c() {
follower.getNavigation().a(followed, speed);
}
}

View File

@ -1,529 +0,0 @@
package me.TheBukor.SkStuff.util;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.NotSerializableException;
import java.io.OutputStream;
import java.io.StreamCorruptedException;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.classes.Serializer;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.registrations.Classes;
import ch.njol.util.coll.CollectionUtils;
import ch.njol.yggdrasil.Fields;
import net.minecraft.server.v1_8_R1.BlockPosition;
import net.minecraft.server.v1_8_R1.EntityInsentient;
import net.minecraft.server.v1_8_R1.Item;
import net.minecraft.server.v1_8_R1.MinecraftKey;
import net.minecraft.server.v1_8_R1.MojangsonParser;
import net.minecraft.server.v1_8_R1.NBTBase;
import net.minecraft.server.v1_8_R1.NBTCompressedStreamTools;
import net.minecraft.server.v1_8_R1.NBTTagByte;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
import net.minecraft.server.v1_8_R1.NBTTagDouble;
import net.minecraft.server.v1_8_R1.NBTTagFloat;
import net.minecraft.server.v1_8_R1.NBTTagInt;
import net.minecraft.server.v1_8_R1.NBTTagList;
import net.minecraft.server.v1_8_R1.NBTTagLong;
import net.minecraft.server.v1_8_R1.NBTTagShort;
import net.minecraft.server.v1_8_R1.NBTTagString;
import net.minecraft.server.v1_8_R1.PathfinderGoal;
import net.minecraft.server.v1_8_R1.PathfinderGoalSelector;
import net.minecraft.server.v1_8_R1.TileEntity;
import net.minecraft.server.v1_8_R1.World;
public class NMS_v1_8_R1 implements NMSInterface {
@Override
public void addToCompound(Object compound, Object toAdd) {
if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) {
((NBTTagCompound) compound).a((NBTTagCompound) toAdd);
}
}
@Override
public void removeFromCompound(Object compound, String ... toRemove) {
if (compound instanceof NBTTagCompound) {
for (String s : toRemove) {
((NBTTagCompound) compound).remove(s);
}
}
}
@Override
public NBTTagCompound parseRawNBT(String rawNBT) {
NBTTagCompound parsedNBT = null;
parsedNBT = MojangsonParser.parse(rawNBT);
return parsedNBT;
}
@Override
public Object[] getContents(Object nbtList) {
if (nbtList instanceof NBTTagList) {
Object[] contents = new Object[((NBTTagList) nbtList).size()];
for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) {
if (getIndex(nbtList, i) != null) {
contents[i] = getIndex(nbtList, i);
}
}
return contents;
}
return null;
}
@Override
public void addToList(Object nbtList, Object toAdd) {
if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) {
((NBTTagList) nbtList).add((NBTBase) toAdd);
}
}
@Override
public void removeFromList(Object nbtList, int index) {
if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) {
((NBTTagList) nbtList).a(index);
}
}
@Override
public void setIndex(Object nbtList, int index, Object toSet) {
if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) {
if (toSet instanceof NBTBase) {
((NBTTagList) nbtList).a(index, (NBTBase) toSet);
} else if (toSet instanceof Number) {
((NBTTagList) nbtList).a(index, convertToNBT((Number) toSet));
} else if (toSet instanceof String) {
((NBTTagList) nbtList).a(index, convertToNBT((String) toSet));
}
}
}
@Override
public Object getIndex(Object nbtList, int index) {
if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) {
NBTBase value = ((NBTTagList) nbtList).g(index);
if (value instanceof NBTTagByte) {
return ((NBTTagByte) value).f(); //Byte stored inside a NBTNumber
} else if (value instanceof NBTTagShort) {
return ((NBTTagShort) value).e(); //Short inside a NBTNumber
} else if (value instanceof NBTTagInt) {
return ((NBTTagInt) value).d(); //Integer inside a NBTNumber
} else if (value instanceof NBTTagLong) {
return ((NBTTagLong) value).c(); //Long inside a NBTNumber
} else if (value instanceof NBTTagFloat) {
return ((NBTTagFloat) value).h(); //Float inside a NBTNumber
} else if (value instanceof NBTTagDouble) {
return ((NBTTagDouble) value).g(); //Double inside a NBTNumber
} else if (value instanceof NBTTagString) {
return ((NBTTagString) value).a_(); //String inside the NBTTagString
} else if (value instanceof NBTBase) {
return value; //No need to convert anything, these are registered by the addon.
}
}
return null;
}
@Override
public void clearPathfinderGoals(Entity entity) {
EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle();
((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
}
@Override
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) {
if (entity instanceof EntityInsentient) {
((EntityInsentient) entity).setGoalTarget(null);
if (isTargetSelector) {
Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).targetSelector)).iterator();
while (goals.hasNext()) {
Object goal = goals.next();
if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) {
goals.remove();
}
}
} else {
Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).goalSelector)).iterator();
while (goals.hasNext()) {
Object goal = goals.next();
if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) {
goals.remove();
}
}
}
}
}
@Override
public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) {
if (entity instanceof EntityInsentient && goal instanceof PathfinderGoal) {
if (isTargetSelector)
((EntityInsentient) entity).targetSelector.a(priority, (PathfinderGoal) goal);
else
((EntityInsentient) entity).goalSelector.a(priority, (PathfinderGoal) goal);
}
}
@Override
public void registerCompoundClassInfo() {
Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() {
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
return CollectionUtils.array(String.class, NBTTagCompound.class);
}
return null;
}
@Override
public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) {
if (mode == ChangeMode.ADD) {
if (delta[0] instanceof String) {
NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]);
addToCompound(NBT[0], parsedNBT);
} else {
addToCompound(NBT[0], delta[0]);
}
} else if (mode == ChangeMode.REMOVE) {
if (delta[0] instanceof NBTTagCompound)
return;
for (Object s : delta) {
NBT[0].remove((String) s);
}
}
}
}).parser(new Parser<NBTTagCompound>() {
@Override
public String getVariableNamePattern() {
return ".+";
}
@Override
@Nullable
public NBTTagCompound parse(String rawNBT, ParseContext context) {
if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) {
NBTTagCompound NBT = null;
NBT = parseRawNBT(rawNBT.substring(4));
return NBT;
}
return null;
}
@Override
public String toString(NBTTagCompound compound, int arg1) {
return compound.toString();
}
@Override
public String toVariableNameString(NBTTagCompound compound) {
return compound.toString();
}
}).serializer(new Serializer<NBTTagCompound>() {
@Override
public Fields serialize(NBTTagCompound compound) throws NotSerializableException {
Fields f = new Fields();
f.putObject("asString", compound.toString());
return f;
}
@Override
public void deserialize(NBTTagCompound compound, Fields f) throws StreamCorruptedException, NotSerializableException {
assert false;
}
@Override
protected boolean canBeInstantiated() {
return false;
}
@Override
protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
String s = fields.getObject("asString", String.class);
NBTTagCompound compound = parseRawNBT(s);
return compound;
}
@Override
@Nullable
public NBTTagCompound deserialize(String s) {
NBTTagCompound compound = parseRawNBT(s);
return compound;
}
@Override
public boolean mustSyncDeserialization() {
return true;
}
}));
}
@Override
public void registerNBTListClassInfo() {
Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() {
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTBase.class);
}
return null;
}
@Override
public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) {
if (delta.length == 0)
return;
if (delta[0] instanceof Number) {
addToList(nbtList, convertToNBT((Number) delta[0]));
} else if (delta[0] instanceof String) {
addToList(nbtList, convertToNBT((String) delta[0]));
} else if (delta[0] instanceof NBTBase) {
addToList(nbtList, delta[0]);
}
}
}).parser(new Parser<NBTTagList>() {
@Override
public String getVariableNamePattern() {
return ".+";
}
@Override
@Nullable
public NBTTagList parse(String listString, ParseContext context) {
if (listString.startsWith("[") && listString.endsWith("]")) {
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
NBTTagList parsedList = (NBTTagList) tempNBT.get("SkStuffIsCool");
return parsedList;
}
return null;
}
@Override
public String toString(NBTTagList nbtList, int arg1) {
return nbtList.toString();
}
@Override
public String toVariableNameString(NBTTagList nbtList) {
return nbtList.toString();
}
}).serializer(new Serializer<NBTTagList>() {
@Override
public Fields serialize(NBTTagList nbtList) throws NotSerializableException {
Fields f = new Fields();
f.putObject("asString", nbtList.toString());
return f;
}
@Override
public void deserialize(NBTTagList nbtList, Fields f) throws StreamCorruptedException, NotSerializableException {
assert false;
}
@Override
protected boolean canBeInstantiated() {
return false;
}
@Override
protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
String s = fields.getObject("asString", String.class);
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
return nbtList;
}
@Override
@Nullable
public NBTTagList deserialize(String s) {
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
return nbtList;
}
@Override
public boolean mustSyncDeserialization() {
return true;
}
}));
}
@Override
public NBTTagCompound getEntityNBT(Entity entity) {
net.minecraft.server.v1_8_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
NBTTagCompound NBT = new NBTTagCompound();
nmsEntity.e(NBT);
return NBT;
}
@Override
public NBTTagCompound getTileNBT(Block block) {
NBTTagCompound NBT = new NBTTagCompound();
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (tileEntity == null)
return null;
tileEntity.b(NBT);
return NBT;
}
@Override
public NBTTagCompound getItemNBT(ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR)
return null;
NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag();
if (itemNBT.isEmpty())
itemNBT = null;
return itemNBT;
}
@Override
public void setEntityNBT(Entity entity, Object newCompound) {
if (newCompound instanceof NBTTagCompound) {
net.minecraft.server.v1_8_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.f((NBTTagCompound) newCompound);
}
}
@Override
public void setTileNBT(Block block, Object newCompound) {
if (newCompound instanceof NBTTagCompound) {
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (tileEntity == null)
return;
tileEntity.a((NBTTagCompound) newCompound);
tileEntity.update();
nmsWorld.notify(tileEntity.getPosition());
}
}
@Override
public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) {
net.minecraft.server.v1_8_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
if (compound instanceof NBTTagCompound && itemStack != null) {
if (itemStack.getType() == Material.AIR)
return null;
if (((NBTTagCompound) compound).isEmpty())
return itemStack;
nmsItem.setTag((NBTTagCompound) compound);
ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem);
return newItem;
} else if (compound == null) {
nmsItem.setTag(null);
ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem);
return newItem;
}
return itemStack;
}
@Override
public NBTTagCompound getFileNBT(File file) {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException ex) {
return null; //File doesn't exist.
}
NBTTagCompound fileNBT = null;
try {
fileNBT = NBTCompressedStreamTools.a(fis);
fis.close();
} catch (IOException ex) {
if (ex instanceof EOFException) {
; //Nothing.
} else {
ex.printStackTrace();
}
}
return fileNBT;
}
@Override
public void setFileNBT(File file, Object newCompound) {
if (newCompound instanceof NBTTagCompound) {
OutputStream os = null;
try {
os = new FileOutputStream(file);
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
try {
NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os);
os.close();
} catch (IOException ex) {
if (ex instanceof EOFException) {
; //Ignore, just end of the file
} else {
ex.printStackTrace();
}
}
}
}
public NBTBase convertToNBT(Number number) {
if (number instanceof Byte) {
return new NBTTagByte((byte) number);
} else if (number instanceof Short) {
return new NBTTagShort((short) number);
} else if (number instanceof Integer) {
return new NBTTagInt((int) number);
} else if (number instanceof Long) {
return new NBTTagLong((long) number);
} else if (number instanceof Float) {
return new NBTTagFloat((float) number);
} else if (number instanceof Double) {
return new NBTTagDouble((double) number);
}
return null;
}
public NBTTagString convertToNBT(String string) {
return new NBTTagString(string);
}
@Override
public String getMCId(ItemStack itemStack) {
net.minecraft.server.v1_8_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
MinecraftKey mcKey = (MinecraftKey) Item.REGISTRY.c(nmsItem.getItem());
return mcKey.toString();
}
@Override
public ItemStack getItemFromMcId(String mcId) {
MinecraftKey mcKey = new MinecraftKey(mcId);
Item nmsItem = (Item) Item.REGISTRY.get(mcKey);
return CraftItemStack.asNewCraftStack(nmsItem);
}
}

View File

@ -1,535 +0,0 @@
package me.TheBukor.SkStuff.util;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.NotSerializableException;
import java.io.OutputStream;
import java.io.StreamCorruptedException;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.classes.Serializer;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.registrations.Classes;
import ch.njol.util.coll.CollectionUtils;
import ch.njol.yggdrasil.Fields;
import net.minecraft.server.v1_8_R2.BlockPosition;
import net.minecraft.server.v1_8_R2.EntityInsentient;
import net.minecraft.server.v1_8_R2.Item;
import net.minecraft.server.v1_8_R2.MinecraftKey;
import net.minecraft.server.v1_8_R2.MojangsonParseException;
import net.minecraft.server.v1_8_R2.MojangsonParser;
import net.minecraft.server.v1_8_R2.NBTBase;
import net.minecraft.server.v1_8_R2.NBTCompressedStreamTools;
import net.minecraft.server.v1_8_R2.NBTTagByte;
import net.minecraft.server.v1_8_R2.NBTTagCompound;
import net.minecraft.server.v1_8_R2.NBTTagDouble;
import net.minecraft.server.v1_8_R2.NBTTagFloat;
import net.minecraft.server.v1_8_R2.NBTTagInt;
import net.minecraft.server.v1_8_R2.NBTTagList;
import net.minecraft.server.v1_8_R2.NBTTagLong;
import net.minecraft.server.v1_8_R2.NBTTagShort;
import net.minecraft.server.v1_8_R2.NBTTagString;
import net.minecraft.server.v1_8_R2.PathfinderGoal;
import net.minecraft.server.v1_8_R2.PathfinderGoalSelector;
import net.minecraft.server.v1_8_R2.TileEntity;
import net.minecraft.server.v1_8_R2.World;
public class NMS_v1_8_R2 implements NMSInterface {
@Override
public void addToCompound(Object compound, Object toAdd) {
if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) {
((NBTTagCompound) compound).a((NBTTagCompound) toAdd);
}
}
@Override
public void removeFromCompound(Object compound, String ... toRemove) {
if (compound instanceof NBTTagCompound) {
for (String s : toRemove) {
((NBTTagCompound) compound).remove(s);
}
}
}
@Override
public NBTTagCompound parseRawNBT(String rawNBT) {
NBTTagCompound parsedNBT = null;
try {
parsedNBT = MojangsonParser.parse(rawNBT);
} catch (MojangsonParseException ex) {
Skript.warning("Error when parsing NBT - " + ex.getMessage());
return null;
}
return parsedNBT;
}
@Override
public Object[] getContents(Object nbtList) {
if (nbtList instanceof NBTTagList) {
Object[] contents = new Object[((NBTTagList) nbtList).size()];
for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) {
if (getIndex(nbtList, i) != null) {
contents[i] = getIndex(nbtList, i);
}
}
return contents;
}
return null;
}
@Override
public void addToList(Object nbtList, Object toAdd) {
if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) {
((NBTTagList) nbtList).add((NBTBase) toAdd);
}
}
@Override
public void removeFromList(Object nbtList, int index) {
if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) {
((NBTTagList) nbtList).a(index);
}
}
@Override
public void setIndex(Object nbtList, int index, Object toSet) {
if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) {
if (toSet instanceof NBTBase) {
((NBTTagList) nbtList).a(index, (NBTBase) toSet);
} else if (toSet instanceof Number) {
((NBTTagList) nbtList).a(index, convertToNBT((Number) toSet));
} else if (toSet instanceof String) {
((NBTTagList) nbtList).a(index, convertToNBT((String) toSet));
}
}
}
@Override
public Object getIndex(Object nbtList, int index) {
if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) {
NBTBase value = ((NBTTagList) nbtList).g(index);
if (value instanceof NBTTagByte) {
return ((NBTTagByte) value).f(); //Byte stored inside a NBTNumber
} else if (value instanceof NBTTagShort) {
return ((NBTTagShort) value).e(); //Short inside a NBTNumber
} else if (value instanceof NBTTagInt) {
return ((NBTTagInt) value).d(); //Integer inside a NBTNumber
} else if (value instanceof NBTTagLong) {
return ((NBTTagLong) value).c(); //Long inside a NBTNumber
} else if (value instanceof NBTTagFloat) {
return ((NBTTagFloat) value).h(); //Float inside a NBTNumber
} else if (value instanceof NBTTagDouble) {
return ((NBTTagDouble) value).g(); //Double inside a NBTNumber
} else if (value instanceof NBTTagString) {
return ((NBTTagString) value).a_(); //String inside the NBTTagString
} else if (value instanceof NBTTagList || value instanceof NBTTagCompound) {
return value; //No need to convert anything, these are registered by the addon.
}
}
return null;
}
@Override
public void clearPathfinderGoals(Entity entity) {
EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle();
((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
}
@Override
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) {
if (entity instanceof EntityInsentient) {
((EntityInsentient) entity).setGoalTarget(null);
if (isTargetSelector) {
Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).targetSelector)).iterator();
while (goals.hasNext()) {
Object goal = goals.next();
if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) {
goals.remove();
}
}
} else {
Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, ((EntityInsentient) entity).goalSelector)).iterator();
while (goals.hasNext()) {
Object goal = goals.next();
if (ReflectionUtils.getField("a", goal.getClass(), goal).getClass() == goalClass) {
goals.remove();
}
}
}
}
}
@Override
public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) {
if (entity instanceof EntityInsentient && goal instanceof PathfinderGoal) {
if (isTargetSelector)
((EntityInsentient) entity).targetSelector.a(priority, (PathfinderGoal) goal);
else
((EntityInsentient) entity).goalSelector.a(priority, (PathfinderGoal) goal);
}
}
@Override
public void registerCompoundClassInfo() {
Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() {
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
return CollectionUtils.array(String.class, NBTTagCompound.class);
}
return null;
}
@Override
public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) {
if (mode == ChangeMode.ADD) {
if (delta[0] instanceof String) {
NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]);
addToCompound(NBT[0], parsedNBT);
} else {
addToCompound(NBT[0], delta[0]);
}
} else if (mode == ChangeMode.REMOVE) {
if (delta[0] instanceof NBTTagCompound)
return;
for (Object s : delta) {
NBT[0].remove((String) s);
}
}
}
}).parser(new Parser<NBTTagCompound>() {
@Override
public String getVariableNamePattern() {
return ".+";
}
@Override
@Nullable
public NBTTagCompound parse(String rawNBT, ParseContext context) {
if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) {
NBTTagCompound NBT = parseRawNBT(rawNBT.substring(4));
return NBT;
}
return null;
}
@Override
public String toString(NBTTagCompound compound, int arg1) {
return compound.toString();
}
@Override
public String toVariableNameString(NBTTagCompound compound) {
return compound.toString();
}
}).serializer(new Serializer<NBTTagCompound>() {
@Override
public Fields serialize(NBTTagCompound compound) throws NotSerializableException {
Fields f = new Fields();
f.putObject("asString", compound.toString());
return f;
}
@Override
public void deserialize(NBTTagCompound compound, Fields f) throws StreamCorruptedException, NotSerializableException {
assert false;
}
@Override
protected boolean canBeInstantiated() {
return false;
}
@Override
protected NBTTagCompound deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
String s = fields.getObject("asString", String.class);
NBTTagCompound compound = parseRawNBT(s);
return compound;
}
@Override
@Nullable
public NBTTagCompound deserialize(String s) {
NBTTagCompound compound = parseRawNBT(s);
return compound;
}
@Override
public boolean mustSyncDeserialization() {
return true;
}
}));
}
@Override
public void registerNBTListClassInfo() {
Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() {
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD) {
return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTBase.class);
}
return null;
}
@Override
public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) {
if (delta.length == 0)
return;
if (delta[0] instanceof Number) {
addToList(nbtList, convertToNBT((Number) delta[0]));
} else if (delta[0] instanceof String) {
addToList(nbtList, convertToNBT((String) delta[0]));
} else if (delta[0] instanceof NBTBase) {
addToList(nbtList, delta[0]);
}
}
}).parser(new Parser<NBTTagList>() {
@Override
public String getVariableNamePattern() {
return ".+";
}
@Override
@Nullable
public NBTTagList parse(String listString, ParseContext context) {
if (listString.startsWith("[") && listString.endsWith("]")) {
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:[0:" + listString.substring(1) + "}");
NBTTagList parsedList = (NBTTagList) tempNBT.get("SkStuffIsCool");
return parsedList;
}
return null;
}
@Override
public String toString(NBTTagList nbtList, int arg1) {
return nbtList.toString();
}
@Override
public String toVariableNameString(NBTTagList nbtList) {
return nbtList.toString();
}
}).serializer(new Serializer<NBTTagList>() {
@Override
public Fields serialize(NBTTagList nbtList) throws NotSerializableException {
Fields f = new Fields();
f.putObject("asString", nbtList.toString());
return f;
}
@Override
public void deserialize(NBTTagList nbtList, Fields f) throws StreamCorruptedException, NotSerializableException {
assert false;
}
@Override
protected boolean canBeInstantiated() {
return false;
}
@Override
protected NBTTagList deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException {
String s = fields.getObject("asString", String.class);
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
return nbtList;
}
@Override
@Nullable
public NBTTagList deserialize(String s) {
NBTTagCompound tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
return nbtList;
}
@Override
public boolean mustSyncDeserialization() {
return true;
}
}));
}
@Override
public NBTTagCompound getEntityNBT(Entity entity) {
net.minecraft.server.v1_8_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
NBTTagCompound NBT = new NBTTagCompound();
nmsEntity.e(NBT);
return NBT;
}
@Override
public NBTTagCompound getTileNBT(Block block) {
NBTTagCompound NBT = new NBTTagCompound();
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (tileEntity == null)
return null;
tileEntity.b(NBT);
return NBT;
}
@Override
public NBTTagCompound getItemNBT(ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR)
return null;
NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag();
if (itemNBT.isEmpty())
itemNBT = null;
return itemNBT;
}
@Override
public void setEntityNBT(Entity entity, Object newCompound) {
if (newCompound instanceof NBTTagCompound) {
net.minecraft.server.v1_8_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.f((NBTTagCompound) newCompound);
}
}
@Override
public void setTileNBT(Block block, Object newCompound) {
if (newCompound instanceof NBTTagCompound) {
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
TileEntity tileEntity = nmsWorld.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (tileEntity == null)
return;
tileEntity.a((NBTTagCompound) newCompound);
tileEntity.update();
nmsWorld.notify(tileEntity.getPosition());
}
}
@Override
public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) {
net.minecraft.server.v1_8_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
if (compound instanceof NBTTagCompound && itemStack != null) {
if (itemStack.getType() == Material.AIR)
return null;
if (((NBTTagCompound) compound).isEmpty())
return itemStack;
nmsItem.setTag((NBTTagCompound) compound);
ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem);
return newItem;
} else if (compound == null) {
nmsItem.setTag(null);
ItemStack newItem = CraftItemStack.asBukkitCopy(nmsItem);
return newItem;
}
return itemStack;
}
@Override
public NBTTagCompound getFileNBT(File file) {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException ex) {
return null; //File doesn't exist.
}
NBTTagCompound fileNBT = null;
try {
fileNBT = NBTCompressedStreamTools.a(fis);
fis.close();
} catch (IOException ex) {
if (ex instanceof EOFException) {
; //Nothing.
} else {
ex.printStackTrace();
}
}
return fileNBT;
}
@Override
public void setFileNBT(File file, Object newCompound) {
if (newCompound instanceof NBTTagCompound) {
OutputStream os = null;
try {
os = new FileOutputStream(file);
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
try {
NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os);
os.close();
} catch (IOException ex) {
if (ex instanceof EOFException) {
; //Ignore, just end of the file
} else {
ex.printStackTrace();
}
}
}
}
public NBTBase convertToNBT(Number number) {
if (number instanceof Byte) {
return new NBTTagByte((byte) number);
} else if (number instanceof Short) {
return new NBTTagShort((short) number);
} else if (number instanceof Integer) {
return new NBTTagInt((int) number);
} else if (number instanceof Long) {
return new NBTTagLong((long) number);
} else if (number instanceof Float) {
return new NBTTagFloat((float) number);
} else if (number instanceof Double) {
return new NBTTagDouble((double) number);
}
return null;
}
public NBTTagString convertToNBT(String string) {
return new NBTTagString(string);
}
@Override
public String getMCId(ItemStack itemStack) {
net.minecraft.server.v1_8_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
MinecraftKey mcKey = Item.REGISTRY.c(nmsItem.getItem());
return mcKey.toString();
}
@Override
public ItemStack getItemFromMcId(String mcId) {
MinecraftKey mcKey = new MinecraftKey(mcId);
Item nmsItem = (Item) Item.REGISTRY.get(mcKey);
return CraftItemStack.asNewCraftStack(nmsItem);
}
}