Closer and closer to a release!

Few changes to pathfinder goals, new "proper" clicked inventory
expression, let Skript debug "toString()" if needed.
This commit is contained in:
Richard 2016-02-14 21:58:54 -02:00
parent bcf0a61121
commit 2cf4e790ba
41 changed files with 464 additions and 240 deletions

View File

@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.fusesource.jansi.Ansi;
@ -35,6 +36,7 @@ import me.TheBukor.SkStuff.effects.EffMakePyramid;
import me.TheBukor.SkStuff.effects.EffMakeSphere;
import me.TheBukor.SkStuff.effects.EffMakeWalls;
import me.TheBukor.SkStuff.effects.EffNaturalize;
import me.TheBukor.SkStuff.effects.EffPasteSchematic;
import me.TheBukor.SkStuff.effects.EffRememberChanges;
import me.TheBukor.SkStuff.effects.EffRemovePathGoal;
import me.TheBukor.SkStuff.effects.EffReplaceBlocksWE;
@ -47,6 +49,7 @@ import me.TheBukor.SkStuff.effects.EffUndoRedoSession;
import me.TheBukor.SkStuff.events.EvtWorldEditChange;
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.ExprFileNBT;
import me.TheBukor.SkStuff.expressions.ExprFireProof;
@ -90,13 +93,14 @@ public class SkStuff extends JavaPlugin {
Skript.registerExpression(ExprToLowerCase.class, String.class, ExpressionType.SIMPLE, "%string% [converted] to [all] lower[ ]case", "convert %string% to [all] lower[ ]case", "un[( |-)]capitalize [all] [char[acter]s (of|in)] %string%");
Skript.registerExpression(ExprWordsToUpperCase.class, String.class, ExpressionType.SIMPLE, "(first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% [converted] to (cap[ital]s|upper[ ]case) (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])", "convert (first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% to (cap[ital]s|upper[ ]case) (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])", "capitalize (first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])");
Skript.registerExpression(ExprTimespanToNumber.class, Number.class, ExpressionType.SIMPLE, "%timespan% [converted] [in]to (0¦ticks|1¦sec[ond]s|2¦min[ute]s|3¦hours|4¦days)");
exprAmount += 4;
Skript.registerExpression(ExprClickedInventory.class, Inventory.class, ExpressionType.SIMPLE, "[skstuff] clicked inventory");
exprAmount += 5;
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] swell|22¦squid (swim|wander)|23¦[blaze] shoot fireball[s]) from %livingentity%");
Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %entitydata%,[ ]radius %number%,[ ][at] speed %number%,[ ][at] speed if close %number%|1¦break door[s]|2¦breed,[ ][move to[wards] lover at] speed %number%|3¦eat grass|4¦(flee from the sun|seek shad(e|ow)),[ ][at] speed %number%|5¦float (in[side]|on) water|6¦follow (owner|tamer),[ ][at] speed %number%|7¦follow (adult|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] swell|22¦squid (swim|wander)|23¦[blaze] shoot fireball[s]) to %livingentity%");
Skript.registerEffect(EffMakeJump.class, "make %livingentities% jump");
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] 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]))) from %livingentity%");
Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %entitydata%,[ ]radius %number%,[ ][at] speed %number%,[ ][at] speed if close %number%|1¦break door[s]|2¦breed,[ ][move to[wards] lover at] speed %number%|3¦eat grass|4¦(flee from the sun|seek shad(e|ow)),[ ][at] speed %number%|5¦float (in[side]|on) water|6¦follow (owner|tamer),[ ][at] speed %number%|7¦follow (adult|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] 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]))) 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%");
@ -104,6 +108,7 @@ public class SkStuff extends JavaPlugin {
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)");
Classes.registerClass(new ClassInfo<Object>((Class<Object>) nbtClass, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<Object>() {
@ -189,7 +194,7 @@ public class SkStuff extends JavaPlugin {
@Override
public String toVariableNameString(Object compound) {
return compound.toString();
return "nbt:" + compound.toString();
}
}));
@ -275,9 +280,9 @@ public class SkStuff extends JavaPlugin {
return list.toString();
}
}));
typeAmount += 2;
effAmount += 5;
exprAmount += 6;
typeAmount += 2;
if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) {
getLogger().info("WorldEdit found! Registering WorldEdit stuff...");
Skript.registerCondition(CondSelectionContains.class, "[(world[ ]edit|we)] selection of %player% (contains|has) %location%", "%player%'s [(world[ ]edit|we)] selection (contains|has) %location%", "[(world[ ]edit|we)] selection of %player% does(n't| not) (contain|have) %location%", "%player%'s [(world[ ]edit|we)] selection does(n't| not) (contain|have) %location%");
@ -293,6 +298,7 @@ public class SkStuff extends JavaPlugin {
Skript.registerEffect(EffSetBlocksWE.class, "set [all] blocks (from|between) %location% (to|and) %location% to %itemstacks% (using|with) [edit[ ]session] %editsession%");
Skript.registerEffect(EffMakeCylinder.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) cylinder at %location% [with] radius [of] %double%,[ ]%integer%(,[ ]| and )%double% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%");
Skript.registerEffect(EffReplaceBlocksWE.class, "replace [all] %itemstacks% (from|between) %location% (to|and) %location% with %itemstacks% (using|with) [edit[ ]session] %editsession%");
Skript.registerEffect(EffPasteSchematic.class, "paste schem[atic] %string% at %location% using [edit[ ]session] %editsession% (0¦|1¦(ignor(e|ing)|without|[with] no) air)");
Skript.registerExpression(ExprEditSessionLimit.class, Integer.class, ExpressionType.PROPERTY, "[block] limit [change] of [edit[ ]session] %editsession%");
Skript.registerExpression(ExprChangedBlocksSession.class, Integer.class, ExpressionType.PROPERTY, "number of [all] changed blocks (in|of) [edit[ ]session] %editsession%");
Skript.registerExpression(ExprNewEditSession.class, EditSession.class, ExpressionType.PROPERTY, "[new] edit[ ]session in [world] %world% [with] [max[imum]] [block] limit [change] [of] %integer%");
@ -325,7 +331,7 @@ public class SkStuff extends JavaPlugin {
return;
}
condAmount += 1;
effAmount += 12;
effAmount += 13;
exprAmount += 7;
typeAmount += 1;
}

View File

@ -29,8 +29,8 @@ public class CondSelectionContains extends Condition {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "if WorldEdit selection of " + player.toString(e, false) + (isNegated() ? " doesn't contain " : " contains ") + loc.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "if WorldEdit selection of " + player.toString(e, debug) + (isNegated() ? " doesn't contain " : " contains ") + loc.toString(e, debug);
}
@Override

View File

@ -29,8 +29,8 @@ public class EffClearPathGoals extends Effect {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "clear all pathfind goals of " + entity.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "clear all pathfinder goals from " + entity.toString(e, debug);
}
@Override

View File

@ -29,8 +29,8 @@ public class EffDrainLiquid extends Effect {
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "drain liquids at " + location.toString(e, false) + " in a radius of " + radius.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "drain liquids at " + location.toString(e, debug) + " in a radius of " + radius.toString(e, debug);
}
@Override

View File

@ -41,8 +41,8 @@ public class EffDrawLineWE extends Effect {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "draw a line from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " using an edit session with " + blockList.toString(e, false) + " and thickness " + thickness.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "draw a line from " + location1.toString(e, debug) + " to " + location2.toString(e, debug) + " using an edit session with " + blockList.toString(e, debug) + " and thickness " + thickness.toString(e, debug);
}
@SuppressWarnings("deprecation")

View File

@ -43,8 +43,8 @@ public class EffMakeCylinder extends Effect {
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "create a cylinder at " + location.toString(e, false) + " with a radius of " + radius1.toString(e, false) + " " + height.toString(e, false) + " " + radius2.toString(e, false) + " using an edit session with " + blockList.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "create a cylinder at " + location.toString(e, debug) + " with a radius of " + radius1.toString(e, debug) + " " + height.toString(e, debug) + " " + radius2.toString(e, debug) + " using an edit session with " + blockList.toString(e, debug);
}
@SuppressWarnings("deprecation")

View File

@ -2,6 +2,7 @@ package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -27,15 +28,15 @@ public class EffMakeJump extends Effect {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "make " + entities.toString(e, false) + " jump";
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 instanceof Player || ent == null)
if (ent == null || ent instanceof Player || ent instanceof ArmorStand)
continue;
Object obcEnt = craftLivEnt.cast(ent);
try {

View File

@ -39,8 +39,8 @@ public class EffMakePyramid extends Effect {
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "create a pyramid at " + location.toString(e, false) + " with a radius of " + radius.toString(e, false) + " using an edit session with " + blockList.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "create a pyramid at " + location.toString(e, debug) + " with a radius of " + radius.toString(e, debug) + " using an edit session with " + blockList.toString(e, debug);
}
@SuppressWarnings("deprecation")

View File

@ -43,8 +43,8 @@ public class EffMakeSphere extends Effect {
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "create a sphere centered at " + location.toString(e, false) + " with a radius of " + radius1.toString(e, false) + " " + radius2.toString(e, false) + " " + radius3.toString(e, false) + " using an edit session with " + blockList.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "create a sphere centered at " + location.toString(e, debug) + " with a radius of " + radius1.toString(e, debug) + " " + radius2.toString(e, debug) + " " + radius3.toString(e, debug) + " using an edit session with " + blockList.toString(e, debug);
}
@SuppressWarnings("deprecation")

View File

@ -38,8 +38,8 @@ public class EffMakeWalls extends Effect {
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "make walls from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " using an edit session with " + blockList.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "make walls from " + location1.toString(e, debug) + " to " + location2.toString(e, debug) + " using an edit session with " + blockList.toString(e, debug);
}
@SuppressWarnings("deprecation")

View File

@ -30,8 +30,8 @@ public class EffNaturalize extends Effect {
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "naturalize all blocks from " + location1.toString(e, false) + " to " + location2.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "naturalize all blocks from " + location1.toString(e, debug) + " to " + location2.toString(e, debug);
}
@Override

View File

@ -0,0 +1,65 @@
package me.TheBukor.SkStuff.effects;
import java.io.File;
import java.io.IOException;
import javax.annotation.Nullable;
import org.bukkit.Location;
import org.bukkit.event.Event;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.data.DataException;
import com.sk89q.worldedit.schematic.SchematicFormat;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
@SuppressWarnings("deprecation")
public class EffPasteSchematic extends Effect {
private Expression<String> schematic;
private Expression<Location> location;
private Expression<EditSession> editSession;
private int mark;
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
mark = result.mark;
schematic = (Expression<String>) expr[0];
location = (Expression<Location>) expr[1];
editSession = (Expression<EditSession>) expr[2];
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "paste schematic " + schematic.toString(e, debug) + " at " + location.toString(e, debug) + " using edit session" + (mark == 1 ? " ignoring air" : "");
}
@Override
protected void execute(Event e) {
String schem = schematic.getSingle(e);
Location loc = location.getSingle(e);
EditSession session = editSession.getSingle(e);
Vector origin = BukkitUtil.toVector(loc);
boolean noAir = false;
if (mark == 1)
noAir = true;
File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic")));
if (!schemFile.exists() || session == null)
return;
try {
SchematicFormat.getFormat(schemFile).load(schemFile).paste(session, origin, noAir);
} catch (MaxChangedBlocksException | DataException | IOException ex) {
if (ex instanceof MaxChangedBlocksException)
return;
ex.printStackTrace();
}
}
}

View File

@ -27,8 +27,8 @@ public class EffRememberChanges extends Effect {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "make " + player.toString(e, false) + " remember changes from edit session";
public String toString(@Nullable Event e, boolean debug) {
return "make " + player.toString(e, debug) + " remember changes from edit session";
}
@Override

View File

@ -6,8 +6,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.Spider;
import org.bukkit.event.Event;
import ch.njol.skript.lang.Effect;
@ -21,33 +24,8 @@ public class EffRemovePathGoal extends Effect {
private int mark;
private Class<?> goalSelectorClass = ReflectionUtils.getNMSClass("PathfinderGoalSelector", false);
private Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget", false);
private Class<?> goalBreed = ReflectionUtils.getNMSClass("PathfinderGoalBreed", false);
private Class<?> goalBreakDoor = ReflectionUtils.getNMSClass("PathfinderGoalBreakDoor", false);
private Class<?> goalEatGrass = ReflectionUtils.getNMSClass("PathfinderGoalEatTile", false);
private Class<?> goalFleeSun = ReflectionUtils.getNMSClass("PathfinderGoalFleeSun", false);
private Class<?> goalFloat = ReflectionUtils.getNMSClass("PathfinderGoalFloat", false);
private Class<?> goalFollowOwner = ReflectionUtils.getNMSClass("PathfinderGoalFollowOwner", false);
private Class<?> goalFollowAdults = ReflectionUtils.getNMSClass("PathfinderGoalFollowParent", false);
private Class<?> goalReactAttack = ReflectionUtils.getNMSClass("PathfinderGoalHurtByTarget", false);
private Class<?> goalJumpOnBlock = ReflectionUtils.getNMSClass("PathfinderGoalJumpOnBlock", false);
private Class<?> goalLeapTarget = ReflectionUtils.getNMSClass("PathfinderGoalLeapAtTarget", false);
private Class<?> goalLookEntities = ReflectionUtils.getNMSClass("PathfinderGoalLookAtPlayer", false);
private Class<?> goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack", false);
private Class<?> goalGotoTarget = ReflectionUtils.getNMSClass("PathfinderGoalMoveTowardsTarget", false);
private Class<?> goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget", false);
private Class<?> goalOcelotAttack = ReflectionUtils.getNMSClass("PathfinderGoalOcelotAttack", false);
private Class<?> goalOpenDoors = ReflectionUtils.getNMSClass("PathfinderGoalOpenDoor", false);
private Class<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic", false);
private Class<?> goalRandomLook = ReflectionUtils.getNMSClass("PathfinderGoalRandomLookaround", false);
private Class<?> goalWander = ReflectionUtils.getNMSClass("PathfinderGoalRandomStroll", false);
private Class<?> goalSit = ReflectionUtils.getNMSClass("PathfinderGoalSit", false);
private Class<?> goalSwell = ReflectionUtils.getNMSClass("PathfinderGoalSwell", false);
private Class<?> 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")
@ -59,11 +37,10 @@ public class EffRemovePathGoal extends Effect {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "remove pathfind goal of " + entity.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "remove pathfinder goal from " + entity.toString(e, debug);
}
@SuppressWarnings({ "unused" })
@Override
protected void execute(Event e) {
LivingEntity ent = entity.getSingle(e);
@ -75,79 +52,146 @@ public class EffRemovePathGoal extends Effect {
Object goalSelector = ReflectionUtils.getField("goalSelector", entInsent, nmsEnt);
Object targetSelector = ReflectionUtils.getField("targetSelector", entInsent, nmsEnt);
Object toRemove = null;
boolean target = false;
if (mark == 0) {
Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget", false);
toRemove = goalAvoid;
} else if (mark == 1) {
Class<?> goalBreakDoor = ReflectionUtils.getNMSClass("PathfinderGoalBreakDoor", false);
toRemove = goalBreakDoor;
} else if (mark == 2) {
Class<?> goalBreed = ReflectionUtils.getNMSClass("PathfinderGoalBreed", false);
toRemove = goalBreed;
} else if (mark == 3) {
Class<?> goalEatGrass = ReflectionUtils.getNMSClass("PathfinderGoalEatTile", false);
toRemove = goalEatGrass;
} else if (mark == 4) {
Class<?> goalFleeSun = ReflectionUtils.getNMSClass("PathfinderGoalFleeSun", false);
toRemove = goalFleeSun;
} else if (mark == 5) {
Class<?> goalFloat = ReflectionUtils.getNMSClass("PathfinderGoalFloat", false);
toRemove = goalFloat;
} else if (mark == 6) {
Class<?> goalFollowOwner = ReflectionUtils.getNMSClass("PathfinderGoalFollowOwner", false);
toRemove = goalFollowOwner;
} else if (mark == 7) {
Class<?> goalFollowAdults = ReflectionUtils.getNMSClass("PathfinderGoalFollowParent", false);
toRemove = goalFollowAdults;
} else if (mark == 8) {
target = true;
Class<?> goalReactAttack = ReflectionUtils.getNMSClass("PathfinderGoalHurtByTarget", false);
toRemove = goalReactAttack;
} else if (mark == 9) {
Class<?> goalJumpOnBlock = ReflectionUtils.getNMSClass("PathfinderGoalJumpOnBlock", false);
toRemove = goalJumpOnBlock;
} else if (mark == 10) {
Class<?> goalLeapTarget = ReflectionUtils.getNMSClass("PathfinderGoalLeapAtTarget", false);
toRemove = goalLeapTarget;
} else if (mark == 11) {
Class<?> goalLookEntities = ReflectionUtils.getNMSClass("PathfinderGoalLookAtPlayer", false);
toRemove = goalLookEntities;
} else if (mark == 12) {
if (ent instanceof Spider) {
Class<?> goalSpiderMelee = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderMeleeAttack", false);
toRemove = goalSpiderMelee;
} else {
Class<?> goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack", false);
toRemove = goalMeleeAttack;
}
} else if (mark == 13) {
if (ent instanceof Ghast) {
Class<?> goalGhastGotoTarget = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalMoveTowardsTarget", false);
toRemove = goalGhastGotoTarget;
} else {
Class<?> goalGotoTarget = ReflectionUtils.getNMSClass("PathfinderGoalMoveTowardsTarget", false);
toRemove = goalGotoTarget;
}
} else if (mark == 14) {
target = true;
if (ent instanceof Spider) {
Class<?> goalSpiderNearTarget = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderNearestAttackableTarget", false);
toRemove = goalSpiderNearTarget;
} else {
Class<?> goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget", false);
toRemove = goalNearTarget;
}
} else if (mark == 15) {
Class<?> goalOcelotAttack = ReflectionUtils.getNMSClass("PathfinderGoalOcelotAttack", false);
toRemove = goalOcelotAttack;
} else if (mark == 16) {
Class<?> goalOpenDoors = ReflectionUtils.getNMSClass("PathfinderGoalOpenDoor", false);
toRemove = goalOpenDoors;
} else if (mark == 17) {
Class<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic", false);
toRemove = goalPanic;
} else if (mark == 18) {
Class<?> goalRandomLook = ReflectionUtils.getNMSClass("PathfinderGoalRandomLookaround", false);
toRemove = goalRandomLook;
} else if (mark == 19) {
Class<?> goalWander = ReflectionUtils.getNMSClass("PathfinderGoalRandomStroll", false);
toRemove = goalWander;
} else if (mark == 20) {
Class<?> goalSit = ReflectionUtils.getNMSClass("PathfinderGoalSit", false);
toRemove = goalSit;
} else if (mark == 21) {
Class<?> goalSwell = ReflectionUtils.getNMSClass("PathfinderGoalSwell", false);
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;
}
}
Class<?> goalSquid = ReflectionUtils.getNMSClass("EntitySquid$PathfinderGoalSquid", false);
toRemove = goalSquid;
} 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 (ent instanceof Blaze) {
Class<?> goalBlazeFireball = ReflectionUtils.getNMSClass("EntityBlaze$PathfinderGoalBlazeFireball", false);
toRemove = goalBlazeFireball;
} else if (ent instanceof Ghast) {
Class<?> goalGhastFireball = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastAttackTarget", false);
toRemove = goalGhastFireball;
}
} else if (mark == 24) {
Class<?> goalHideInBlock = ReflectionUtils.getNMSClass("EntitySilverfish$PathfinderGoalSilverfishHideInBlock", false);
toRemove = goalHideInBlock;
} else if (mark == 25) {
Class<?> goalWakeSilverfish = ReflectionUtils.getNMSClass("EntitySilverfish$PathfinderGoalSilverfishWakeOthers", false);
toRemove = goalWakeSilverfish;
} else if (mark == 26) {
Class<?> goalPickBlocks = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalEndermanPickupBlock", false);
toRemove = goalPickBlocks;
} else if (mark == 27) {
Class<?> goalPlaceBlocks = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalEndermanPlaceBlock", false);
toRemove = goalPlaceBlocks;
} else if (mark == 28) {
target = true;
Class<?> goalAttackLooker = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget", false);
toRemove = goalAttackLooker;
} else if (mark == 29) {
Class<?> goalGhastMoveTarget = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastMoveTowardsTarget", false);
toRemove = goalGhastMoveTarget;
} else if (mark == 30) {
Class<?> goalGhastIdleMove = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastIdleMove", false);
toRemove = goalGhastIdleMove;
}
if (toRemove == null)
return;
Class<?> goalSelectorClass = ReflectionUtils.getNMSClass("PathfinderGoalSelector", false);
if (target) {
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();
}
}
} else {
Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", goalSelectorClass, goalSelector)).iterator();
Iterator<?> goalPriorities = ((List<?>) ReflectionUtils.getField("c", goalSelectorClass, goalSelector)).iterator();
while (goals.hasNext()) {
Object o = goals.next();
goalPriorities.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();
goalPriorities.remove();
}
}
}
} catch (Exception ex) {

View File

@ -43,8 +43,8 @@ public class EffReplaceBlocksWE extends Effect {
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "replace all " + blockList1.toString(e, false) + " from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " with " + blockList1.toString(e, false) + " using an edit session";
public String toString(@Nullable Event e, boolean debug) {
return "replace all " + blockList1.toString(e, debug) + " from " + location1.toString(e, debug) + " to " + location2.toString(e, debug) + " with " + blockList1.toString(e, debug) + " using an edit session";
}
@SuppressWarnings({ "deprecation" })

View File

@ -38,8 +38,8 @@ public class EffSetBlocksWE extends Effect {
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "set all blocks from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " to " + blockList.toString(e, false) + " using an edit session";
public String toString(@Nullable Event e, boolean debug) {
return "set all blocks from " + location1.toString(e, debug) + " to " + location2.toString(e, debug) + " to " + blockList.toString(e, debug) + " using an edit session";
}
@SuppressWarnings("deprecation")

View File

@ -1,14 +1,20 @@
package me.TheBukor.SkStuff.effects;
import java.lang.reflect.Constructor;
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.Enderman;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
import org.bukkit.entity.Silverfish;
import org.bukkit.entity.Spider;
import org.bukkit.entity.Squid;
import org.bukkit.entity.Tameable;
import org.bukkit.event.Event;
@ -48,31 +54,6 @@ public class EffSetPathGoal extends Effect {
private int mark;
private Class<?> goal = ReflectionUtils.getNMSClass("PathfinderGoal", false);
private Class<?> goalSelector = ReflectionUtils.getNMSClass("PathfinderGoalSelector", false);
private Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget", false);
private Class<?> goalBreed = ReflectionUtils.getNMSClass("PathfinderGoalBreed", false);
private Class<?> goalBreakDoor = ReflectionUtils.getNMSClass("PathfinderGoalBreakDoor", false);
private Class<?> goalEatGrass = ReflectionUtils.getNMSClass("PathfinderGoalEatTile", false);
private Class<?> goalFleeSun = ReflectionUtils.getNMSClass("PathfinderGoalFleeSun", false);
private Class<?> goalFloat = ReflectionUtils.getNMSClass("PathfinderGoalFloat", false);
private Class<?> goalFollowOwner = ReflectionUtils.getNMSClass("PathfinderGoalFollowOwner", false);
private Class<?> goalFollowAdults = ReflectionUtils.getNMSClass("PathfinderGoalFollowParent", false);
private Class<?> goalReactAttack = ReflectionUtils.getNMSClass("PathfinderGoalHurtByTarget", false);
private Class<?> goalJumpOnBlock = ReflectionUtils.getNMSClass("PathfinderGoalJumpOnBlock", false);
private Class<?> goalLeapTarget = ReflectionUtils.getNMSClass("PathfinderGoalLeapAtTarget", false);
private Class<?> goalLookEntities = ReflectionUtils.getNMSClass("PathfinderGoalLookAtPlayer", false);
private Class<?> goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack", false);
private Class<?> goalGotoTarget = ReflectionUtils.getNMSClass("PathfinderGoalMoveTowardsTarget", false);
private Class<?> goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget", false);
private Class<?> goalOcelotAttack = ReflectionUtils.getNMSClass("PathfinderGoalOcelotAttack", false);
private Class<?> goalOpenDoors = ReflectionUtils.getNMSClass("PathfinderGoalOpenDoor", false);
private Class<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic", false);
private Class<?> goalRandomLook = ReflectionUtils.getNMSClass("PathfinderGoalRandomLookaround", false);
private Class<?> goalWander = ReflectionUtils.getNMSClass("PathfinderGoalRandomStroll", false);
private Class<?> goalSit = ReflectionUtils.getNMSClass("PathfinderGoalSit", false);
private Class<?> goalSwell = ReflectionUtils.getNMSClass("PathfinderGoalSwell", false);
private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity");
private Class<?> entAnimal = ReflectionUtils.getNMSClass("EntityAnimal", false);
private Class<?> entCreature = ReflectionUtils.getNMSClass("EntityCreature", false);
@ -125,8 +106,8 @@ public class EffSetPathGoal extends Effect {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "add pathfinder goal to ent";
public String toString(@Nullable Event e, boolean debug) {
return "add pathfinder goal to entity";
}
@SuppressWarnings("deprecation")
@ -136,26 +117,26 @@ public class EffSetPathGoal extends Effect {
if (goalPriority != null) {
priority = goalPriority.getSingle(e).intValue();
} else {
priority = 1;
priority = 4;
}
if (priority < 0) {
if (priority < 1) {
priority = 1;
} else if (priority > 9) {
priority = 9;
}
LivingEntity ent = entity.getSingle(e);
if (ent instanceof Player || ent == null)
if (ent == null ||ent instanceof Player)
return;
Object obcEnt = craftLivEnt.cast(ent);
Object nmsEnt = null;
Class<?> clazz = null;
try {
Object nmsEnt = null;
boolean target = false;
Object newGoal = null;
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) {
Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget", false);
float radius = avoidRadius.getSingle(e).floatValue();
double spd1 = avoidSpeed1.getSingle(e).doubleValue();
double spd2 = avoidSpeed2.getSingle(e).doubleValue();
@ -165,6 +146,9 @@ public class EffSetPathGoal extends Effect {
exprInput = exprInput.substring(4);
}
entityData = EntityData.parseWithoutIndefiniteArticle(exprInput);
if (!LivingEntity.class.isAssignableFrom(entityData.getType())) {
return;
}
String className = entityData.getType().getSimpleName();
if (className.equals("HumanEntity"))
className = "Human";
@ -174,43 +158,47 @@ public class EffSetPathGoal extends Effect {
return;
newGoal = goalAvoid.getConstructor(entCreature, Class.class, float.class, double.class, double.class).newInstance(nmsEnt, nmsClass, radius, spd1, spd2);
} else if (mark == 1) {
Class<?> goalBreakDoor = ReflectionUtils.getNMSClass("PathfinderGoalBreakDoor", false);
newGoal = goalBreakDoor.getConstructor(entInsent).newInstance(nmsEnt);
} else if (mark == 2) {
Class<?> goalBreed = ReflectionUtils.getNMSClass("PathfinderGoalBreed", false);
double spd = breedSpeed.getSingle(e).doubleValue();
if (!(ent instanceof Animals)) {
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not an animal - \u00A7e[DEBUG MESSAGE]");
if (!(ent instanceof Animals))
return;
}
newGoal = goalBreed.getConstructor(entAnimal, double.class).newInstance(nmsEnt, spd);
} else if (mark == 3) {
Class<?> goalEatGrass = ReflectionUtils.getNMSClass("PathfinderGoalEatTile", false);
newGoal = goalEatGrass.getConstructor(entInsent).newInstance(nmsEnt);
} else if (mark == 4) {
Class<?> goalFleeSun = ReflectionUtils.getNMSClass("PathfinderGoalFleeSun", false);
double spd = fleeSunSpeed.getSingle(e).doubleValue();
newGoal = goalFleeSun.getConstructor(entCreature, double.class).newInstance(nmsEnt, spd);
} else if (mark == 5) {
Class<?> goalFloat = ReflectionUtils.getNMSClass("PathfinderGoalFloat", false);
newGoal = goalFloat.getConstructor(entInsent).newInstance(nmsEnt);
} else if (mark == 6) {
Class<?> goalFollowOwner = ReflectionUtils.getNMSClass("PathfinderGoalFollowOwner", false);
double spd = followOwnerSpeed.getSingle(e).doubleValue();
if (!(ent instanceof Tameable)) {
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a tameable animal - \u00A7e[DEBUG MESSAGE]");
if (!(ent instanceof Tameable))
return;
}
newGoal = goalFollowOwner.getConstructor(entTameable, double.class, float.class, float.class).newInstance(nmsEnt, spd, 20.0F, 5.0F);
} else if (mark == 7) {
Class<?> goalFollowAdults = ReflectionUtils.getNMSClass("PathfinderGoalFollowParent", false);
double spd = followAdultsSpeed.getSingle(e).doubleValue();
if (!(ent instanceof Animals)) {
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not an animal - \u00A7e[DEBUG MESSAGE]");
if (!(ent instanceof Animals))
return;
}
newGoal = goalFollowAdults.getConstructor(entAnimal, double.class).newInstance(nmsEnt, spd);
} else if (mark == 8) {
target = true;
Class<?> goalReactAttack = ReflectionUtils.getNMSClass("PathfinderGoalHurtByTarget", false);
EntityData<?> entityData;
String exprInput = typesToFightBack.toString(e, false);
if (exprInput.startsWith("the ")) {
exprInput = exprInput.substring(4);
}
entityData = EntityData.parseWithoutIndefiniteArticle(exprInput);
if (!LivingEntity.class.isAssignableFrom(entityData.getType()))
return;
String className = entityData.getType().getSimpleName();
if (className.equals("HumanEntity"))
className = "Human";
@ -220,20 +208,25 @@ public class EffSetPathGoal extends Effect {
return;
newGoal = goalReactAttack.getConstructor(entCreature, boolean.class, Class[].class).newInstance(nmsEnt, false, nmsClass[0]);
} else if (mark == 9) {
Class<?> goalJumpOnBlock = ReflectionUtils.getNMSClass("PathfinderGoalJumpOnBlock", false);
double spd = jumpOnBlockSpeed.getSingle(e).doubleValue();
if (!(ent instanceof Ocelot))
return;
newGoal = goalJumpOnBlock.getConstructor(nmsEnt.getClass(), double.class).newInstance(nmsEnt, spd);
} else if (mark == 10) {
Class<?> goalLeapTarget = ReflectionUtils.getNMSClass("PathfinderGoalLeapAtTarget", false);
float height = leapHeight.getSingle(e).floatValue();
newGoal = goalLeapTarget.getConstructor(entInsent, float.class).newInstance(nmsEnt, height);
} else if (mark == 11) {
Class<?> goalLookEntities = ReflectionUtils.getNMSClass("PathfinderGoalLookAtPlayer", false);
EntityData<?> entityData;
String exprInput = lookType.toString(e, false);
if (exprInput.startsWith("the ")) {
exprInput = exprInput.substring(4);
}
entityData = EntityData.parseWithoutIndefiniteArticle(exprInput);
if (!LivingEntity.class.isAssignableFrom(entityData.getType()))
return;
String className = entityData.getType().getSimpleName();
if (className.equals("HumanEntity"))
className = "Human";
@ -250,6 +243,29 @@ public class EffSetPathGoal extends Effect {
exprInput = exprInput.substring(4);
}
entityData = EntityData.parseWithoutIndefiniteArticle(exprInput);
if (!LivingEntity.class.isAssignableFrom(entityData.getType()))
return;
if (ent instanceof Spider) {
Class<?>[] classes = nmsEnt.getClass().getDeclaredClasses();
Class<?> clazz = null;
for (Class<?> c : classes) {
Bukkit.broadcastMessage("Class name: \u00A7e" + c.getName());
if (c.getName().equals("PathfinderGoalSpiderMeleeAttack"))
clazz = c;
}
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
Constructor<?> constr = null;
for (Constructor<?> constructor : constructors) {
Bukkit.broadcastMessage("Constructor name: \u00A7a" + constructor.getName());
if (constructor.getName().equals("PathfinderGoalSpiderMeleeAttack"))
constr = constructor;
}
if (constr == null)
return;
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt, entityData);
} else {
Class<?> goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack", false);
String className = entityData.getType().getSimpleName();
if (className.equals("HumanEntity"))
className = "Human";
@ -259,7 +275,9 @@ public class EffSetPathGoal extends Effect {
return;
double spd = meleeSpeed.getSingle(e).doubleValue();
newGoal = goalMeleeAttack.getConstructor(entCreature, Class.class, double.class, boolean.class).newInstance(nmsEnt, nmsClass, spd, false);
}
} else if (mark == 13) {
Class<?> goalGotoTarget = ReflectionUtils.getNMSClass("PathfinderGoalMoveTowardsTarget", false);
double spd = moveTargetSpeed.getSingle(e).doubleValue();
float radius = moveTargetRadius.getSingle(e).floatValue();
newGoal = goalGotoTarget.getConstructor(entCreature, double.class, float.class).newInstance(nmsEnt, spd, radius);
@ -271,6 +289,15 @@ public class EffSetPathGoal extends Effect {
exprInput = exprInput.substring(4);
}
entityData = EntityData.parseWithoutIndefiniteArticle(exprInput);
if (!LivingEntity.class.isAssignableFrom(entityData.getType()))
return;
if (ent instanceof Spider) {
Class<?> goalSpiderNearTarget = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderNearestAttackableTarget", false);
Constructor<?> constr = goalSpiderNearTarget.getDeclaredConstructor(nmsEnt.getClass(), Class.class);
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt, entityData);
} else {
Class<?> goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget", false);
String className = entityData.getType().getSimpleName();
if (className.equals("HumanEntity"))
className = "Human";
@ -279,92 +306,130 @@ public class EffSetPathGoal extends Effect {
if (nmsClass == null)
return;
newGoal = goalNearTarget.getConstructor(entCreature, Class.class, boolean.class).newInstance(nmsEnt, nmsClass, false);
}
} else if (mark == 15) {
Class<?> goalOcelotAttack = ReflectionUtils.getNMSClass("PathfinderGoalOcelotAttack", false);
newGoal = goalOcelotAttack.getConstructor(entInsent).newInstance(nmsEnt);
} else if (mark == 16) {
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);
} else if (mark == 18) {
Class<?> goalRandomLook = ReflectionUtils.getNMSClass("PathfinderGoalRandomLookaround", false);
newGoal = goalRandomLook.getConstructor(entInsent).newInstance(nmsEnt);
} else if (mark == 19) {
Class<?> goalWander = ReflectionUtils.getNMSClass("PathfinderGoalRandomStroll", false);
double spd = randomWalkSpeed.getSingle(e).doubleValue();
int interval = randomWalkInterval.getSingle(e).getTicks();
newGoal = goalWander.getConstructor(entCreature, double.class, int.class).newInstance(nmsEnt, spd, interval);
} else if (mark == 20) {
if (!(ent instanceof Tameable)) {
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a tameable animal - \u00A7e[DEBUG MESSAGE]");
Class<?> goalSit = ReflectionUtils.getNMSClass("PathfinderGoalSit", false);
if (!(ent instanceof Tameable))
return;
}
newGoal = goalSit.getConstructor(entTameable).newInstance(nmsEnt);
} else if (mark == 21) {
if (!(ent instanceof Creeper)) {
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a creeper - \u00A7e[DEBUG MESSAGE]");
Class<?> goalSwell = ReflectionUtils.getNMSClass("PathfinderGoalSwell", false);
if (!(ent instanceof Creeper))
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]");
Class<?> goalSquid = ReflectionUtils.getNMSClass("EntitySquid$PathfinderGoalSquid", false);
if (!(ent instanceof Squid))
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);
Constructor<?> constr = goalSquid.getDeclaredConstructor(nmsEnt.getClass());
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt);
} else if (mark == 23) {
if (!(ent instanceof Blaze)) {
Bukkit.broadcastMessage("\u00A7c" + ent.getType().toString() + " is not a blaze - \u00A7e[DEBUG MESSAGE]");
return;
if (ent instanceof Blaze) {
Class<?> goalBlazeFireball = ReflectionUtils.getNMSClass("EntityBlaze$PathfinderGoalBlazeFireball", false);
Constructor<?> constr = goalBlazeFireball.getDeclaredConstructor(nmsEnt.getClass());
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt);
} else if (ent instanceof Ghast) {
Class<?> goalGhastFireball = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastAttackTarget", false);
Constructor<?> constr = goalGhastFireball.getDeclaredConstructor(nmsEnt.getClass());
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt);
}
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) {
Class<?> goalHideInBlock = ReflectionUtils.getNMSClass("EntitySilverfish$PathfinderGoalSilverfishHideInBlocks", false);
if (!(ent instanceof Silverfish))
return;
Constructor<?> constr = goalHideInBlock.getDeclaredConstructor(nmsEnt.getClass());
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt);
} else if (mark == 25) {
Class<?> goalWakeSilverfish = ReflectionUtils.getNMSClass("EntitySilverfish$PathfinderGoalSilverfishWakeOthers", false);
if (!(ent instanceof Silverfish))
return;
Constructor<?> constr = goalWakeSilverfish.getDeclaredConstructor(nmsEnt.getClass());
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt);
} else if (mark == 26) {
Class<?> goalPickBlocks = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalEndermanPickupBlock", false);
if (!(ent instanceof Enderman))
return;
Constructor<?> constr = goalPickBlocks.getDeclaredConstructor(nmsEnt.getClass());
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt);
} else if (mark == 27) {
Class<?> goalPlaceBlocks = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalEndermanPlaceBlock", false);
if (!(ent instanceof Enderman))
return;
Constructor<?> constr = goalPlaceBlocks.getDeclaredConstructor(nmsEnt.getClass());
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt);
} else if (mark == 28) {
target = true;
Class<?> goalAttackLooker = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget", false);
if (!(ent instanceof Enderman))
return;
Constructor<?> constr = goalAttackLooker.getDeclaredConstructor(nmsEnt.getClass());
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt);
} else if (mark == 29) {
Class<?> goalGhastMoveTarget = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastMoveTowardsTarget", false);
if (!(ent instanceof Ghast))
return;
Constructor<?> constr = goalGhastMoveTarget.getDeclaredConstructor(nmsEnt.getClass());
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt);
} else if (mark == 30) {
Class<?> goalGhastIdleMove = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastIdleMove", false);
if (!(ent instanceof Ghast))
return;
Constructor<?> constr = goalGhastIdleMove.getDeclaredConstructor(nmsEnt.getClass());
constr.setAccessible(true);
newGoal = constr.newInstance(nmsEnt);
} else if (mark == 31) {
// 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.
* ZPigMan, 2 goals, anger and anger other (adapted HurtByTarget to work with Anger tag)
*/
/* Goals to add:
* Tempt - Mob follows you with a certain item in hand (e.g cow follows wheat)
* AttackNonTamed - Used by ocelots, to attack chickens (maybe for wolves to attack sheep to?)
*/
}
if (newGoal == null)
return;
Class<?> goal = ReflectionUtils.getNMSClass("PathfinderGoal", false);
Class<?> goalSelector = ReflectionUtils.getNMSClass("PathfinderGoalSelector", false);
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 ex1) {
if (clazz != null)
try {
clazz.getConstructor(nmsEnt.getClass()).setAccessible(true);
} catch (SecurityException | NoSuchMethodException ex2) {
ex2.printStackTrace();
}
ex1.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@ -44,8 +44,8 @@ public class EffShowEntityEffect extends Effect {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "play entity effect " + toStringMark + "at" + entity.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "play entity effect " + toStringMark + "at" + entity.toString(e, debug);
}
@Override

View File

@ -29,8 +29,8 @@ public class EffSimulateSnow extends Effect {
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "make " + location.toString(e, false) + " snowy in a radius of " + radius.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "make " + location.toString(e, debug) + " snowy in a radius of " + radius.toString(e, debug);
}
@Override

View File

@ -31,8 +31,8 @@ public class EffToggleVanish extends Effect {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "toggle vanished state of " + player.toString(e, false) + toStringMark;
public String toString(@Nullable Event e, boolean debug) {
return "toggle vanished state of " + player.toString(e, debug) + toStringMark;
}
@Override

View File

@ -25,7 +25,7 @@ public class EffUndoRedoSession extends Effect {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
public String toString(@Nullable Event e, boolean debug) {
return (redo == true ? "redo " : "undo ") + "changes from edit session";
}

View File

@ -31,7 +31,7 @@ public class ExprChangedBlocksSession extends SimpleExpression<Integer> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
public String toString(@Nullable Event e, boolean debug) {
return "the number of changed blocks in an edit session";
}

View File

@ -0,0 +1,49 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.util.Kleenean;
public class ExprClickedInventory extends SimpleExpression<Inventory> {
@Override
public Class<? extends Inventory> getReturnType() {
return Inventory.class;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
if (!ScriptLoader.isCurrentEvent(InventoryClickEvent.class)) {
Skript.error("The expression clicked inventory can only be used in an on inventory click event", ErrorQuality.SEMANTIC_ERROR);
return false;
}
return true;
}
@Override
public String toString(@Nullable Event e, boolean debug) {
return "clicked inventory";
}
@Override
@Nullable
protected Inventory[] get(Event e) {
return new Inventory[] { ((InventoryClickEvent) e).getClickedInventory() };
}
}

View File

@ -38,7 +38,7 @@ public class ExprEditSessionLimit extends SimpleExpression<Integer> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
public String toString(@Nullable Event e, boolean debug) {
return "the block change limit of an edit session";
}

View File

@ -50,8 +50,8 @@ public class ExprFileNBT extends SimpleExpression<Object> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT from file " + input.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "the NBT from file " + input.toString(e, debug);
}
@Override

View File

@ -35,8 +35,8 @@ public class ExprFireProof extends SimpleExpression<Boolean> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "fireproof state of " + entity.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "fireproof state of " + entity.toString(e, debug);
}
@Override

View File

@ -45,8 +45,8 @@ public class ExprItemNBT extends SimpleExpression<ItemStack> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return itemStack.toString(e, false) + " with custom NBT " + string.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return itemStack.toString(e, debug) + " with custom NBT " + string.toString(e, debug);
}
@Override

View File

@ -51,8 +51,8 @@ public class ExprNBTOf extends SimpleExpression<Object> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of " + target.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "the NBT of " + target.toString(e, debug);
}
@Override

View File

@ -38,8 +38,8 @@ public class ExprNewEditSession extends SimpleExpression<EditSession> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "new edit session in world " + world.toString(e, false) + " with maximum block change limit of " + blockLimit.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "new edit session in world " + world.toString(e, debug) + " with maximum block change limit of " + blockLimit.toString(e, debug);
}
@Override

View File

@ -34,8 +34,8 @@ public class ExprNoClip extends SimpleExpression<Boolean> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "no clip state of " + entity.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "no clip state of " + entity.toString(e, debug);
}
@Override

View File

@ -52,8 +52,8 @@ public class ExprSchematicArea extends SimpleExpression<Integer> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the " + toStringMark + " of the schematic from " + schematic.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "the " + toStringMark + " of the schematic from " + schematic.toString(e, debug);
}
@SuppressWarnings("deprecation")

View File

@ -49,8 +49,8 @@ public class ExprSelectionArea extends SimpleExpression<Integer> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the " + toStringMark + " of the WorldEdit selection of " + player.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "the " + toStringMark + " of the WorldEdit selection of " + player.toString(e, debug);
}
@Override

View File

@ -44,8 +44,8 @@ public class ExprSelectionOfPlayer extends SimpleExpression<Location> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the WorldEdit selection of " + player.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "the WorldEdit selection of " + player.toString(e, debug);
}
@Override

View File

@ -49,8 +49,8 @@ public class ExprSelectionPos extends SimpleExpression<Location> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the WorldEdit point " + (usePos2 ? "2" : "1") + " selection of " + player.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "the WorldEdit point " + (usePos2 ? "2" : "1") + " selection of " + player.toString(e, debug);
}
@Override

View File

@ -35,8 +35,8 @@ public class ExprTagOf extends SimpleExpression<Object> {
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the tag " + string.toString(e, false) + " of compound";
public String toString(@Nullable Event e, boolean debug) {
return "the tag " + string.toString(e, debug) + " of compound";
}
@Override

View File

@ -46,8 +46,8 @@ public class ExprTimespanToNumber extends SimpleExpression<Number> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return time.toString(e, false) + "converted to " + toStringMark;
public String toString(@Nullable Event e, boolean debug) {
return time.toString(e, debug) + "converted to " + toStringMark;
}
@SuppressWarnings("deprecation")

View File

@ -30,8 +30,8 @@ public class ExprToLowerCase extends SimpleExpression<String> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "convert all characters in " + text.toString(e, false) + " to lowercase";
public String toString(@Nullable Event e, boolean debug) {
return "convert all characters in " + text.toString(e, debug) + " to lowercase";
}
@Override

View File

@ -30,8 +30,8 @@ public class ExprToUpperCase extends SimpleExpression<String> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "convert all characters in " + text.toString(e, false) + " to uppercase";
public String toString(@Nullable Event e, boolean debug) {
return "convert all characters in " + text.toString(e, debug) + " to uppercase";
}
@Override

View File

@ -35,8 +35,8 @@ public class ExprVanishState extends SimpleExpression<Boolean> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "vanish state of " + player.toString(e, false);
public String toString(@Nullable Event e, boolean debug) {
return "vanish state of " + player.toString(e, debug);
}
@Override

View File

@ -39,8 +39,8 @@ public class ExprWordsToUpperCase extends SimpleExpression<String> {
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "convert first character of each word in " + text.toString(e, false) + toStringEnd;
public String toString(@Nullable Event e, boolean debug) {
return "convert first character of each word in " + text.toString(e, debug) + toStringEnd;
}
@Override

View File

@ -41,10 +41,7 @@ public class ReflectionUtils {
f = clazz.getDeclaredField(field);
f.setAccessible(true);
obj = f.get(object);
f.setAccessible(false);
} catch (Exception ex) {
if (f != null)
f.setAccessible(false);
ex.printStackTrace();
}
return obj;
@ -56,10 +53,7 @@ public class ReflectionUtils {
f = clazz.getDeclaredField(field);
f.setAccessible(true);
f.set(object, toSet);
f.setAccessible(false);
} catch (Exception ex) {
if (f != null)
f.setAccessible(false);
ex.printStackTrace();
}
}