Hopefuly should work fine.

Updated to 1.9, moving from Reflection to a new method using and
Interface with useful NMS methods (some expressions are still using
Reflection).
This commit is contained in:
Richard 2016-03-03 22:01:19 -03:00
parent f3fcb59fa1
commit b0aa11475e
23 changed files with 4900 additions and 4238 deletions

View File

@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/plugins/Skript.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/plugins/Skript.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/plugins/WorldEdit.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/plugins/WorldEdit.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.7.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.7.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/VanishNoPacket.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/VanishNoPacket.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.10.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.10.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.3.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.3.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.9.jar"/>
</classpath> <classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,6 +1,6 @@
name: SkStuff name: SkStuff
author: TheBukor author: TheBukor
description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support. description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support.
version: 1.5.1 version: 1.6
main: me.TheBukor.SkStuff.SkStuff main: me.TheBukor.SkStuff.SkStuff
softdepend: [Skript, WorldEdit] softdepend: [Skript, WorldEdit]

View File

@ -1,219 +1,217 @@
package me.TheBukor.SkStuff; package me.TheBukor.SkStuff;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import ch.njol.skript.Skript; import ch.njol.skript.Skript;
import ch.njol.skript.classes.ClassInfo; import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.util.SimpleEvent; import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.Classes; import ch.njol.skript.registrations.Classes;
import ch.njol.skript.registrations.EventValues; import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter; import ch.njol.skript.util.Getter;
import me.TheBukor.SkStuff.conditions.CondSelectionContains; import me.TheBukor.SkStuff.conditions.CondSelectionContains;
import me.TheBukor.SkStuff.effects.EffClearPathGoals; import me.TheBukor.SkStuff.effects.EffClearPathGoals;
import me.TheBukor.SkStuff.effects.EffDrainLiquid; import me.TheBukor.SkStuff.effects.EffDrainLiquid;
import me.TheBukor.SkStuff.effects.EffDrawLineWE; import me.TheBukor.SkStuff.effects.EffDrawLineWE;
import me.TheBukor.SkStuff.effects.EffGZipFile; import me.TheBukor.SkStuff.effects.EffGZipFile;
import me.TheBukor.SkStuff.effects.EffMakeCylinder; import me.TheBukor.SkStuff.effects.EffMakeCylinder;
import me.TheBukor.SkStuff.effects.EffMakeJump; import me.TheBukor.SkStuff.effects.EffMakeJump;
import me.TheBukor.SkStuff.effects.EffMakePyramid; import me.TheBukor.SkStuff.effects.EffMakePyramid;
import me.TheBukor.SkStuff.effects.EffMakeSphere; import me.TheBukor.SkStuff.effects.EffMakeSphere;
import me.TheBukor.SkStuff.effects.EffMakeWalls; import me.TheBukor.SkStuff.effects.EffMakeWalls;
import me.TheBukor.SkStuff.effects.EffNaturalize; import me.TheBukor.SkStuff.effects.EffNaturalize;
import me.TheBukor.SkStuff.effects.EffPasteSchematic; import me.TheBukor.SkStuff.effects.EffPasteSchematic;
import me.TheBukor.SkStuff.effects.EffRememberChanges; import me.TheBukor.SkStuff.effects.EffRememberChanges;
import me.TheBukor.SkStuff.effects.EffRemovePathGoal; import me.TheBukor.SkStuff.effects.EffRemovePathGoal;
import me.TheBukor.SkStuff.effects.EffReplaceBlocksWE; import me.TheBukor.SkStuff.effects.EffReplaceBlocksWE;
import me.TheBukor.SkStuff.effects.EffSetBlocksWE; import me.TheBukor.SkStuff.effects.EffSetBlocksWE;
import me.TheBukor.SkStuff.effects.EffSetPathGoal; import me.TheBukor.SkStuff.effects.EffSetPathGoal;
import me.TheBukor.SkStuff.effects.EffShowEntityEffect; import me.TheBukor.SkStuff.effects.EffShowEntityEffect;
import me.TheBukor.SkStuff.effects.EffSimulateSnow; import me.TheBukor.SkStuff.effects.EffSimulateSnow;
import me.TheBukor.SkStuff.effects.EffToggleVanish; import me.TheBukor.SkStuff.effects.EffToggleVanish;
import me.TheBukor.SkStuff.effects.EffUndoRedoSession; import me.TheBukor.SkStuff.effects.EffUndoRedoSession;
import me.TheBukor.SkStuff.events.EvtWorldEditChange; import me.TheBukor.SkStuff.events.EvtWorldEditChange;
import me.TheBukor.SkStuff.events.WorldEditChangeHandler; import me.TheBukor.SkStuff.events.WorldEditChangeHandler;
import me.TheBukor.SkStuff.expressions.ExprChangedBlocksSession; import me.TheBukor.SkStuff.expressions.ExprChangedBlocksSession;
import me.TheBukor.SkStuff.expressions.ExprClickedInventory; import me.TheBukor.SkStuff.expressions.ExprClickedInventory;
import me.TheBukor.SkStuff.expressions.ExprEditSessionLimit; import me.TheBukor.SkStuff.expressions.ExprEditSessionLimit;
import me.TheBukor.SkStuff.expressions.ExprEndermanBlocks; import me.TheBukor.SkStuff.expressions.ExprEndermanBlocks;
import me.TheBukor.SkStuff.expressions.ExprFileNBT; import me.TheBukor.SkStuff.expressions.ExprFileNBT;
import me.TheBukor.SkStuff.expressions.ExprFireProof; import me.TheBukor.SkStuff.expressions.ExprFireProof;
import me.TheBukor.SkStuff.expressions.ExprItemNBT; import me.TheBukor.SkStuff.expressions.ExprItemNBT;
import me.TheBukor.SkStuff.expressions.ExprNBTListContents; import me.TheBukor.SkStuff.expressions.ExprNBTListContents;
import me.TheBukor.SkStuff.expressions.ExprNBTListIndex; import me.TheBukor.SkStuff.expressions.ExprNBTListIndex;
import me.TheBukor.SkStuff.expressions.ExprNBTOf; import me.TheBukor.SkStuff.expressions.ExprNBTOf;
import me.TheBukor.SkStuff.expressions.ExprNewEditSession; import me.TheBukor.SkStuff.expressions.ExprNewEditSession;
import me.TheBukor.SkStuff.expressions.ExprNoClip; import me.TheBukor.SkStuff.expressions.ExprNoClip;
import me.TheBukor.SkStuff.expressions.ExprSchematicArea; import me.TheBukor.SkStuff.expressions.ExprSchematicArea;
import me.TheBukor.SkStuff.expressions.ExprSelectionArea; import me.TheBukor.SkStuff.expressions.ExprSelectionArea;
import me.TheBukor.SkStuff.expressions.ExprSelectionOfPlayer; import me.TheBukor.SkStuff.expressions.ExprSelectionOfPlayer;
import me.TheBukor.SkStuff.expressions.ExprSelectionPos; import me.TheBukor.SkStuff.expressions.ExprSelectionPos;
import me.TheBukor.SkStuff.expressions.ExprTagOf; import me.TheBukor.SkStuff.expressions.ExprTagOf;
import me.TheBukor.SkStuff.expressions.ExprTimespanToNumber; import me.TheBukor.SkStuff.expressions.ExprTimespanToNumber;
import me.TheBukor.SkStuff.expressions.ExprToLowerCase; import me.TheBukor.SkStuff.expressions.ExprToLowerCase;
import me.TheBukor.SkStuff.expressions.ExprToUpperCase; import me.TheBukor.SkStuff.expressions.ExprToUpperCase;
import me.TheBukor.SkStuff.expressions.ExprVanishState; 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_R1;
import me.TheBukor.SkStuff.util.NMS_v1_8_R2; 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.ReflectionUtils; import me.TheBukor.SkStuff.util.NMS_v1_9_R1;
import me.TheBukor.SkStuff.util.ReflectionUtils;
public class SkStuff extends JavaPlugin {
private int condAmount = 0; public class SkStuff extends JavaPlugin {
private int effAmount = 0; private int condAmount = 0;
private int evtAmount = 0; private int effAmount = 0;
private int exprAmount = 0; private int evtAmount = 0;
private int typeAmount = 0; private int exprAmount = 0;
private int typeAmount = 0;
public static SkStuff instance;
private static NMSInterface nmsMethods;
private static NMSInterface nmsMethods;
public void onEnable() {
public void onEnable() { if (Bukkit.getPluginManager().getPlugin("Skript") != null && Skript.isAcceptRegistrations()) {
if (Bukkit.getPluginManager().getPlugin("Skript") != null && Skript.isAcceptRegistrations()) { Skript.registerAddon(this);
Skript.registerAddon(this); getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully enabled!");
getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully enabled!");
getLogger().info("Registering general non version specific stuff...");
getLogger().info("Registering general non version specific stuff..."); 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.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(ExprToUpperCase.class, String.class, ExpressionType.SIMPLE, "%string% [converted] to [all] (cap[ital]s|upper[ ]case)", "convert %string% to [all] (cap[ital]s|upper[ ]case)", "capitalize [all] [char[acter]s (of|in)] %string%");
Skript.registerExpression(ExprToUpperCase.class, String.class, ExpressionType.SIMPLE, "%string% [converted] to [all] (cap[ital]s|upper[ ]case)", "convert %string% to [all] (cap[ital]s|upper[ ]case)", "capitalize [all] [char[acter]s (of|in)] %string%"); 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(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(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)");
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)"); Skript.registerExpression(ExprClickedInventory.class, Inventory.class, ExpressionType.SIMPLE, "[skstuff] clicked inventory");
Skript.registerExpression(ExprClickedInventory.class, Inventory.class, ExpressionType.SIMPLE, "[skstuff] clicked inventory"); effAmount += 1;
effAmount += 1; exprAmount += 5;
exprAmount += 5;
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) %livingentity%");
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¦target nearest entity|15¦o(c|z)elot attack [chicken[s]]|16¦open door[s]|17¦(panic|flee)|18¦look around randomly|19¦(walk around randomly|wander)|20¦sit|21¦[creeper] (explode|inflate|swell)|22¦squid (swim|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦(wake other silverfish[es]|[silverfish] call (help|reinforcement|other [hidden] silverfish[es]))|26¦[enderm(a|e)n] pick[[ ]up] block[s]|27¦[enderm(a|e)n] place block[s]|28¦[enderman] attack player (staring|looking) [at eye[s]]|29¦ghast move to[wards] target|30¦ghast (idle move[ment]|wander|random fl(ight|y[ing]))|31¦(tempt to|follow players (holding|with)) [a[n]] item|32¦target [random] entity (if|when) (not tamed|untamed)|33¦guardian attack [entity]|34¦[z[ombie[ ]]pig[man]] attack [player[s]] (if|when) angry|35¦[z[ombie[ ]]pig[man]] (react to|fight back|target) (attacker|damager) (if|when) angry|36¦[rabbit] eat carrot crops|37¦[killer] rabbit [melee] attack|38¦slime [random] jump|39¦slime change (direction|facing) randomly|40¦slime (idle move[ment]|wander)) from %livingentity%");
Skript.registerEffect(EffRemovePathGoal.class, "remove pathfind[er] goal (0¦(avoid|run away from) entit(y|ies)|1¦break door[s]|2¦breed|3¦eat grass|4¦(flee from the sun|seek shad(e|ow))|5¦float (in[side]|on) water|6¦follow (owner|tamer)|7¦follow (adult|parent)[s]|8¦(fight back|react to|target) (damager|attacker)|9¦o(c|z)elot jump on blocks|10¦leap at target|11¦look at entit(y|ies)|12¦melee attack entit(y|ies)|13¦move to[wards] target|14¦target nearest entity|15¦o(c|z)elot attack [chicken[s]]|16¦open door[s]|17¦(panic|flee)|18¦look around randomly|19¦(walk around randomly|wander)|20¦sit|21¦[creeper] (explode|inflate|swell)|22¦squid (swim|wander)|23¦shoot fireball[s]|24¦[silverfish] hide (in[side]|on) block[s]|25¦(wake other silverfish[es]|[silverfish] call (help|reinforcement|other [hidden] silverfish[es]))|26¦[enderm(a|e)n] pick[[ ]up] block[s]|27¦[enderm(a|e)n] place block[s]|28¦[enderman] attack player (staring|looking) [at eye[s]]|29¦ghast move to[wards] target|30¦ghast (idle move[ment]|wander|random fl(ight|y[ing]))|31¦(tempt to|follow players (holding|with)) [a[n]] item|32¦target [random] entity (if|when) (not tamed|untamed)|33¦guardian attack [entity]|34¦[z[ombie[ ]]pig[man]] attack [player[s]] (if|when) angry|35¦[z[ombie[ ]]pig[man]] (react to|fight back|target) (attacker|damager) (if|when) angry|36¦[rabbit] eat carrot crops|37¦[killer] rabbit [melee] attack|38¦slime [random] jump|39¦slime change (direction|facing) randomly|40¦slime (idle move[ment]|wander)) from %livingentity%"); Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %entitydata%[, radius %-number%[, 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] %entitydata%[, 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 %entitydata%[, (radius|max[imum] distance) %-number%]|12¦melee attack %entitydata%[, [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] %entitydata%[, 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] %entitydata% (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 %livingentity%");
Skript.registerEffect(EffSetPathGoal.class, "add pathfind[er] goal [[with] priority %-integer%] (0¦(avoid|run away from) %entitydata%[, 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] %entitydata%[, 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 %entitydata%[, (radius|max[imum] distance) %-number%]|12¦melee attack %entitydata%[, [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] %entitydata%[, 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] %entitydata% (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 %livingentity%"); 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] %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]]"); Skript.registerExpression(ExprItemNBT.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%");
Skript.registerExpression(ExprItemNBT.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOf.class, Object.class, ExpressionType.PROPERTY, "[nbt[ ]]tag %string% of [[nbt] compound] %compound%");
Skript.registerExpression(ExprTagOf.class, Object.class, ExpressionType.PROPERTY, "[nbt[ ]]tag %string% of [[nbt] compound] %compound%"); Skript.registerExpression(ExprFileNBT.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%");
Skript.registerExpression(ExprFileNBT.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%"); Skript.registerExpression(ExprNBTListIndex.class, Object.class, ExpressionType.PROPERTY, "[nbt[ ]list] %nbtlist% index %number%");
Skript.registerExpression(ExprNBTListIndex.class, Object.class, ExpressionType.PROPERTY, "[nbt[ ]list] %nbtlist% index %number%"); Skript.registerExpression(ExprNBTListContents.class, Object.class, ExpressionType.PROPERTY, "[all] contents (of|from) [nbt[ ]list] %nbtlist%", "[nbt[ ]list] %nbtlist% contents");
Skript.registerExpression(ExprNBTListContents.class, Object.class, ExpressionType.PROPERTY, "[all] contents (of|from) [nbt[ ]list] %nbtlist%", "[nbt[ ]list] %nbtlist% contents"); Skript.registerExpression(ExprNoClip.class, Boolean.class, ExpressionType.PROPERTY, "no[( |-)]clip (state|mode) of %entities%", "%entities%'s no[( |-)]clip (state|mode)");
Skript.registerExpression(ExprNoClip.class, Boolean.class, ExpressionType.PROPERTY, "no[( |-)]clip (state|mode) of %entities%", "%entities%'s no[( |-)]clip (state|mode)"); Skript.registerExpression(ExprFireProof.class, Boolean.class, ExpressionType.PROPERTY, "fire[ ]proof (state|mode) of %entities%", "%entities%'s fire[ ]proof (state|mode)");
Skript.registerExpression(ExprFireProof.class, Boolean.class, ExpressionType.PROPERTY, "fire[ ]proof (state|mode) of %entities%", "%entities%'s fire[ ]proof (state|mode)"); Skript.registerExpression(ExprEndermanBlocks.class, ItemStack.class, ExpressionType.PROPERTY, "blocks that %entity% can (carry|hold|grab|steal)");
Skript.registerExpression(ExprEndermanBlocks.class, ItemStack.class, ExpressionType.PROPERTY, "blocks that %entity% can (carry|hold|grab|steal)"); nmsMethods.registerCompoundClassInfo();
nmsMethods.registerCompoundClassInfo(); nmsMethods.registerNBTListClassInfo();
nmsMethods.registerNBTListClassInfo(); effAmount += 5;
effAmount += 5; exprAmount += 9;
exprAmount += 9; typeAmount += 2;
typeAmount += 2; }
} if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) {
if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) { getLogger().info("WorldEdit found! Registering WorldEdit stuff...");
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%");
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%"); Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks% [with] thick[ness] %double%");
Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks% [with] thick[ness] %double%"); Skript.registerEffect(EffUndoRedoSession.class, "(0¦undo|1¦redo) (change|edit)s (of|from) [edit[ ]session] %editsession%");
Skript.registerEffect(EffUndoRedoSession.class, "(0¦undo|1¦redo) (change|edit)s (of|from) [edit[ ]session] %editsession%"); Skript.registerEffect(EffRememberChanges.class, "make %player% (remember|be able to undo) changes (of|from) [edit[ ]session] %editsession%");
Skript.registerEffect(EffRememberChanges.class, "make %player% (remember|be able to undo) changes (of|from) [edit[ ]session] %editsession%"); Skript.registerEffect(EffMakeSphere.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) (ellipsoid|sphere) [centered] at %location% [with] radius [of] %double%,[ ]%double%(,[ ]| and )%double% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%");
Skript.registerEffect(EffMakeSphere.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) (ellipsoid|sphere) [centered] at %location% [with] radius [of] %double%,[ ]%double%(,[ ]| and )%double% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%"); Skript.registerEffect(EffSimulateSnow.class, "(simulate snow at|place snow over) %location% (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%", "make %location% snowy (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%");
Skript.registerEffect(EffSimulateSnow.class, "(simulate snow at|place snow over) %location% (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%", "make %location% snowy (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%"); Skript.registerEffect(EffMakePyramid.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) pyramid at %location% [with] radius [of] %integer% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%");
Skript.registerEffect(EffMakePyramid.class, "(create|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) pyramid at %location% [with] radius [of] %integer% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%"); Skript.registerEffect(EffDrainLiquid.class, "(drain|remove) [all] liquid[s] at %location% (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%");
Skript.registerEffect(EffDrainLiquid.class, "(drain|remove) [all] liquid[s] at %location% (in|within) [a] radius [of] %double% (using|with) [edit[ ]session] %editsession%"); Skript.registerEffect(EffNaturalize.class, "naturalize ([cuboid] region|[all] blocks) (from|between) %location% (to|and) %location% (using|with) [edit[ ]session] %editsession%");
Skript.registerEffect(EffNaturalize.class, "naturalize ([cuboid] region|[all] blocks) (from|between) %location% (to|and) %location% (using|with) [edit[ ]session] %editsession%"); Skript.registerEffect(EffMakeWalls.class, "(create|make) wall[s] from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%");
Skript.registerEffect(EffMakeWalls.class, "(create|make) wall[s] from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks%"); Skript.registerEffect(EffSetBlocksWE.class, "set [all] blocks (from|between) %location% (to|and) %location% to %itemstacks% (using|with) [edit[ ]session] %editsession%");
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(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(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.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(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(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%");
Skript.registerExpression(ExprNewEditSession.class, EditSession.class, ExpressionType.PROPERTY, "[new] edit[ ]session in [world] %world% [with] [max[imum]] [block] limit [change] [of] %integer%"); Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection");
Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection"); Skript.registerExpression(ExprSelectionPos.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ](0¦1|1¦2) of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ](0¦1|1¦2)");
Skript.registerExpression(ExprSelectionPos.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ](0¦1|1¦2) of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ](0¦1|1¦2)"); Skript.registerExpression(ExprSelectionArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection (0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area)");
Skript.registerExpression(ExprSelectionArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection (0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area)"); Skript.registerExpression(ExprSchematicArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area) of schem[atic] [from] %string%");
Skript.registerExpression(ExprSchematicArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area) of schem[atic] [from] %string%"); Classes.registerClass(new ClassInfo<EditSession>(EditSession.class, "editsession").name("Edit Session").user("edit ?sessions?"));
Classes.registerClass(new ClassInfo<EditSession>(EditSession.class, "editsession").name("Edit Session").user("edit ?sessions?")); try {
try { Class.forName("com.sk89q.worldedit.extent.logging.AbstractLoggingExtent");
Class.forName("com.sk89q.worldedit.extent.logging.AbstractLoggingExtent"); new WorldEditChangeHandler();
new WorldEditChangeHandler(); Skript.registerEvent("WorldEdit block change", SimpleEvent.class, EvtWorldEditChange.class, "world[ ]edit [block] (chang(e|ing)|edit[ing])");
Skript.registerEvent("WorldEdit block change", SimpleEvent.class, EvtWorldEditChange.class, "world[ ]edit [block] (chang(e|ing)|edit[ing])"); EventValues.registerEventValue(EvtWorldEditChange.class, Player.class, new Getter<Player, EvtWorldEditChange>() {
EventValues.registerEventValue(EvtWorldEditChange.class, Player.class, new Getter<Player, EvtWorldEditChange>() { @Override
@Override @Nullable
@Nullable public Player get(EvtWorldEditChange e) {
public Player get(EvtWorldEditChange e) { return EvtWorldEditChange.getPlayer();
return EvtWorldEditChange.getPlayer(); }
} }, 0);
}, 0); EventValues.registerEventValue(EvtWorldEditChange.class, Block.class, new Getter<Block, EvtWorldEditChange>() {
EventValues.registerEventValue(EvtWorldEditChange.class, Block.class, new Getter<Block, EvtWorldEditChange>() { @Override
@Override @Nullable
@Nullable public Block get(EvtWorldEditChange e) {
public Block get(EvtWorldEditChange e) { return EvtWorldEditChange.getBlock();
return EvtWorldEditChange.getBlock(); }
} }, 0);
}, 0); evtAmount += 1;
evtAmount += 1; } catch (ClassNotFoundException ex) {
} catch (ClassNotFoundException ex) { Skript.error("Unable to register \"On WorldEdit block change\" event! You will need to upgrade to WorldEdit 6.0");
Skript.error("Unable to register \"On WorldEdit block change\" event! You will need to upgrade to WorldEdit 6.0"); return;
return; }
} condAmount += 1;
condAmount += 1; effAmount += 13;
effAmount += 13; exprAmount += 7;
exprAmount += 7; typeAmount += 1;
typeAmount += 1; }
} if (Bukkit.getPluginManager().getPlugin("VanishNoPacket") != null) {
if (Bukkit.getPluginManager().getPlugin("VanishNoPacket") != null) { getLogger().info("VanishNoPacket was found! Registering vanishing features...");
getLogger().info("VanishNoPacket was found! Registering vanishing features..."); Skript.registerEffect(EffToggleVanish.class, "toggle vanish (state|mode) of %player% (0¦|1¦(silently|quietly))", "toggle %player%'s vanish (state|mode) (0¦|1¦(silently|quietly))");
Skript.registerEffect(EffToggleVanish.class, "toggle vanish (state|mode) of %player% (0¦|1¦(silently|quietly))", "toggle %player%'s vanish (state|mode) (0¦|1¦(silently|quietly))"); Skript.registerExpression(ExprVanishState.class, Boolean.class, ExpressionType.PROPERTY, "vanish (state|mode) of %player%", "%player%'s vanish (state|mode)");
Skript.registerExpression(ExprVanishState.class, Boolean.class, ExpressionType.PROPERTY, "vanish (state|mode) of %player%", "%player%'s vanish (state|mode)"); effAmount += 1;
effAmount += 1; exprAmount += 1;
exprAmount += 1; }
} getLogger().info("Everything ready! Loaded a total of " + condAmount + " conditions, " + effAmount + " effects, " + evtAmount + "events, " + exprAmount + " expressions and " + typeAmount + " types!");
getLogger().info("Everything ready! Loaded a total of " + condAmount + " conditions, " + effAmount + " effects, " + evtAmount + "events, " + exprAmount + " expressions and " + typeAmount + " types!"); } else {
} else { getLogger().info("Unable to find Skript or Skript isn't accepting registrations, disabling SkStuff...");
getLogger().info("Unable to find Skript or Skript isn't accepting registrations, disabling SkStuff..."); Bukkit.getPluginManager().disablePlugin(this);;
Bukkit.getPluginManager().disablePlugin(this);; }
} }
}
private boolean setupNMSVersion() {
private boolean setupNMSVersion() { String version = ReflectionUtils.getVersion();
String version = ReflectionUtils.getVersion(); 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.")) {
} else if (version.equals("v1_8_R1.")) { nmsMethods = new NMS_v1_8_R1();
nmsMethods = new NMS_v1_8_R1(); getLogger().info("It looks like you're running 1.8.0!");
getLogger().info("It looks like you're running 1.8.0!"); } else if (version.equals("v1_8_R2.")) {
} else if (version.equals("v1_8_R2.")) { nmsMethods = new NMS_v1_8_R2();
nmsMethods = new NMS_v1_8_R2(); getLogger().info("It looks like you're running 1.8.3!");
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.7, 1.8.8 or 1.8.9!"); } else if (version.equals("v1_9_R1.")) {
} else { nmsMethods = new NMS_v1_9_R1();
getLogger().warning("It looks like you're running an unsupported server version, some features will not be available :("); getLogger().info("It looks like you're running 1.9.0!");
} } else {
return nmsMethods != null; getLogger().warning("It looks like you're running an unsupported server version, some features will not be available :(");
} }
return nmsMethods != null;
public static SkStuff getInstance() { }
return instance;
} public static NMSInterface getNMSMethods() {
return nmsMethods;
public static NMSInterface getNMSMethods() { }
return nmsMethods;
} public void onDisable() {
getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully disabled.");
public void onDisable() { }
getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully disabled.");
}
} }

View File

@ -1,54 +1,54 @@
package me.TheBukor.SkStuff.effects; package me.TheBukor.SkStuff.effects;
import java.util.List; import java.util.List;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import me.TheBukor.SkStuff.util.ReflectionUtils; import me.TheBukor.SkStuff.util.ReflectionUtils;
public class EffClearPathGoals extends Effect { public class EffClearPathGoals extends Effect {
private Expression<LivingEntity> entity; private Expression<LivingEntity> entity;
private Class<?> goalSelectorClass = ReflectionUtils.getNMSClass("PathfinderGoalSelector", false); private Class<?> goalSelectorClass = ReflectionUtils.getNMSClass("PathfinderGoalSelector");
private Class<?> insentientEnt = ReflectionUtils.getNMSClass("EntityInsentient", false); private Class<?> insentientEnt = ReflectionUtils.getNMSClass("EntityInsentient");
private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity"); private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity");
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
entity = (Expression<LivingEntity>) expr[0]; entity = (Expression<LivingEntity>) expr[0];
return true; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean debug) { public String toString(@Nullable Event e, boolean debug) {
return "clear all pathfinder goals from " + entity.toString(e, debug); return "clear all pathfinder goals from " + entity.toString(e, debug);
} }
@Override @Override
protected void execute(Event e) { protected void execute(Event e) {
LivingEntity ent = entity.getSingle(e); LivingEntity ent = entity.getSingle(e);
if (ent instanceof Player || ent == null) if (ent instanceof Player || ent == null)
return; return;
Object obcEnt = craftLivEnt.cast(ent); Object obcEnt = craftLivEnt.cast(ent);
try { try {
Object nmsEnt = insentientEnt.cast(obcEnt.getClass().getMethod("getHandle").invoke(obcEnt)); Object nmsEnt = insentientEnt.cast(obcEnt.getClass().getMethod("getHandle").invoke(obcEnt));
Object goalSelector = ReflectionUtils.getField("goalSelector", insentientEnt, nmsEnt); Object goalSelector = ReflectionUtils.getField("goalSelector", insentientEnt, nmsEnt);
Object targetSelector = ReflectionUtils.getField("targetSelector", insentientEnt, nmsEnt); Object targetSelector = ReflectionUtils.getField("targetSelector", insentientEnt, nmsEnt);
((List<?>) ReflectionUtils.getField("b", goalSelectorClass, goalSelector)).clear(); ((List<?>) ReflectionUtils.getField("b", goalSelectorClass, goalSelector)).clear();
((List<?>) ReflectionUtils.getField("c", goalSelectorClass, goalSelector)).clear(); ((List<?>) ReflectionUtils.getField("c", goalSelectorClass, goalSelector)).clear();
((List<?>) ReflectionUtils.getField("b", goalSelectorClass, targetSelector)).clear(); ((List<?>) ReflectionUtils.getField("b", goalSelectorClass, targetSelector)).clear();
((List<?>) ReflectionUtils.getField("c", goalSelectorClass, targetSelector)).clear(); ((List<?>) ReflectionUtils.getField("c", goalSelectorClass, targetSelector)).clear();
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} }

View File

@ -1,56 +1,49 @@
package me.TheBukor.SkStuff.effects; package me.TheBukor.SkStuff.effects;
import java.io.EOFException; import java.io.EOFException;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
public class EffGZipFile extends Effect { public class EffGZipFile extends Effect {
private Expression<String> filePath; private Expression<String> filePath;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
filePath = (Expression<String>) expr[0]; filePath = (Expression<String>) expr[0];
return true; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean debug) { public String toString(@Nullable Event e, boolean debug) {
return "create GZipped file at " + filePath.toString(e, debug); return "create GZipped file at path " + filePath.toString(e, debug);
} }
@Override @Override
protected void execute(Event e) { protected void execute(Event e) {
File newFile = new File(filePath.getSingle(e)); File newFile = new File(filePath.getSingle(e));
/* if (!newFile.exists()) {
if (!newFile.exists()) { try {
try { new GZIPOutputStream(new FileOutputStream(newFile)).close();
newFile.createNewFile(); } catch (FileNotFoundException ex) {
} catch (IOException ex) { ex.printStackTrace();
ex.printStackTrace(); } catch (IOException ex) {
} if (!(ex instanceof EOFException)) {
} ex.printStackTrace();
*/ }
try { }
new GZIPOutputStream(new FileOutputStream(newFile)).close(); }
} catch (FileNotFoundException ex) { }
ex.printStackTrace(); }
} catch (IOException ex) {
if (!(ex instanceof EOFException)) {
ex.printStackTrace();
}
}
}
}

View File

@ -1,51 +1,51 @@
package me.TheBukor.SkStuff.effects; package me.TheBukor.SkStuff.effects;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import me.TheBukor.SkStuff.util.ReflectionUtils; import me.TheBukor.SkStuff.util.ReflectionUtils;
public class EffMakeJump extends Effect { public class EffMakeJump extends Effect {
private Expression<LivingEntity> entities; private Expression<LivingEntity> entities;
private Class<?> entInsent = ReflectionUtils.getNMSClass("EntityInsentient", false); private Class<?> entInsent = ReflectionUtils.getNMSClass("EntityInsentient");
private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity"); private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity");
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
entities = (Expression<LivingEntity>) expr[0]; entities = (Expression<LivingEntity>) expr[0];
return true; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean debug) { public String toString(@Nullable Event e, boolean debug) {
return "make " + entities.toString(e, debug) + " jump"; return "make " + entities.toString(e, debug) + " jump";
} }
@Override @Override
protected void execute(Event e) { protected void execute(Event e) {
LivingEntity[] ents = entities.getAll(e); LivingEntity[] ents = entities.getAll(e);
for (Entity ent : ents) { for (Entity ent : ents) {
if (ent == null || ent instanceof Player || ent instanceof ArmorStand) if (ent == null || ent instanceof Player || ent instanceof ArmorStand)
continue; continue;
Object obcEnt = craftLivEnt.cast(ent); Object obcEnt = craftLivEnt.cast(ent);
try { try {
Object nmsEnt = entInsent.cast(obcEnt.getClass().getMethod("getHandle").invoke(obcEnt)); Object nmsEnt = entInsent.cast(obcEnt.getClass().getMethod("getHandle").invoke(obcEnt));
Object controllerJump = nmsEnt.getClass().getMethod("getControllerJump").invoke(nmsEnt); Object controllerJump = nmsEnt.getClass().getMethod("getControllerJump").invoke(nmsEnt);
controllerJump.getClass().getMethod("a").invoke(controllerJump); controllerJump.getClass().getMethod("a").invoke(controllerJump);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} }
} }

View File

@ -1,256 +1,235 @@
package me.TheBukor.SkStuff.effects; package me.TheBukor.SkStuff.effects;
import java.util.Iterator; import javax.annotation.Nullable;
import java.util.List;
import org.bukkit.entity.Blaze;
import javax.annotation.Nullable; import org.bukkit.entity.Creature;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Blaze; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Creature; import org.bukkit.entity.Player;
import org.bukkit.entity.Ghast; import org.bukkit.entity.Rabbit;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Spider;
import org.bukkit.entity.Player; import org.bukkit.event.Event;
import org.bukkit.entity.Rabbit;
import org.bukkit.entity.Spider; import ch.njol.skript.lang.Effect;
import org.bukkit.event.Event; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.Effect; import ch.njol.util.Kleenean;
import ch.njol.skript.lang.Expression; import me.TheBukor.SkStuff.SkStuff;
import ch.njol.skript.lang.SkriptParser.ParseResult; import me.TheBukor.SkStuff.util.ReflectionUtils;
import ch.njol.util.Kleenean;
import me.TheBukor.SkStuff.util.ReflectionUtils; public class EffRemovePathGoal extends Effect {
private Expression<LivingEntity> entity;
public class EffRemovePathGoal extends Effect {
private Expression<LivingEntity> entity; private int mark;
private int mark; private Class<?> entInsent = ReflectionUtils.getNMSClass("EntityInsentient");
private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity");
private Class<?> entInsent = ReflectionUtils.getNMSClass("EntityInsentient", false);
private Class<?> craftLivEnt = ReflectionUtils.getOBCClass("entity.CraftLivingEntity"); @SuppressWarnings("unchecked")
@Override
@SuppressWarnings("unchecked") public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
@Override mark = result.mark;
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { entity = (Expression<LivingEntity>) expr[0];
mark = result.mark; return true;
entity = (Expression<LivingEntity>) expr[0]; }
return true;
} @Override
public String toString(@Nullable Event e, boolean debug) {
@Override return "remove pathfinder goal from " + entity.toString(e, debug);
public String toString(@Nullable Event e, boolean debug) { }
return "remove pathfinder goal from " + entity.toString(e, debug);
} @Override
protected void execute(Event e) {
@Override LivingEntity ent = entity.getSingle(e);
protected void execute(Event e) { if (ent instanceof Player || ent == null)
LivingEntity ent = entity.getSingle(e); return;
if (ent instanceof Player || ent == null) Object obcEnt = craftLivEnt.cast(ent);
return; try {
Object obcEnt = craftLivEnt.cast(ent); Object nmsEnt = entInsent.cast(obcEnt.getClass().getMethod("getHandle").invoke(obcEnt));
try { Class<?> toRemove = null;
Object nmsEnt = entInsent.cast(obcEnt.getClass().getMethod("getHandle").invoke(obcEnt)); boolean target = false;
Object goalSelector = ReflectionUtils.getField("goalSelector", entInsent, nmsEnt); boolean resetGoalTarget = false;
Object targetSelector = ReflectionUtils.getField("targetSelector", entInsent, nmsEnt); if (mark == 0) {
Object toRemove = null; if (ent instanceof Rabbit) {
boolean target = false; Class<?> goalRabbitAvoid = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalRabbitAvoidTarget");
boolean resetGoalTarget = false; toRemove = goalRabbitAvoid;
if (mark == 0) { } else {
if (ent instanceof Rabbit) { Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget");
Class<?> goalRabbitAvoid = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalRabbitAvoidTarget", false); toRemove = goalAvoid;
toRemove = goalRabbitAvoid; }
} else { } else if (mark == 1) {
Class<?> goalAvoid = ReflectionUtils.getNMSClass("PathfinderGoalAvoidTarget", false); Class<?> goalBreakDoor = ReflectionUtils.getNMSClass("PathfinderGoalBreakDoor");
toRemove = goalAvoid; toRemove = goalBreakDoor;
} } else if (mark == 2) {
} else if (mark == 1) { Class<?> goalBreed = ReflectionUtils.getNMSClass("PathfinderGoalBreed");
Class<?> goalBreakDoor = ReflectionUtils.getNMSClass("PathfinderGoalBreakDoor", false); toRemove = goalBreed;
toRemove = goalBreakDoor; } else if (mark == 3) {
} else if (mark == 2) { Class<?> goalEatGrass = ReflectionUtils.getNMSClass("PathfinderGoalEatTile");
Class<?> goalBreed = ReflectionUtils.getNMSClass("PathfinderGoalBreed", false); toRemove = goalEatGrass;
toRemove = goalBreed; } else if (mark == 4) {
} else if (mark == 3) { Class<?> goalFleeSun = ReflectionUtils.getNMSClass("PathfinderGoalFleeSun");
Class<?> goalEatGrass = ReflectionUtils.getNMSClass("PathfinderGoalEatTile", false); toRemove = goalFleeSun;
toRemove = goalEatGrass; } else if (mark == 5) {
} else if (mark == 4) { Class<?> goalFloat = ReflectionUtils.getNMSClass("PathfinderGoalFloat");
Class<?> goalFleeSun = ReflectionUtils.getNMSClass("PathfinderGoalFleeSun", false); toRemove = goalFloat;
toRemove = goalFleeSun; } else if (mark == 6) {
} else if (mark == 5) { Class<?> goalFollowOwner = ReflectionUtils.getNMSClass("PathfinderGoalFollowOwner");
Class<?> goalFloat = ReflectionUtils.getNMSClass("PathfinderGoalFloat", false); toRemove = goalFollowOwner;
toRemove = goalFloat; } else if (mark == 7) {
} else if (mark == 6) { Class<?> goalFollowAdults = ReflectionUtils.getNMSClass("PathfinderGoalFollowParent");
Class<?> goalFollowOwner = ReflectionUtils.getNMSClass("PathfinderGoalFollowOwner", false); toRemove = goalFollowAdults;
toRemove = goalFollowOwner; } else if (mark == 8) {
} else if (mark == 7) { target = true;
Class<?> goalFollowAdults = ReflectionUtils.getNMSClass("PathfinderGoalFollowParent", false); Class<?> goalReactAttack = ReflectionUtils.getNMSClass("PathfinderGoalHurtByTarget");
toRemove = goalFollowAdults; toRemove = goalReactAttack;
} else if (mark == 8) { } else if (mark == 9) {
target = true; Class<?> goalJumpOnBlock = ReflectionUtils.getNMSClass("PathfinderGoalJumpOnBlock");
Class<?> goalReactAttack = ReflectionUtils.getNMSClass("PathfinderGoalHurtByTarget", false); toRemove = goalJumpOnBlock;
toRemove = goalReactAttack; } else if (mark == 10) {
} else if (mark == 9) { Class<?> goalLeapTarget = ReflectionUtils.getNMSClass("PathfinderGoalLeapAtTarget");
Class<?> goalJumpOnBlock = ReflectionUtils.getNMSClass("PathfinderGoalJumpOnBlock", false); toRemove = goalLeapTarget;
toRemove = goalJumpOnBlock; } else if (mark == 11) {
} else if (mark == 10) { Class<?> goalLookEntities = ReflectionUtils.getNMSClass("PathfinderGoalLookAtPlayer");
Class<?> goalLeapTarget = ReflectionUtils.getNMSClass("PathfinderGoalLeapAtTarget", false); toRemove = goalLookEntities;
toRemove = goalLeapTarget; } else if (mark == 12) {
} else if (mark == 11) { if (ent instanceof Spider) {
Class<?> goalLookEntities = ReflectionUtils.getNMSClass("PathfinderGoalLookAtPlayer", false); Class<?> goalSpiderMelee = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderMeleeAttack");
toRemove = goalLookEntities; toRemove = goalSpiderMelee;
} else if (mark == 12) { } else {
if (ent instanceof Spider) { Class<?> goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack");
Class<?> goalSpiderMelee = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderMeleeAttack", false); toRemove = goalMeleeAttack;
toRemove = goalSpiderMelee; }
} else { } else if (mark == 13) {
Class<?> goalMeleeAttack = ReflectionUtils.getNMSClass("PathfinderGoalMeleeAttack", false); if (ent instanceof Ghast) {
toRemove = goalMeleeAttack; Class<?> goalGhastGotoTarget = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalMoveTowardsTarget");
} toRemove = goalGhastGotoTarget;
} else if (mark == 13) { } else {
if (ent instanceof Ghast) { Class<?> goalGotoTarget = ReflectionUtils.getNMSClass("PathfinderGoalMoveTowardsTarget");
Class<?> goalGhastGotoTarget = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalMoveTowardsTarget", false); toRemove = goalGotoTarget;
toRemove = goalGhastGotoTarget; }
} else { } else if (mark == 14) {
Class<?> goalGotoTarget = ReflectionUtils.getNMSClass("PathfinderGoalMoveTowardsTarget", false); target = true;
toRemove = goalGotoTarget; if (ent instanceof Spider) {
} Class<?> goalSpiderNearTarget = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderNearestAttackableTarget");
} else if (mark == 14) { toRemove = goalSpiderNearTarget;
target = true; } else {
if (ent instanceof Spider) { Class<?> goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget");
Class<?> goalSpiderNearTarget = ReflectionUtils.getNMSClass("EntitySpider$PathfinderGoalSpiderNearestAttackableTarget", false); toRemove = goalNearTarget;
toRemove = goalSpiderNearTarget; }
} else { } else if (mark == 15) {
Class<?> goalNearTarget = ReflectionUtils.getNMSClass("PathfinderGoalNearestAttackableTarget", false); Class<?> goalOcelotAttack = ReflectionUtils.getNMSClass("PathfinderGoalOcelotAttack");
toRemove = goalNearTarget; toRemove = goalOcelotAttack;
} } else if (mark == 16) {
} else if (mark == 15) { Class<?> goalOpenDoors = ReflectionUtils.getNMSClass("PathfinderGoalOpenDoor");
Class<?> goalOcelotAttack = ReflectionUtils.getNMSClass("PathfinderGoalOcelotAttack", false); toRemove = goalOpenDoors;
toRemove = goalOcelotAttack; } else if (mark == 17) {
} else if (mark == 16) { if (ent instanceof Rabbit) {
Class<?> goalOpenDoors = ReflectionUtils.getNMSClass("PathfinderGoalOpenDoor", false); Class<?> goalRabbitPanic = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalRabbitPanic");
toRemove = goalOpenDoors; toRemove = goalRabbitPanic;
} else if (mark == 17) { } else {
if (ent instanceof Rabbit) { Class<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic");
Class<?> goalRabbitPanic = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalRabbitPanic", false); toRemove = goalPanic;
toRemove = goalRabbitPanic; }
} else { } else if (mark == 18) {
Class<?> goalPanic = ReflectionUtils.getNMSClass("PathfinderGoalPanic", false); Class<?> goalRandomLook = ReflectionUtils.getNMSClass("PathfinderGoalRandomLookaround");
toRemove = goalPanic; toRemove = goalRandomLook;
} } else if (mark == 19) {
} else if (mark == 18) { Class<?> goalWander = ReflectionUtils.getNMSClass("PathfinderGoalRandomStroll");
Class<?> goalRandomLook = ReflectionUtils.getNMSClass("PathfinderGoalRandomLookaround", false); toRemove = goalWander;
toRemove = goalRandomLook; } else if (mark == 20) {
} else if (mark == 19) { Class<?> goalSit = ReflectionUtils.getNMSClass("PathfinderGoalSit");
Class<?> goalWander = ReflectionUtils.getNMSClass("PathfinderGoalRandomStroll", false); toRemove = goalSit;
toRemove = goalWander; } else if (mark == 21) {
} else if (mark == 20) { Class<?> goalSwell = ReflectionUtils.getNMSClass("PathfinderGoalSwell");
Class<?> goalSit = ReflectionUtils.getNMSClass("PathfinderGoalSit", false); toRemove = goalSwell;
toRemove = goalSit; } else if (mark == 22) {
} else if (mark == 21) { Class<?> goalSquid = ReflectionUtils.getNMSClass("EntitySquid$PathfinderGoalSquid");
Class<?> goalSwell = ReflectionUtils.getNMSClass("PathfinderGoalSwell", false); toRemove = goalSquid;
toRemove = goalSwell; } else if (mark == 23) {
} else if (mark == 22) { resetGoalTarget = true;
Class<?> goalSquid = ReflectionUtils.getNMSClass("EntitySquid$PathfinderGoalSquid", false); if (ent instanceof Blaze) {
toRemove = goalSquid; Class<?> goalBlazeFireball = ReflectionUtils.getNMSClass("EntityBlaze$PathfinderGoalBlazeFireball");
} else if (mark == 23) { toRemove = goalBlazeFireball;
resetGoalTarget = true; } else if (ent instanceof Ghast) {
if (ent instanceof Blaze) { Class<?> goalGhastFireball = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastAttackTarget");
Class<?> goalBlazeFireball = ReflectionUtils.getNMSClass("EntityBlaze$PathfinderGoalBlazeFireball", false); toRemove = goalGhastFireball;
toRemove = goalBlazeFireball; }
} else if (ent instanceof Ghast) { } else if (mark == 24) {
Class<?> goalGhastFireball = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastAttackTarget", false); Class<?> goalHideInBlock = ReflectionUtils.getNMSClass("EntitySilverfish$PathfinderGoalSilverfishHideInBlock");
toRemove = goalGhastFireball; toRemove = goalHideInBlock;
} } else if (mark == 25) {
} else if (mark == 24) { Class<?> goalWakeSilverfish = ReflectionUtils.getNMSClass("EntitySilverfish$PathfinderGoalSilverfishWakeOthers");
Class<?> goalHideInBlock = ReflectionUtils.getNMSClass("EntitySilverfish$PathfinderGoalSilverfishHideInBlock", false); toRemove = goalWakeSilverfish;
toRemove = goalHideInBlock; } else if (mark == 26) {
} else if (mark == 25) { Class<?> goalPickBlocks = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalEndermanPickupBlock");
Class<?> goalWakeSilverfish = ReflectionUtils.getNMSClass("EntitySilverfish$PathfinderGoalSilverfishWakeOthers", false); toRemove = goalPickBlocks;
toRemove = goalWakeSilverfish; } else if (mark == 27) {
} else if (mark == 26) { Class<?> goalPlaceBlocks = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalEndermanPlaceBlock");
Class<?> goalPickBlocks = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalEndermanPickupBlock", false); toRemove = goalPlaceBlocks;
toRemove = goalPickBlocks; } else if (mark == 28) {
} else if (mark == 27) { target = true;
Class<?> goalPlaceBlocks = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalEndermanPlaceBlock", false); Class<?> goalAttackLooker = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget");
toRemove = goalPlaceBlocks; toRemove = goalAttackLooker;
} else if (mark == 28) { } else if (mark == 29) {
target = true; Class<?> goalGhastMoveTarget = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastMoveTowardsTarget");
Class<?> goalAttackLooker = ReflectionUtils.getNMSClass("EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget", false); toRemove = goalGhastMoveTarget;
toRemove = goalAttackLooker; } else if (mark == 30) {
} else if (mark == 29) { Class<?> goalGhastIdleMove = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastIdleMove");
Class<?> goalGhastMoveTarget = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastMoveTowardsTarget", false); toRemove = goalGhastIdleMove;
toRemove = goalGhastMoveTarget; } else if (mark == 31) {
} else if (mark == 30) { Class<?> goalTempt = ReflectionUtils.getNMSClass("PathfinderGoalTempt");
Class<?> goalGhastIdleMove = ReflectionUtils.getNMSClass("EntityGhast$PathfinderGoalGhastIdleMove", false); toRemove = goalTempt;
toRemove = goalGhastIdleMove; } else if (mark == 32) {
} else if (mark == 31) { target = true;
Class<?> goalTempt = ReflectionUtils.getNMSClass("PathfinderGoalTempt", false); Class<?> goalTargetNonTamed = ReflectionUtils.getNMSClass("PathfinderGoalRandomTargetNonTamed");
toRemove = goalTempt; toRemove = goalTargetNonTamed;
} else if (mark == 32) { } else if (mark == 33) {
target = true; resetGoalTarget = true;
Class<?> goalTargetNonTamed = ReflectionUtils.getNMSClass("PathfinderGoalRandomTargetNonTamed", false); Class<?> goalGuardianAttack = ReflectionUtils.getNMSClass("EntityGuardian$PathfinderGoalGuardianAttack");
toRemove = goalTargetNonTamed; toRemove = goalGuardianAttack;
} else if (mark == 33) { } else if (mark == 34) {
resetGoalTarget = true; target = true;
Class<?> goalGuardianAttack = ReflectionUtils.getNMSClass("EntityGuardian$PathfinderGoalGuardianAttack", false); Class<?> goalAnger = ReflectionUtils.getNMSClass("EntityPigZombie$PathfinderGoalAnger");
toRemove = goalGuardianAttack; toRemove = goalAnger;
} else if (mark == 34) { } else if (mark == 35) {
target = true; target = true;
Class<?> goalAnger = ReflectionUtils.getNMSClass("EntityPigZombie$PathfinderGoalAnger", false); Class<?> goalAngerOther = ReflectionUtils.getNMSClass("EntityPigZombie$PathfinderGoalAngerOther");
toRemove = goalAnger; toRemove = goalAngerOther;
} else if (mark == 35) { } else if (mark == 36) {
target = true; Class<?> goalEatCarrots = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalEatCarrots");
Class<?> goalAngerOther = ReflectionUtils.getNMSClass("EntityPigZombie$PathfinderGoalAngerOther", false); toRemove = goalEatCarrots;
toRemove = goalAngerOther; } else if (mark == 37) {
} else if (mark == 36) { Class<?> goalRabbitAttack = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalKillerRabbitMeleeAttack");
Class<?> goalEatCarrots = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalEatCarrots", false); toRemove = goalRabbitAttack;
toRemove = goalEatCarrots; } else if (mark == 38) {
} else if (mark == 37) { Class<?> goalJump = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeRandomJump");
Class<?> goalRabbitAttack = ReflectionUtils.getNMSClass("EntityRabbit$PathfinderGoalKillerRabbitMeleeAttack", false); toRemove = goalJump;
toRemove = goalRabbitAttack; } else if (mark == 39) {
} else if (mark == 38) { Class<?> goalRandomDir = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeRandomDirection");
Class<?> goalJump = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeRandomJump", false); toRemove = goalRandomDir;
toRemove = goalJump; } else if (mark == 40) {
} else if (mark == 39) { Class<?> goalSlimeWander = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeIdle");
Class<?> goalRandomDir = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeRandomDirection", false); toRemove = goalSlimeWander;
toRemove = goalRandomDir; }
} else if (mark == 40) { if (toRemove == null)
Class<?> goalSlimeWander = ReflectionUtils.getNMSClass("EntitySlime$PathfinderGoalSlimeIdle", false); return;
toRemove = goalSlimeWander;
} /* "Hey, why are you setting the entity's target to null?!"
if (toRemove == null) *
return; * For some goals (Blaze/Ghast fireball and Guardian attack), if you remove the goal while the entity is attacking, it will not stop attacking imediatelly, it will keep attacking its target.
* So there's a "bug" with this behavior, as soon as the entity's target resets (null, A.K.A <none>) the server crashes. Because we messed with the entity's "attack target" goal, the game
/* "Hey, why are you setting the entity's target to null?!" * still thinks it needs to get the target's location for some reason, and since the target is null... It throws an unhandled NPE (it never happens in Vanilla behavior), crashing the server.
* * So I'm just setting the target to null before removing the goal, so it stops attacking properly, and also prevents the said crash.
* For some goals (Blaze/Ghast fireball and Guardian attack), if you remove the goal while the entity is attacking, it will not stop attacking imediatelly, it will keep attacking its target. */
* So there's a "bug" with this behavior, as soon as the entity's target resets (null, A.K.A <none>) the server crashes. Because we messed with the entity's "attack target" goal, the game
* still thinks it needs to get the target's location for some reason, and since the target is null... It throws an unhandled NPE (it never happens in Vanilla behavior), crashing the server. if (resetGoalTarget) {
* So I'm just setting the target to null before removing the goal, so it stops attacking properly, and also prevents the said crash. ((Creature) entity.getSingle(e)).setTarget(null);
*/ }
if (resetGoalTarget) { SkStuff.getNMSMethods().removePathfinderGoal(nmsEnt, toRemove, target);
((Creature) entity.getSingle(e)).setTarget(null); } catch (Exception ex) {
} ex.printStackTrace();
}
Class<?> goalSelectorClass = ReflectionUtils.getNMSClass("PathfinderGoalSelector", false); }
if (target) { //Target Selector
Iterator<?> targets = ((List<?>) ReflectionUtils.getField("b", goalSelectorClass, targetSelector)).iterator();
while (targets.hasNext()) {
Object o = targets.next();
if (ReflectionUtils.getField("a", o.getClass(), o).getClass() == toRemove) {
targets.remove();
}
}
} else { //Goal Selector
Iterator<?> goals = ((List<?>) ReflectionUtils.getField("b", goalSelectorClass, goalSelector)).iterator();
while (goals.hasNext()) {
Object o = goals.next();
if (ReflectionUtils.getField("a", o.getClass(), o).getClass() == toRemove) {
goals.remove();
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,163 +1,163 @@
package me.TheBukor.SkStuff.expressions; package me.TheBukor.SkStuff.expressions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Enderman; import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.CollectionUtils;
import me.TheBukor.SkStuff.util.ReflectionUtils; import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprEndermanBlocks extends SimpleExpression<ItemStack> { public class ExprEndermanBlocks extends SimpleExpression<ItemStack> {
private Expression<Entity> entity; private Expression<Entity> entity;
private Class<?> nmsBlockClass = ReflectionUtils.getNMSClass("Block", false); private Class<?> nmsBlockClass = ReflectionUtils.getNMSClass("Block");
private Class<?> endermanClass = ReflectionUtils.getNMSClass("EntityEnderman", false); private Class<?> endermanClass = ReflectionUtils.getNMSClass("EntityEnderman");
private Class<?> nmsIBlockData = ReflectionUtils.getNMSClass("IBlockData", false); private Class<?> nmsIBlockData = ReflectionUtils.getNMSClass("IBlockData");
private Class<?> nmsItemClass = ReflectionUtils.getNMSClass("ItemStack", false); private Class<?> nmsItemClass = ReflectionUtils.getNMSClass("ItemStack");
private Class<?> craftEntClass = ReflectionUtils.getOBCClass("entity.CraftEntity"); private Class<?> craftEntClass = ReflectionUtils.getOBCClass("entity.CraftEntity");
private Class<?> craftItemClass = ReflectionUtils.getOBCClass("inventory.CraftItemStack"); private Class<?> craftItemClass = ReflectionUtils.getOBCClass("inventory.CraftItemStack");
@Override @Override
public Class<? extends ItemStack> getReturnType() { public Class<? extends ItemStack> getReturnType() {
return ItemStack.class; return ItemStack.class;
} }
@Override @Override
public boolean isSingle() { public boolean isSingle() {
return false; return false;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
entity = (Expression<Entity>) expr[0]; entity = (Expression<Entity>) expr[0];
return true; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean debug) { public String toString(@Nullable Event e, boolean debug) {
return "blocks that " + entity.toString(e, debug) + " can carry"; return "blocks that " + entity.toString(e, debug) + " can carry";
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
@Nullable @Nullable
protected ItemStack[] get(Event e) { protected ItemStack[] get(Event e) {
Entity ent = entity.getSingle(e); Entity ent = entity.getSingle(e);
if (ent == null || !(ent instanceof Enderman)) if (ent == null || !(ent instanceof Enderman))
return null; return null;
Object nmsEnt = null; Object nmsEnt = null;
try { try {
nmsEnt = craftEntClass.cast(ent).getClass().getMethod("getHandle").invoke(ent); nmsEnt = craftEntClass.cast(ent).getClass().getMethod("getHandle").invoke(ent);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
Set<Object> nmsBlocks = (Set<Object>) ReflectionUtils.getField("c", endermanClass, nmsEnt); Set<Object> nmsBlocks = (Set<Object>) ReflectionUtils.getField("c", endermanClass, nmsEnt);
List<ItemStack> items = new ArrayList<ItemStack>(); List<ItemStack> items = new ArrayList<ItemStack>();
for (Object nmsBlock : nmsBlocks) { for (Object nmsBlock : nmsBlocks) {
Object nmsBlockData; Object nmsBlockData;
try { try {
nmsBlockData = nmsBlockClass.getMethod("getBlockData").invoke(nmsBlock); nmsBlockData = nmsBlockClass.getMethod("getBlockData").invoke(nmsBlock);
int dataValue = (int) nmsBlockClass.getMethod("toLegacyData", nmsIBlockData).invoke(nmsBlock, int dataValue = (int) nmsBlockClass.getMethod("toLegacyData", nmsIBlockData).invoke(nmsBlock,
nmsBlockData); nmsBlockData);
Object nmsItem = nmsItemClass.getConstructor(nmsBlockClass, int.class, int.class).newInstance(nmsBlock, Object nmsItem = nmsItemClass.getConstructor(nmsBlockClass, int.class, int.class).newInstance(nmsBlock,
1, dataValue); 1, dataValue);
ItemStack bukkitItem = (ItemStack) craftItemClass.getMethod("asCraftMirror", nmsItemClass).invoke(null, ItemStack bukkitItem = (ItemStack) craftItemClass.getMethod("asCraftMirror", nmsItemClass).invoke(null,
nmsItem); nmsItem);
items.add(bukkitItem); items.add(bukkitItem);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
; ;
} }
} }
return Arrays.copyOf(items.toArray(), items.size(), ItemStack[].class); return Arrays.copyOf(items.toArray(), items.size(), ItemStack[].class);
} }
@SuppressWarnings({ "unused", "unchecked" }) @SuppressWarnings({ "unused", "unchecked" })
@Override @Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
Entity ent = entity.getSingle(e); Entity ent = entity.getSingle(e);
if (ent == null || !(ent instanceof Enderman)) if (ent == null || !(ent instanceof Enderman))
return; return;
Object nmsEnt = null; Object nmsEnt = null;
try { try {
nmsEnt = craftEntClass.cast(ent).getClass().getMethod("getHandle").invoke(ent); nmsEnt = craftEntClass.cast(ent).getClass().getMethod("getHandle").invoke(ent);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
Set<Object> enderBlocks = (Set<Object>) ReflectionUtils.getField("c", endermanClass, nmsEnt); Set<Object> enderBlocks = (Set<Object>) ReflectionUtils.getField("c", endermanClass, nmsEnt);
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) { if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) {
ItemStack[] deltaItems = Arrays.copyOf(delta, delta.length, ItemStack[].class); ItemStack[] deltaItems = Arrays.copyOf(delta, delta.length, ItemStack[].class);
if (mode == ChangeMode.SET) { if (mode == ChangeMode.SET) {
enderBlocks.clear(); enderBlocks.clear();
} }
for (ItemStack itemStack : deltaItems) { for (ItemStack itemStack : deltaItems) {
if (itemStack.getType() == Material.AIR || itemStack == null) if (itemStack.getType() == Material.AIR || itemStack == null)
continue; continue;
Object nmsItemStack = CraftItemStack.asNMSCopy(itemStack); Object nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
Object nmsItem = null; Object nmsItem = null;
try { try {
nmsItem = nmsItemStack.getClass().getMethod("getItem").invoke(nmsItemStack); nmsItem = nmsItemStack.getClass().getMethod("getItem").invoke(nmsItemStack);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
if (mode == ChangeMode.ADD || mode == ChangeMode.SET) if (mode == ChangeMode.ADD || mode == ChangeMode.SET)
enderBlocks.add(nmsItem); enderBlocks.add(nmsItem);
else //ChangeMode.REMOVE else //ChangeMode.REMOVE
enderBlocks.remove(nmsItem); enderBlocks.remove(nmsItem);
} }
} else if (mode == ChangeMode.RESET) { } else if (mode == ChangeMode.RESET) {
ItemStack grass = new ItemStack(Material.GRASS); ItemStack grass = new ItemStack(Material.GRASS);
ItemStack dirt = new ItemStack(Material.DIRT); ItemStack dirt = new ItemStack(Material.DIRT);
ItemStack sand = new ItemStack(Material.SAND); ItemStack sand = new ItemStack(Material.SAND);
ItemStack gravel = new ItemStack(Material.GRAVEL); ItemStack gravel = new ItemStack(Material.GRAVEL);
ItemStack dandelion = new ItemStack(Material.YELLOW_FLOWER); ItemStack dandelion = new ItemStack(Material.YELLOW_FLOWER);
ItemStack poppy = new ItemStack(Material.RED_ROSE); ItemStack poppy = new ItemStack(Material.RED_ROSE);
ItemStack brownShroom = new ItemStack(Material.BROWN_MUSHROOM); ItemStack brownShroom = new ItemStack(Material.BROWN_MUSHROOM);
ItemStack redShroom = new ItemStack(Material.RED_MUSHROOM); ItemStack redShroom = new ItemStack(Material.RED_MUSHROOM);
ItemStack tnt = new ItemStack(Material.TNT); ItemStack tnt = new ItemStack(Material.TNT);
ItemStack cactus = new ItemStack(Material.CACTUS); ItemStack cactus = new ItemStack(Material.CACTUS);
ItemStack clay = new ItemStack(Material.CLAY); ItemStack clay = new ItemStack(Material.CLAY);
ItemStack pumpkin = new ItemStack(Material.PUMPKIN); ItemStack pumpkin = new ItemStack(Material.PUMPKIN);
ItemStack melon = new ItemStack(Material.MELON_BLOCK); ItemStack melon = new ItemStack(Material.MELON_BLOCK);
ItemStack mycellium = new ItemStack(Material.MYCEL); ItemStack mycellium = new ItemStack(Material.MYCEL);
ItemStack[] defaultItems = new ItemStack[] { grass, dirt, gravel, dandelion, poppy, brownShroom, redShroom, tnt, cactus, clay, pumpkin, melon, mycellium }; ItemStack[] defaultItems = new ItemStack[] { grass, dirt, gravel, dandelion, poppy, brownShroom, redShroom, tnt, cactus, clay, pumpkin, melon, mycellium };
enderBlocks.clear(); enderBlocks.clear();
for (ItemStack itemStack : defaultItems) { for (ItemStack itemStack : defaultItems) {
Object nmsItemStack = CraftItemStack.asNMSCopy(itemStack); Object nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
Object nmsItem = null; Object nmsItem = null;
try { try {
nmsItem = nmsItemStack.getClass().getMethod("getItem").invoke(nmsItemStack); nmsItem = nmsItemStack.getClass().getMethod("getItem").invoke(nmsItemStack);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
enderBlocks.add(nmsItem); enderBlocks.add(nmsItem);
} }
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
@Nullable @Nullable
public Class<?>[] acceptChange(ChangeMode mode) { public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.RESET|| mode == ChangeMode.SET) { if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.RESET|| mode == ChangeMode.SET) {
return CollectionUtils.array(ItemStack[].class); return CollectionUtils.array(ItemStack[].class);
} }
return null; return null;
} }
} }

View File

@ -1,85 +1,86 @@
package me.TheBukor.SkStuff.expressions; package me.TheBukor.SkStuff.expressions;
import java.io.File; import java.io.File;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.CollectionUtils;
import me.TheBukor.SkStuff.SkStuff; import me.TheBukor.SkStuff.SkStuff;
import me.TheBukor.SkStuff.util.ReflectionUtils; import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprFileNBT extends SimpleExpression<Object> { public class ExprFileNBT extends SimpleExpression<Object> {
private Expression<String> input; private Expression<String> input;
private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound", false); private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
@Override @Override
public Class<? extends Object> getReturnType() { public Class<? extends Object> getReturnType() {
return nbtClass; return nbtClass;
} }
@Override @Override
public boolean isSingle() { public boolean isSingle() {
return true; return true;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
input = (Expression<String>) expr[0]; input = (Expression<String>) expr[0];
return true; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean debug) { public String toString(@Nullable Event e, boolean debug) {
return "the NBT from file " + input.toString(e, debug); return "the NBT from file " + input.toString(e, debug);
} }
@Override @Override
@Nullable @Nullable
public Object[] get(Event e) { public Object[] get(Event e) {
String fileName = input.getSingle(e); String fileName = input.getSingle(e);
fileName = !fileName.endsWith(".dat") ? fileName + ".dat" : fileName; fileName = !fileName.endsWith(".dat") ? fileName + ".dat" : fileName;
File file = new File(fileName); File file = new File(fileName);
if (!file.exists()) if (!file.exists())
return null; return null;
return new Object[] { SkStuff.getNMSMethods().getFileNBT(file) }; return new Object[] { SkStuff.getNMSMethods().getFileNBT(file) };
} }
@Override @Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
String fileName = input.getSingle(e); String fileName = input.getSingle(e);
fileName = !fileName.endsWith(".dat") ? fileName + ".dat" : fileName; fileName = !fileName.endsWith(".dat") ? fileName + ".dat" : fileName;
File file = new File(fileName); File file = new File(fileName);
if (!file.exists()) if (!file.exists())
return; return;
Object fileNBT = SkStuff.getNMSMethods().getFileNBT(file); Object fileNBT = SkStuff.getNMSMethods().getFileNBT(file);
if (mode == ChangeMode.ADD) { if (mode == ChangeMode.ADD) {
Object parsedNBT = SkStuff.getNMSMethods().parseRawNBT((String) delta[0]); Object parsedNBT = null;
SkStuff.getNMSMethods().addToCompound(fileNBT, parsedNBT); parsedNBT = SkStuff.getNMSMethods().parseRawNBT((String) delta[0]);
SkStuff.getNMSMethods().setFileNBT(file, fileNBT); SkStuff.getNMSMethods().addToCompound(fileNBT, parsedNBT);
} else if (mode == ChangeMode.REMOVE) { SkStuff.getNMSMethods().setFileNBT(file, fileNBT);
for (Object s : delta) { } else if (mode == ChangeMode.REMOVE) {
SkStuff.getNMSMethods().removeFromCompound(fileNBT, (String) s); for (Object s : delta) {
} SkStuff.getNMSMethods().removeFromCompound(fileNBT, (String) s);
SkStuff.getNMSMethods().setFileNBT(file, fileNBT); }
} SkStuff.getNMSMethods().setFileNBT(file, fileNBT);
} }
}
@SuppressWarnings("unchecked")
@Override @SuppressWarnings("unchecked")
@Nullable @Override
public Class<?>[] acceptChange(ChangeMode mode) { @Nullable
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { public Class<?>[] acceptChange(ChangeMode mode) {
return CollectionUtils.array(String[].class); if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
} return CollectionUtils.array(String[].class);
return null; }
} return null;
}
} }

View File

@ -1,55 +1,56 @@
package me.TheBukor.SkStuff.expressions; package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import me.TheBukor.SkStuff.SkStuff; import me.TheBukor.SkStuff.SkStuff;
public class ExprItemNBT extends SimpleExpression<ItemStack> { public class ExprItemNBT extends SimpleExpression<ItemStack> {
private Expression<ItemStack> itemStack; private Expression<ItemStack> itemStack;
private Expression<String> string; private Expression<String> string;
@Override @Override
public Class<? extends ItemStack> getReturnType() { public Class<? extends ItemStack> getReturnType() {
return ItemStack.class; return ItemStack.class;
} }
@Override @Override
public boolean isSingle() { public boolean isSingle() {
return true; return true;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
itemStack = (Expression<ItemStack>) expr[0]; itemStack = (Expression<ItemStack>) expr[0];
string = (Expression<String>) expr[1]; string = (Expression<String>) expr[1];
return true; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean debug) { public String toString(@Nullable Event e, boolean debug) {
return itemStack.toString(e, debug) + " with custom NBT " + string.toString(e, debug); return itemStack.toString(e, debug) + " with custom NBT " + string.toString(e, debug);
} }
@Override @Override
@Nullable @Nullable
public ItemStack[] get(Event e) { public ItemStack[] get(Event e) {
ItemStack item = itemStack.getSingle(e); ItemStack item = itemStack.getSingle(e);
String newTags = string.getSingle(e); String newTags = string.getSingle(e);
if (item.getType() == Material.AIR || item == null) { if (item.getType() == Material.AIR || item == null) {
return null; return null;
} }
Object parsedNBT = SkStuff.getNMSMethods().parseRawNBT(newTags); Object parsedNBT = null;
ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT(item, parsedNBT); parsedNBT = SkStuff.getNMSMethods().parseRawNBT(newTags);
return new ItemStack[] { newItem }; ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT(item, parsedNBT);
} return new ItemStack[] { newItem };
}
} }

View File

@ -1,77 +1,69 @@
package me.TheBukor.SkStuff.expressions; package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
//import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
//import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.CollectionUtils;
import me.TheBukor.SkStuff.SkStuff; import me.TheBukor.SkStuff.SkStuff;
//import me.TheBukor.SkStuff.util.ReflectionUtils; import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprNBTListContents extends SimpleExpression<Object> { public class ExprNBTListContents extends SimpleExpression<Object> {
private Expression<Object> nbtList; private Expression<Object> nbtList;
//private Class<?> nbtListClass = ReflectionUtils.getNMSClass("NBTTagList", false); private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase");
//private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound", false);
@Override
@Override public Class<? extends Object> getReturnType() {
public Class<? extends Object> getReturnType() { return Object.class;
return Object.class; }
}
@Override
@Override public boolean isSingle() {
public boolean isSingle() { return false;
return false; }
}
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") @Override
@Override public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { nbtList = (Expression<Object>) expr[0];
nbtList = (Expression<Object>) expr[0]; return true;
return false; }
}
@Override
@Override public String toString(@Nullable Event e, boolean debug) {
public String toString(@Nullable Event e, boolean debug) { return "contents from NBT list " + nbtList.toString(e, debug);
return "contents from NBT list " + nbtList.toString(e, debug); }
}
@Override
@Override @Nullable
@Nullable protected Object[] get(Event e) {
protected Object[] get(Event e) { Object list = nbtList.getSingle(e);
Object list = nbtList.getSingle(e); return SkStuff.getNMSMethods().getContents(list);
SkStuff.getNMSMethods().getContents(list); }
return null;
} @Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
/* Object list = nbtList.getSingle(e);
@Override if (mode == ChangeMode.ADD) {
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { if (!(delta[0] instanceof Number || delta[0] instanceof String || nbtBaseClass.isAssignableFrom(delta[0].getClass())))
Object list = nbtList.getSingle(e); return; //NBT can only store numbers, strings, lists or compounds.
if (mode == ChangeMode.ADD) { SkStuff.getNMSMethods().addToList(list, delta[0]);
if (!(delta[0] instanceof Number || delta[0] instanceof String || nbtListClass.isAssignableFrom(delta[0].getClass()) || nbtClass.isAssignableFrom(delta[0].getClass()))) }
return; //NBT can only store numbers, strings, lists or compounds. }
SkStuff.getNMSMethods().addToList(list, delta[0]);
} else if (mode == ChangeMode.REMOVE) { @SuppressWarnings("unchecked")
// TODO A method to remove a specific object from a NBT List @Override
} else if (mode == ChangeMode.REMOVE_ALL) { @Nullable
// TODO A method to remove all objects of some type from a NBT List public Class<?>[] acceptChange(ChangeMode mode) {
} if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.REMOVE_ALL) {
} return CollectionUtils.array(Object.class);
}
@SuppressWarnings("unchecked") return null;
@Override }
@Nullable }
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.REMOVE_ALL) {
return CollectionUtils.array(Object.class);
}
return null;
}
*/
}

View File

@ -1,77 +1,76 @@
package me.TheBukor.SkStuff.expressions; package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.CollectionUtils;
import me.TheBukor.SkStuff.SkStuff; import me.TheBukor.SkStuff.SkStuff;
import me.TheBukor.SkStuff.util.ReflectionUtils; import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprNBTListIndex extends SimpleExpression<Object> { public class ExprNBTListIndex extends SimpleExpression<Object> {
private Expression<Object> nbtList; private Expression<Object> nbtList;
private Expression<Number> index; private Expression<Number> index;
private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase", false); private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase");
@Override @Override
public Class<? extends Object> getReturnType() { public Class<? extends Object> getReturnType() {
return Object.class; return Object.class;
} }
@Override @Override
public boolean isSingle() { public boolean isSingle() {
return false; return false;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
nbtList = (Expression<Object>) expr[0]; nbtList = (Expression<Object>) expr[0];
index = (Expression<Number>) expr[1]; index = (Expression<Number>) expr[1];
return false; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean debug) { public String toString(@Nullable Event e, boolean debug) {
return "NBT list" + nbtList.toString(e, debug) + " index " + index.toString(e, debug); return "NBT list" + nbtList.toString(e, debug) + " index " + index.toString(e, debug);
} }
@Override @Override
@Nullable @Nullable
protected Object[] get(Event e) { protected Object[] get(Event e) {
int i = index.getSingle(e).intValue(); int i = index.getSingle(e).intValue();
Object list = nbtList.getSingle(e); Object list = nbtList.getSingle(e);
SkStuff.getNMSMethods().getIndex(list, i); return new Object[] { SkStuff.getNMSMethods().getIndex(list, i) };
return null; }
}
@Override
@Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { int i = index.getSingle(e).intValue();
int i = index.getSingle(e).intValue(); Object list = nbtList.getSingle(e);
Object list = nbtList.getSingle(e); if (mode == ChangeMode.SET) {
if (mode == ChangeMode.SET) { if (!(delta[0] instanceof Number || delta[0] instanceof String || nbtBaseClass.isAssignableFrom(delta[0].getClass())))
if (!(delta[0] instanceof Number || delta[0] instanceof String || nbtBaseClass.isAssignableFrom(delta[0].getClass()))) //All NBTTags extends NBTBase, so it will check if delta[0] is instance of NBTTagList or NBTTagCompound, because these are the only NBTTagX classes registered in this addon.
//All NBTTags extends NBTBase, so it will check if delta[0] is instance of NBTTagList or NBTTagCompound, because these are the only NBTTagX classes registered in this addon. return; //NBT can only store numbers, strings, lists or compounds.
return; //NBT can only store numbers, strings, lists or compounds. SkStuff.getNMSMethods().setIndex(list, i, delta[0]);
SkStuff.getNMSMethods().setIndex(list, i, delta[0]); } else if (mode == ChangeMode.DELETE) {
} else if (mode == ChangeMode.DELETE) { SkStuff.getNMSMethods().removeFromList(list, i);
SkStuff.getNMSMethods().removeFromList(list, i); }
} }
}
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") @Override
@Override @Nullable
@Nullable public Class<?>[] acceptChange(ChangeMode mode) {
public Class<?>[] acceptChange(ChangeMode mode) { if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) {
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) { return CollectionUtils.array(Object.class);
return CollectionUtils.array(Object.class); }
} return null;
return null; }
} }
}

View File

@ -1,145 +1,156 @@
package me.TheBukor.SkStuff.expressions; package me.TheBukor.SkStuff.expressions;
import java.util.Arrays; import java.util.Arrays;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit; import org.bukkit.block.Block;
import org.bukkit.block.Block; import org.bukkit.entity.Entity;
import org.bukkit.entity.Entity; import org.bukkit.event.Event;
import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
import ch.njol.skript.ScriptLoader; import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.Skript; import ch.njol.skript.lang.Expression;
import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.log.ErrorQuality;
import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.util.Slot;
import ch.njol.skript.log.ErrorQuality; import ch.njol.util.Kleenean;
import ch.njol.skript.util.Slot; import ch.njol.util.coll.CollectionUtils;
import ch.njol.util.Kleenean; import me.TheBukor.SkStuff.SkStuff;
import ch.njol.util.coll.CollectionUtils; import me.TheBukor.SkStuff.util.ReflectionUtils;
import me.TheBukor.SkStuff.SkStuff;
import me.TheBukor.SkStuff.util.ReflectionUtils; public class ExprNBTOf extends SimpleExpression<Object> {
private Expression<Object> target;
public class ExprNBTOf extends SimpleExpression<Object> {
private Expression<Object> target; private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound", false); @Override
public Class<? extends Object> getReturnType() {
@Override return nbtClass;
public Class<? extends Object> getReturnType() { }
return nbtClass;
} @Override
public boolean isSingle() {
@Override return true;
public boolean isSingle() { }
return true;
} @SuppressWarnings("unchecked")
@Override
@SuppressWarnings("unchecked") public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
@Override target = (Expression<Object>) expr[0];
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { Class<?> type = target.getReturnType();
target = (Expression<Object>) expr[0]; if (type != Entity.class || type != Block.class || type != ItemStack.class || type != Slot.class) {
Class<?> type = target.getReturnType(); Skript.error(target.toString() + " is neither an entity, a block nor an itemstack.", ErrorQuality.SEMANTIC_ERROR);
Class<? extends Event>[] evts = ScriptLoader.getCurrentEvents(); }
for (int i = 0; i < evts.length; i++) { return true;
Bukkit.broadcastMessage("Event #" + i + ": \u00A7b" + evts[i].getSimpleName()); }
}
Bukkit.broadcastMessage("Object type: \u00A79" + type.getSimpleName()); @Override
if (type != Entity.class || type != Block.class || type != ItemStack.class || type != Slot.class) { public String toString(@Nullable Event e, boolean debug) {
Skript.error(target.toString() + " is neither an entity, a block nor an itemstack.", ErrorQuality.SEMANTIC_ERROR); return "the NBT of " + target.toString(e, debug);
} }
return true;
} @Override
@Nullable
@Override public Object[] get(Event e) {
public String toString(@Nullable Event e, boolean debug) { Object tar = target.getSingle(e);
return "the NBT of " + target.toString(e, debug); if (tar instanceof Entity) {
} return new Object[] { SkStuff.getNMSMethods().getEntityNBT((Entity) tar) };
} else if (tar instanceof Block) {
@Override return new Object[] { SkStuff.getNMSMethods().getTileNBT((Block) tar) };
@Nullable } else if (tar instanceof ItemStack) {
public Object[] get(Event e) { return new Object[] { SkStuff.getNMSMethods().getItemNBT((ItemStack) tar) };
Object tar = target.getSingle(e); } else if (tar instanceof Slot) {
if (tar instanceof Entity) { return new Object[] { SkStuff.getNMSMethods().getItemNBT(((Slot) tar).getItem()) };
return new Object[] { SkStuff.getNMSMethods().getEntityNBT((Entity) tar) }; }
} else if (tar instanceof Block) { return null;
return new Object[] { SkStuff.getNMSMethods().getTileNBT((Block) tar) }; }
} else if (tar instanceof ItemStack) {
return new Object[] { SkStuff.getNMSMethods().getItemNBT((ItemStack) tar) }; @Override
} public void change(Event e, Object[] delta, ChangeMode mode) {
return null; Object tar = target.getSingle(e);
} Object parsedNBT = null;
if (delta != null) {
@Override parsedNBT = SkStuff.getNMSMethods().parseRawNBT((String) delta[0]);
public void change(Event e, Object[] delta, ChangeMode mode) { }
Object tar = target.getSingle(e); if (tar instanceof Entity) {
if (tar instanceof Entity) { Object entNBT = SkStuff.getNMSMethods().getEntityNBT((Entity) tar);
Object entNBT = SkStuff.getNMSMethods().getEntityNBT((Entity) tar); if (mode == ChangeMode.ADD) {
if (mode == ChangeMode.ADD) { SkStuff.getNMSMethods().removeFromCompound(parsedNBT, "UUIDMost", "UUIDLeast", "WorldUUDMost", "WorldUUIDLeast", "Bukkit.updateLevel");
Object parsedNBT = SkStuff.getNMSMethods().parseRawNBT((String) delta[0]); SkStuff.getNMSMethods().addToCompound(entNBT, parsedNBT);
SkStuff.getNMSMethods().removeFromCompound(parsedNBT, "UUIDMost", "UUIDLeast", "WorldUUDMost", "WorldUUIDLeast", "Bukkit.updateLevel"); SkStuff.getNMSMethods().setEntityNBT((Entity) tar, entNBT);
SkStuff.getNMSMethods().addToCompound(entNBT, parsedNBT); } else if (mode == ChangeMode.REMOVE) {
SkStuff.getNMSMethods().setEntityNBT((Entity) tar, entNBT); for (Object s : delta) {
} else if (mode == ChangeMode.REMOVE) { if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast" || s != "Bukkit.updateLevel") { // Prevent crucial data from being modified
for (Object s : delta) { SkStuff.getNMSMethods().removeFromCompound(entNBT, (String) s);
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast" || s != "Bukkit.updateLevel") { // Prevent crucial data from being modified }
SkStuff.getNMSMethods().removeFromCompound(entNBT, (String) s); }
} SkStuff.getNMSMethods().setEntityNBT((Entity) tar, entNBT);
} }
SkStuff.getNMSMethods().setEntityNBT((Entity) tar, entNBT); } else if (tar instanceof Block) {
} Object blockNBT = SkStuff.getNMSMethods().getTileNBT((Block) tar);
} else if (tar instanceof Block) { if (mode == ChangeMode.ADD) {
Object blockNBT = SkStuff.getNMSMethods().getTileNBT((Block) tar); SkStuff.getNMSMethods().removeFromCompound(parsedNBT, "x", "y", "z", "id");
if (mode == ChangeMode.ADD) { SkStuff.getNMSMethods().addToCompound(blockNBT, parsedNBT);
Object parsedNBT = SkStuff.getNMSMethods().parseRawNBT((String) delta[0]); SkStuff.getNMSMethods().setTileNBT((Block) tar, blockNBT);
SkStuff.getNMSMethods().removeFromCompound(parsedNBT, "x", "y", "z", "id"); } else if (mode == ChangeMode.REMOVE) {
SkStuff.getNMSMethods().addToCompound(blockNBT, parsedNBT); for (Object s : delta) {
SkStuff.getNMSMethods().setTileNBT((Block) tar, blockNBT); if (s != "x" || s != "y" || s != "z" || s != "id") {
} else if (mode == ChangeMode.REMOVE) { SkStuff.getNMSMethods().removeFromCompound(blockNBT, (String) s);
for (Object s : delta) { }
if (s != "x" || s != "y" || s != "z" || s != "id") { }
SkStuff.getNMSMethods().removeFromCompound(blockNBT, (String) s); SkStuff.getNMSMethods().setTileNBT((Block) tar, blockNBT);
} }
} } else if (tar instanceof ItemStack) {
SkStuff.getNMSMethods().setTileNBT((Block) tar, blockNBT); Object itemNBT = SkStuff.getNMSMethods().getItemNBT((ItemStack) tar);
} if (mode == ChangeMode.ADD) {
} else if (tar instanceof ItemStack) { SkStuff.getNMSMethods().addToCompound(itemNBT, parsedNBT);
Object itemNBT = SkStuff.getNMSMethods().getItemNBT((ItemStack) tar); ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, itemNBT);
if (mode == ChangeMode.ADD) { Object slot = target.getSource().getSingle(e);
Object parsedNBT = SkStuff.getNMSMethods().parseRawNBT((String) delta[0]); if (slot instanceof Slot) {
SkStuff.getNMSMethods().addToCompound(itemNBT, parsedNBT); ((Slot) slot).setItem(newItem);
ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, itemNBT); }
Object slot = target.getSource().getSingle(e); } else if (mode == ChangeMode.REMOVE) {
if (slot instanceof Slot) { String[] toRemove = Arrays.copyOf(delta, delta.length, String[].class);
((Slot) slot).setItem(newItem); SkStuff.getNMSMethods().removeFromCompound(itemNBT, toRemove);
} ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, itemNBT);
} else if (mode == ChangeMode.REMOVE) { Object slot = target.getSource().getSingle(e);
String[] toRemove = Arrays.copyOf(delta, delta.length, String[].class); if (slot instanceof Slot) {
SkStuff.getNMSMethods().removeFromCompound(itemNBT, toRemove); ((Slot) slot).setItem(newItem);
ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, itemNBT); }
Object slot = target.getSource().getSingle(e); } else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
if (slot instanceof Slot) { ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, null);
((Slot) slot).setItem(newItem); Object slot = target.getSource().getSingle(e);
} if (slot instanceof Slot) {
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { ((Slot) slot).setItem(newItem);
ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, null); }
Object slot = target.getSource().getSingle(e); }
if (slot instanceof Slot) { } else if (tar instanceof Slot) {
((Slot) slot).setItem(newItem); Object itemNBT = SkStuff.getNMSMethods().getItemNBT(((Slot) tar).getItem());
} if (mode == ChangeMode.ADD) {
} SkStuff.getNMSMethods().addToCompound(itemNBT, parsedNBT);
} ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, itemNBT);
} ((Slot) tar).setItem(newItem);
} else if (mode == ChangeMode.REMOVE) {
@SuppressWarnings("unchecked") String[] toRemove = Arrays.copyOf(delta, delta.length, String[].class);
@Override SkStuff.getNMSMethods().removeFromCompound(itemNBT, toRemove);
public Class<?>[] acceptChange(final ChangeMode mode) { ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, itemNBT);
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { ((Slot) tar).setItem(newItem);
return CollectionUtils.array(String[].class); } else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
} ItemStack newItem = SkStuff.getNMSMethods().getItemWithNBT((ItemStack) tar, null);
return null; ((Slot) tar).setItem(newItem);
} }
}
}
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
return CollectionUtils.array(String[].class);
}
return null;
}
} }

View File

@ -1,194 +1,194 @@
package me.TheBukor.SkStuff.expressions; package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.CollectionUtils;
import me.TheBukor.SkStuff.util.ReflectionUtils; import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprTagOf extends SimpleExpression<Object> { public class ExprTagOf extends SimpleExpression<Object> {
private Expression<String> string; private Expression<String> string;
private Expression<Object> compound; private Expression<Object> compound;
private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound", false); private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase", false); private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase");
@Override @Override
public Class<? extends Object> getReturnType() { public Class<? extends Object> getReturnType() {
return Object.class; return Object.class;
} }
@Override @Override
public boolean isSingle() { public boolean isSingle() {
return true; return true;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) { public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
string = (Expression<String>) expr[0]; string = (Expression<String>) expr[0];
compound = (Expression<Object>) expr[1]; compound = (Expression<Object>) expr[1];
return true; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean debug) { public String toString(@Nullable Event e, boolean debug) {
return "the tag " + string.toString(e, debug) + " of compound"; return "the tag " + string.toString(e, debug) + " of compound";
} }
@Override @Override
@Nullable @Nullable
protected Object[] get(Event e) { protected Object[] get(Event e) {
Object NBT = compound.getSingle(e); Object NBT = compound.getSingle(e);
if (NBT == null || NBT.toString().equals("{}")) return null; //The NBT can be empty/inexistant for items ("{}" is an empty compound). if (NBT == null || NBT.toString().equals("{}")) return null; //The NBT can be empty/inexistant for items ("{}" is an empty compound).
String stringTag = string.getSingle(e); String stringTag = string.getSingle(e);
Object tag = null; Object tag = null;
try { try {
tag = nbtClass.getMethod("get", String.class).invoke(NBT, stringTag); tag = nbtClass.getMethod("get", String.class).invoke(NBT, stringTag);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
if (tag == null) if (tag == null)
return null; //The tag doesn't exist? Return <none>. return null; //The tag doesn't exist? Return <none>.
Byte id = null; Byte id = null;
try { try {
id = (Byte) tag.getClass().getMethod("getTypeId").invoke(tag); id = (Byte) tag.getClass().getMethod("getTypeId").invoke(tag);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
try { try {
switch (id) { switch (id) {
case 1: case 1:
return new Byte[] { Byte.valueOf(nbtClass.getMethod("getByte", String.class).invoke(NBT, stringTag).toString()) }; return new Byte[] { Byte.valueOf(nbtClass.getMethod("getByte", String.class).invoke(NBT, stringTag).toString()) };
case 2: case 2:
return new Short[] { Short.valueOf(nbtClass.getMethod("getShort", String.class).invoke(NBT, stringTag).toString()) }; return new Short[] { Short.valueOf(nbtClass.getMethod("getShort", String.class).invoke(NBT, stringTag).toString()) };
case 3: case 3:
return new Integer[] { Integer.valueOf(nbtClass.getMethod("getInt", String.class).invoke(NBT, stringTag).toString()) }; return new Integer[] { Integer.valueOf(nbtClass.getMethod("getInt", String.class).invoke(NBT, stringTag).toString()) };
case 4: case 4:
return new Long[] { Long.valueOf(nbtClass.getMethod("getLong", String.class).invoke(NBT, stringTag).toString()) }; return new Long[] { Long.valueOf(nbtClass.getMethod("getLong", String.class).invoke(NBT, stringTag).toString()) };
case 5: case 5:
return new Float[] { Float.valueOf(nbtClass.getMethod("getFloat", String.class).invoke(NBT, stringTag).toString()) }; return new Float[] { Float.valueOf(nbtClass.getMethod("getFloat", String.class).invoke(NBT, stringTag).toString()) };
case 6: case 6:
return new Double[] { Double.valueOf(nbtClass.getMethod("getDouble", String.class).invoke(NBT, stringTag).toString()) }; return new Double[] { Double.valueOf(nbtClass.getMethod("getDouble", String.class).invoke(NBT, stringTag).toString()) };
case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser. case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser.
break; break;
case 8: case 8:
return new String[] { nbtClass.getMethod("getString", String.class).invoke(NBT, stringTag).toString() }; return new String[] { nbtClass.getMethod("getString", String.class).invoke(NBT, stringTag).toString() };
case 9: case 9:
int i; int i;
Object[] list = new Object[] { new Object() }; Object[] list = new Object[] { new Object() };
for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside, for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside,
//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list. //since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list.
list[0] = nbtClass.getMethod("getList", String.class, int.class).invoke(NBT, stringTag, i); //Try to get the list with the ID "loop-number". list[0] = nbtClass.getMethod("getList", String.class, int.class).invoke(NBT, stringTag, i); //Try to get the list with the ID "loop-number".
if (!list[0].toString().equals("[]")) { //If list is not empty. if (!list[0].toString().equals("[]")) { //If list is not empty.
break; //Stop loop. break; //Stop loop.
} }
} }
return list; return list;
/* /*
REMOVED TEMPORARILY, HOPEFULLY THE NEW IMPLEMENTATION SHOULD WORK BETTER REMOVED TEMPORARILY, HOPEFULLY THE NEW IMPLEMENTATION SHOULD WORK BETTER
int i; int i;
Object list = null; Object list = null;
for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside, for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside,
//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list. //since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list.
list = nbtClass.getMethod("getList", String.class, int.class).invoke(NBT, stringTag, i); //Try to get the list with the ID "loop-number". list = nbtClass.getMethod("getList", String.class, int.class).invoke(NBT, stringTag, i); //Try to get the list with the ID "loop-number".
if (!list.toString().equals("[]")) { //If list is not empty. if (!list.toString().equals("[]")) { //If list is not empty.
break; //Stop loop. break; //Stop loop.
} }
} }
String methodName = null; String methodName = null;
switch (NBTUtil.getContentsId(list)) { switch (NBTUtil.getContentsId(list)) {
case 5: //Float case 5: //Float
methodName = "e"; //list.e(int) = get float from the specified index. methodName = "e"; //list.e(int) = get float from the specified index.
break; break;
case 6: //Double case 6: //Double
methodName = "d"; //list.d(int) = get double from the specified index. methodName = "d"; //list.d(int) = get double from the specified index.
break; break;
case 8: //String case 8: //String
methodName = "getString"; //Self-explanatory, I guess. methodName = "getString"; //Self-explanatory, I guess.
break; break;
case 10: //Compound case 10: //Compound
methodName = "get"; //list.get(int) = get compound at the specified index. methodName = "get"; //list.get(int) = get compound at the specified index.
break; break;
case 11: //Integer array case 11: //Integer array
methodName = "c"; //Not sure if ever used, but meh. methodName = "c"; //Not sure if ever used, but meh.
break; break;
default: default:
break; break;
} }
int listSize = (int) list.getClass().getMethod("size").invoke(list); int listSize = (int) list.getClass().getMethod("size").invoke(list);
Object[] tags = new Object[listSize]; Object[] tags = new Object[listSize];
for (i = 0; i < listSize; i++) { for (i = 0; i < listSize; i++) {
Object gottenTag = list.getClass().getMethod(methodName, int.class).invoke(list, i); Object gottenTag = list.getClass().getMethod(methodName, int.class).invoke(list, i);
tags[i] = gottenTag; tags[i] = gottenTag;
} }
return tags; return tags;
*/ */
case 10: case 10:
return new Object[] { nbtClass.getMethod("getCompound", String.class).invoke(NBT, stringTag) }; return new Object[] { nbtClass.getMethod("getCompound", String.class).invoke(NBT, stringTag) };
case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?). case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?).
return new Object[] { nbtClass.getMethod("getIntArray", String.class).invoke(NBT, stringTag).toString() }; return new Object[] { nbtClass.getMethod("getIntArray", String.class).invoke(NBT, stringTag).toString() };
default: //This shouldn't happen, but it's better to have this just in case it spills errors everywhere. default: //This shouldn't happen, but it's better to have this just in case it spills errors everywhere.
break; break;
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
return null; return null;
} }
@Override @Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
Object NBT = compound.getSingle(e); Object NBT = compound.getSingle(e);
if (NBT == null) if (NBT == null)
try { try {
NBT = nbtClass.newInstance(); //If the NBT isn't set, create an empty one NBT = nbtClass.newInstance(); //If the NBT isn't set, create an empty one
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
String stringTag = string.getSingle(e); String stringTag = string.getSingle(e);
if (mode == ChangeMode.SET) { if (mode == ChangeMode.SET) {
Object newValue = delta[0]; Object newValue = delta[0];
try { try {
if (newValue instanceof Byte) { if (newValue instanceof Byte) {
nbtClass.getMethod("setByte", String.class, byte.class).invoke(NBT, stringTag, ((Byte) newValue).byteValue()); nbtClass.getMethod("setByte", String.class, byte.class).invoke(NBT, stringTag, ((Byte) newValue).byteValue());
} else if (newValue instanceof Short) { } else if (newValue instanceof Short) {
nbtClass.getMethod("setShort", String.class, short.class).invoke(NBT, stringTag, ((Short) newValue).shortValue()); nbtClass.getMethod("setShort", String.class, short.class).invoke(NBT, stringTag, ((Short) newValue).shortValue());
} else if (newValue instanceof Integer) { } else if (newValue instanceof Integer) {
nbtClass.getMethod("setInt", String.class, int.class).invoke(NBT, stringTag, ((Integer) newValue).intValue()); nbtClass.getMethod("setInt", String.class, int.class).invoke(NBT, stringTag, ((Integer) newValue).intValue());
} else if (newValue instanceof Long) { } else if (newValue instanceof Long) {
nbtClass.getMethod("setLong", String.class, long.class).invoke(NBT, stringTag, ((Long) newValue).longValue()); nbtClass.getMethod("setLong", String.class, long.class).invoke(NBT, stringTag, ((Long) newValue).longValue());
} else if (newValue instanceof Float) { } else if (newValue instanceof Float) {
nbtClass.getMethod("setFloat", String.class, float.class).invoke(NBT, stringTag, ((Float) newValue).floatValue()); nbtClass.getMethod("setFloat", String.class, float.class).invoke(NBT, stringTag, ((Float) newValue).floatValue());
} else if (newValue instanceof Double) { } else if (newValue instanceof Double) {
nbtClass.getMethod("setDouble", String.class, double.class).invoke(NBT, stringTag, ((Double) newValue).doubleValue()); nbtClass.getMethod("setDouble", String.class, double.class).invoke(NBT, stringTag, ((Double) newValue).doubleValue());
} else if (newValue instanceof String) { } else if (newValue instanceof String) {
nbtClass.getMethod("setString", String.class, String.class).invoke(NBT, stringTag, String.valueOf(newValue)); nbtClass.getMethod("setString", String.class, String.class).invoke(NBT, stringTag, String.valueOf(newValue));
} else { } else {
return; //Something else like a list or entire compound. return; //Something else like a list or entire compound.
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} else if (mode == ChangeMode.RESET || mode == ChangeMode.DELETE) { } else if (mode == ChangeMode.RESET || mode == ChangeMode.DELETE) {
try { try {
nbtClass.getMethod("set", String.class, nbtBaseClass).invoke(NBT, stringTag, nbtBaseClass.newInstance()); nbtClass.getMethod("set", String.class, nbtBaseClass).invoke(NBT, stringTag, nbtBaseClass.newInstance());
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
@Nullable @Nullable
public Class<?>[] acceptChange(ChangeMode mode) { public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
return CollectionUtils.array(Object.class); return CollectionUtils.array(Object.class);
} }
return null; return null;
} }
} }

View File

@ -1,179 +0,0 @@
package me.TheBukor.SkStuff.util;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.fusesource.jansi.Ansi;
import ch.njol.skript.Skript;
public class NBTUtil {
private static Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase", false);
private static Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound", false);
private static Class<?> nbtListClass = ReflectionUtils.getNMSClass("NBTTagList", false);
/**
* This is actually a copy of the "a(NBTTagCompound)" method in the NBTTagCompound class.
* I needed to add this because the 1.7 and before versions of the NBTTagCompound class didn't have this method,
* so there wasn't actually a reliable way to multiple tags at once into a compound.
* For the original code for the method, check https://github.com/linouxis9/mc-dev-1.8.7/blob/master/net/minecraft/server/NBTTagCompound.java#L348
*
* Please note that I adapted it to work using reflection.
*/
@SuppressWarnings("unchecked")
public static void addCompound(Object NBT, Object toAdd) {
if (NBT.getClass() == nbtClass && toAdd.getClass() == nbtClass) {
try {
HashMap<String, Object> map = (HashMap<String, Object>) ReflectionUtils.getField("map", nbtClass, toAdd);
Set<String> keySet = (Set<String>) nbtClass.getMethod("c").invoke(toAdd);
Iterator<String> iterator = keySet.iterator();
while(iterator.hasNext()) {
String string = (String) iterator.next();
Object base = nbtBaseClass.cast(map.get(string));
if((byte) nbtBaseClass.getMethod("getTypeId").invoke(base) == 10) {
if((boolean) nbtClass.getMethod("hasKeyOfType", String.class, int.class).invoke(NBT, string, 10)) {
Object localNBT = null;
localNBT = nbtClass.getMethod("getCompound", String.class).invoke(localNBT, string);
NBTUtil.addCompound(localNBT, nbtBaseClass.cast(nbtClass));
} else {
nbtClass.getMethod("set", String.class, nbtBaseClass).invoke(NBT, string, base.getClass().getMethod("clone").invoke(base));
}
} else {
nbtClass.getMethod("set", String.class, nbtBaseClass).invoke(NBT, string, base.getClass().getMethod("clone").invoke(base));
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
/**
* Gets the ID of the contents inside a NBT List.
* I needed to add this because the 1.7 and before versions of the NBTTagList
* class had a different name for the method that got this value.
* 1.8 used "f()", while 1.7 used "d()".
*/
public static int getContentsId(Object list) {
if (list.getClass() == nbtListClass) {
Field type = null;
int result = 0;
try {
type = nbtListClass.getDeclaredField("type");
type.setAccessible(true);
result = type.getInt(list);
type.setAccessible(false);
return result;
} catch (Exception ex) {
type.setAccessible(false);
ex.printStackTrace();
}
return result;
}
return 0;
}
/**
* Used for the "addToList()" and "setIndex()" methods if the typeId of the contents is still not defined.
*/
public static void setContentsId(Object list, int newId) {
if (list.getClass() == nbtListClass) {
Field type = null;
try {
type = nbtListClass.getDeclaredField("type");
type.setAccessible(true);
type.set(list, newId);
type.setAccessible(false);
} catch (Exception ex) {
type.setAccessible(false);
ex.printStackTrace();
}
}
}
@SuppressWarnings("unchecked")
public static List<Object> getContents(Object list) {
if (list.getClass() == nbtListClass) {
List<Object> result = null;
result = (List<Object>) ReflectionUtils.getField("list", nbtListClass, list);
return result;
}
return null;
}
/**
* Kind of a copy of the "add()" method from the NBTTagList class.
*/
public static void addToList(Object list, Object[] toAdd) {
if (list.getClass() == nbtListClass && toAdd[0].getClass() == nbtBaseClass) {
int listTypeId = NBTUtil.getContentsId(list);
int toAddId = 0;
try {
toAddId = (int) toAdd.getClass().getMethod("getTypeId").invoke(toAdd);
} catch (Exception ex) {
ex.printStackTrace();
}
if (listTypeId == 0) {
try {
NBTUtil.setContentsId(list, toAddId);
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (listTypeId != toAddId) {
Skript.warning(Ansi.ansi().fgBright(Ansi.Color.RED) + "Adding mismatching tag types to NBT list" + Ansi.ansi().fgBright(Ansi.Color.DEFAULT));
return;
}
for (Object tag : toAdd) {
NBTUtil.getContents(list).add(tag);
}
}
}
public static void removefromList(Object list, int index) {
if (list.getClass() == nbtListClass) {
if (index >= 0 && index < NBTUtil.getContents(list).size()) {
NBTUtil.getContents(list).remove(index);
}
}
}
public static void setIndex(Object list, int index, Object toAdd) {
if (list.getClass() == nbtListClass && toAdd.getClass() == nbtBaseClass) {
if (index >= 0 && index < NBTUtil.getContents(list).size()) {
int listTypeId = NBTUtil.getContentsId(list);
int toAddId = 0;
try {
toAddId = (int) toAdd.getClass().getMethod("getTypeId").invoke(toAdd);
} catch (Exception ex) {
ex.printStackTrace();
}
if (listTypeId == 0) {
try {
NBTUtil.setContentsId(list, toAddId);
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (listTypeId != toAddId) {
Skript.warning("Adding mismatching tag types to NBT list");
return;
}
NBTUtil.getContents(list).set(index, toAdd);
}
}
}
public static Object getIndex(Object list, int index) {
if (list.getClass() == nbtListClass) {
if (index >= 0 && index < NBTUtil.getContents(list).size()) {
NBTUtil.getContents(list).get(index);
}
}
return null;
}
}

View File

@ -1,52 +1,56 @@
package me.TheBukor.SkStuff.util; package me.TheBukor.SkStuff.util;
import java.io.File; import java.io.File;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public interface NMSInterface { public interface NMSInterface {
public void addToCompound(Object compound, Object toAdd); public void addToCompound(Object compound, Object toAdd);
public void removeFromCompound(Object compound, String ... toRemove); public void removeFromCompound(Object compound, String ... toRemove);
public Object parseRawNBT(String rawNBT); public Object parseRawNBT(String rawNBT);
public int getContentsId(Object nbtList); public int getContentsId(Object nbtList);
public Object[] getContents(Object nbtList); public Object[] getContents(Object nbtList);
public void addToList(Object nbtList, Object toAdd); public void addToList(Object nbtList, Object toAdd);
public void removeFromList(Object nbtList, int index); public void removeFromList(Object nbtList, int index);
public void setIndex(Object nbtList, int index, Object toSet); public void setIndex(Object nbtList, int index, Object toSet);
public Object getIndex(Object nbtList, int index); public Object getIndex(Object nbtList, int index);
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector); public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector);
public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector); public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector);
public void registerCompoundClassInfo(); public void registerCompoundClassInfo();
public void registerNBTListClassInfo(); public void registerNBTListClassInfo();
public Object getEntityNBT(Entity entity); public Object getEntityNBT(Entity entity);
public Object getTileNBT(Block block); public Object getTileNBT(Block block);
public Object getItemNBT(ItemStack itemStack); public Object getItemNBT(ItemStack itemStack);
public void setEntityNBT(Entity entity, Object newCompound); public void setEntityNBT(Entity entity, Object newCompound);
public void setTileNBT(Block block, Object newCompound); public void setTileNBT(Block block, Object newCompound);
public ItemStack getItemWithNBT(ItemStack itemStack, Object compound); public ItemStack getItemWithNBT(ItemStack itemStack, Object compound);
public Object getFileNBT(File file); public Object getFileNBT(File file);
public void setFileNBT(File file, Object newCompound); public void setFileNBT(File file, Object newCompound);
}
public Object convertToNBT(Number number);
public Object convertToNBT(String string);
}

View File

@ -1,444 +1,498 @@
package me.TheBukor.SkStuff.util; package me.TheBukor.SkStuff.util;
import java.io.EOFException; import java.io.EOFException;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.HashMap;
import java.util.HashMap; import java.util.Iterator;
import java.util.Iterator; import java.util.List;
import java.util.List; import java.util.Set;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Bukkit; import org.bukkit.Material;
import org.bukkit.Material; import org.bukkit.block.Block;
import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity; import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack; import org.bukkit.entity.Entity;
import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
import ch.njol.skript.Skript; import ch.njol.skript.classes.Changer;
import ch.njol.skript.classes.Changer; import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.ClassInfo; import ch.njol.skript.classes.Parser;
import ch.njol.skript.classes.Parser; import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.lang.ParseContext; import ch.njol.skript.registrations.Classes;
import ch.njol.skript.registrations.Classes; import ch.njol.util.coll.CollectionUtils;
import ch.njol.util.coll.CollectionUtils; import net.minecraft.server.v1_7_R4.MojangsonParser;
import net.minecraft.server.v1_7_R4.MojangsonParser; import net.minecraft.server.v1_7_R4.NBTBase;
import net.minecraft.server.v1_7_R4.NBTBase; import net.minecraft.server.v1_7_R4.NBTCompressedStreamTools;
import net.minecraft.server.v1_7_R4.NBTCompressedStreamTools; import net.minecraft.server.v1_7_R4.NBTTagCompound;
import net.minecraft.server.v1_7_R4.NBTTagCompound; import net.minecraft.server.v1_7_R4.NBTTagDouble;
import net.minecraft.server.v1_7_R4.NBTTagDouble; import net.minecraft.server.v1_7_R4.NBTTagFloat;
import net.minecraft.server.v1_7_R4.NBTTagEnd; import net.minecraft.server.v1_7_R4.NBTTagInt;
import net.minecraft.server.v1_7_R4.NBTTagFloat; import net.minecraft.server.v1_7_R4.NBTTagList;
import net.minecraft.server.v1_7_R4.NBTTagInt; import net.minecraft.server.v1_7_R4.NBTTagString;
import net.minecraft.server.v1_7_R4.NBTTagList; import net.minecraft.server.v1_7_R4.TileEntity;
import net.minecraft.server.v1_7_R4.NBTTagString; import net.minecraft.server.v1_7_R4.World;
import net.minecraft.server.v1_7_R4.TileEntity; import net.minecraft.server.v1_8_R3.NBTTagByte;
import net.minecraft.server.v1_7_R4.World; import net.minecraft.server.v1_8_R3.NBTTagLong;
import net.minecraft.server.v1_8_R3.NBTTagShort;
public class NMS_v1_7_R4 implements NMSInterface {
public class NMS_v1_7_R4 implements NMSInterface {
@SuppressWarnings("unchecked")
@Override @SuppressWarnings("unchecked")
public void addToCompound(Object compound, Object toAdd) { @Override
if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) { public void addToCompound(Object compound, Object toAdd) {
HashMap<String, Object> map = (HashMap<String, Object>) ReflectionUtils.getField("map", NBTTagCompound.class, toAdd); if (compound instanceof NBTTagCompound && toAdd instanceof NBTTagCompound) {
Set<String> keySet = ((NBTTagCompound) toAdd).c(); HashMap<String, Object> map = (HashMap<String, Object>) ReflectionUtils.getField("map", NBTTagCompound.class, toAdd);
Iterator<String> iterator = keySet.iterator(); Set<String> keySet = ((NBTTagCompound) toAdd).c();
Iterator<String> iterator = keySet.iterator();
while(iterator.hasNext()) {
String string = (String) iterator.next(); while(iterator.hasNext()) {
NBTBase base = (NBTBase) map.get(string); String string = (String) iterator.next();
if(base.getTypeId() == 10) { NBTBase base = (NBTBase) map.get(string);
if(((NBTTagCompound) compound).hasKeyOfType(string, 10)) { if(base.getTypeId() == 10) {
NBTTagCompound localNBT = ((NBTTagCompound) compound).getCompound(string); if(((NBTTagCompound) compound).hasKeyOfType(string, 10)) {
addToCompound(localNBT, (NBTTagCompound) base); NBTTagCompound localNBT = ((NBTTagCompound) compound).getCompound(string);
} else { addToCompound(localNBT, (NBTTagCompound) base);
((NBTTagCompound) compound).set(string, base.clone()); } else {
} ((NBTTagCompound) compound).set(string, base.clone());
} else { }
((NBTTagCompound) compound).set(string, base.clone()); } else {
} ((NBTTagCompound) compound).set(string, base.clone());
} }
} }
} }
}
@Override
public void removeFromCompound(Object compound, String ... toRemove) { @Override
if (compound instanceof NBTTagCompound) { public void removeFromCompound(Object compound, String ... toRemove) {
((NBTTagCompound) compound).remove(toRemove.toString()); //FIXME if (compound instanceof NBTTagCompound) {
} for (String s : toRemove) {
} ((NBTTagCompound) compound).remove(s);
}
@Override }
public Object parseRawNBT(String rawNBT) { }
NBTTagCompound parsedNBT = null;
parsedNBT = (NBTTagCompound) MojangsonParser.parse(rawNBT); @Override
return parsedNBT; public NBTTagCompound parseRawNBT(String rawNBT) {
} NBTTagCompound parsedNBT = null;
parsedNBT = (NBTTagCompound) MojangsonParser.parse(rawNBT);
@Override return parsedNBT;
public int getContentsId(Object nbtList) { }
if (nbtList instanceof NBTTagList) {
return ((NBTTagList) nbtList).d(); @Override
} public int getContentsId(Object nbtList) {
return 0; if (nbtList instanceof NBTTagList) {
} return ((NBTTagList) nbtList).d();
}
@Override return 0;
public Object[] getContents(Object nbtList) { }
if (nbtList instanceof NBTTagList) {
List<Object> contents = new ArrayList<Object>(); @Override
for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) { public Object[] getContents(Object nbtList) {
if (getIndex(nbtList, i) != null) { if (nbtList instanceof NBTTagList) {
contents.add(getIndex(nbtList, i)); Object[] contents = new Object[((NBTTagList) nbtList).size()];
} for (int i = 0; i < ((NBTTagList) nbtList).size(); i++) {
} if (getIndex(nbtList, i) != null) {
return contents.toArray(); contents[i] = getIndex(nbtList, i);
} }
return null; }
} return contents;
}
@Override return null;
public void addToList(Object nbtList, Object toAdd) { }
if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) {
((NBTTagList) nbtList).add((NBTBase) toAdd); @Override
} public void addToList(Object nbtList, Object toAdd) {
} if (nbtList instanceof NBTTagList && toAdd instanceof NBTBase) {
((NBTTagList) nbtList).add((NBTBase) toAdd);
@SuppressWarnings("unchecked") }
@Override }
public void removeFromList(Object nbtList, int index) {
if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { @SuppressWarnings("unchecked")
List<Object> actualList = null; @Override
actualList = (List<Object>) ReflectionUtils.getField("list", NBTTagList.class, nbtList); public void removeFromList(Object nbtList, int index) {
actualList.remove(index); if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) {
} List<Object> actualList = null;
} actualList = (List<Object>) ReflectionUtils.getField("list", NBTTagList.class, nbtList);
actualList.remove(index);
@SuppressWarnings("unchecked") }
@Override }
public void setIndex(Object nbtList, int index, Object toSet) {
if (nbtList instanceof NBTTagList && toSet instanceof NBTBase && index >= 0 && index < ((NBTTagList) nbtList).size()) { @SuppressWarnings("unchecked")
int typeId = getContentsId(nbtList); @Override
int toSetId = ((NBTBase) toSet).getTypeId(); public void setIndex(Object nbtList, int index, Object toSet) {
if (typeId == 0) { if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) {
ReflectionUtils.setField("type", NBTTagList.class, nbtList, toSetId); int typeId = getContentsId(nbtList);
} else if (typeId != toSetId) { NBTBase toSetNBT = null;
Skript.warning("Adding mismatching tag types to NBT list"); if (toSet instanceof NBTBase)
return; toSetNBT = (NBTBase) toSet;
} else if (toSet instanceof Number)
List<Object> actualList = null; toSetNBT = (NBTBase) convertToNBT((Number) toSet);
actualList = (List<Object>) ReflectionUtils.getField("list", NBTTagList.class, nbtList); else if (toSet instanceof String)
actualList.set(index, toSet); toSetNBT = convertToNBT((String) toSet);
} else
} return;
int toSetId = (toSetNBT).getTypeId();
@SuppressWarnings("unchecked") if (typeId == 0) {
@Override ReflectionUtils.setField("type", NBTTagList.class, nbtList, toSetId);
public Object getIndex(Object nbtList, int index) { } else if (typeId != toSetId) {
if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) { Skript.warning("Adding mismatching tag types to NBT list");
List<NBTBase> actualList = null; return;
actualList = (List<NBTBase>) ReflectionUtils.getField("list", NBTTagList.class, nbtList); }
NBTBase value = (NBTBase) actualList.get(index); List<Object> actualList = null;
if (value instanceof NBTTagEnd) actualList = (List<Object>) ReflectionUtils.getField("list", NBTTagList.class, nbtList);
return null; actualList.set(index, toSetNBT);
else }
return value; }
}
return null; @SuppressWarnings("unchecked")
} @Override
public Object getIndex(Object nbtList, int index) {
@Override if (nbtList instanceof NBTTagList && index >= 0 && index < ((NBTTagList) nbtList).size()) {
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) { List<NBTBase> actualList = null;
Bukkit.getLogger().warning("Sorry, Pathfinder Goals are only supported in 1.8 and above"); actualList = (List<NBTBase>) ReflectionUtils.getField("list", NBTTagList.class, nbtList);
} NBTBase value = (NBTBase) actualList.get(index);
return value;
@Override }
public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) { return null;
Bukkit.getLogger().warning("Sorry, Pathfinder Goals are only supported in 1.8 and above"); }
}
@Override
@Override public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) {
public void registerCompoundClassInfo() { Bukkit.getLogger().warning("Sorry, Pathfinder Goals are only supported in 1.8 and above");
Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() { }
@SuppressWarnings("unchecked") @Override
@Override public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector) {
@Nullable Bukkit.getLogger().warning("Sorry, Pathfinder Goals are only supported in 1.8 and above");
public Class<?>[] acceptChange(ChangeMode mode) { }
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) {
return CollectionUtils.array(String[].class, NBTTagCompound[].class); @Override
} public void registerCompoundClassInfo() {
return null; Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").changer(new Changer<NBTTagCompound>() {
}
@SuppressWarnings("unchecked")
@Override @Override
public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) { @Nullable
if (mode == ChangeMode.SET) { public Class<?>[] acceptChange(ChangeMode mode) {
if (delta[0] instanceof NBTTagCompound) { if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) {
NBT[0] = (NBTTagCompound) delta[0]; return CollectionUtils.array(String[].class, NBTTagCompound[].class);
} else { }
NBTTagCompound parsedNBT = (NBTTagCompound) parseRawNBT((String) delta[0]); return null;
NBT[0] = parsedNBT; }
}
} else if (mode == ChangeMode.ADD) { @Override
if (delta[0] instanceof String) { public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) {
NBTTagCompound parsedNBT = (NBTTagCompound) parseRawNBT((String) delta[0]); if (mode == ChangeMode.SET) {
addToCompound(NBT[0], parsedNBT); if (delta[0] instanceof NBTTagCompound) {
} else { NBT[0] = (NBTTagCompound) delta[0];
addToCompound(NBT[0], delta[0]); } else {
} NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]);
} else if (mode == ChangeMode.REMOVE) { NBT[0] = parsedNBT;
if (delta[0] instanceof NBTTagCompound) }
return; } else if (mode == ChangeMode.ADD) {
for (Object s : delta) { if (delta[0] instanceof String) {
NBT[0].remove((String) s); NBTTagCompound parsedNBT = parseRawNBT((String) delta[0]);
} addToCompound(NBT[0], parsedNBT);
} } else {
} addToCompound(NBT[0], delta[0]);
}).parser(new Parser<NBTTagCompound>() { }
} else if (mode == ChangeMode.REMOVE) {
@Override if (delta[0] instanceof NBTTagCompound)
public String getVariableNamePattern() { return;
return ".+"; for (Object s : delta) {
} NBT[0].remove((String) s);
}
@Override }
@Nullable }
public NBTTagCompound parse(String rawNBT, ParseContext context) { }).parser(new Parser<NBTTagCompound>() {
if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) {
rawNBT.substring(4); @Override
NBTTagCompound NBT = (NBTTagCompound) parseRawNBT(rawNBT); public String getVariableNamePattern() {
if (NBT.toString().equals("{}")) { return ".+";
return null; }
}
return NBT; @Override
} @Nullable
return null; public NBTTagCompound parse(String rawNBT, ParseContext context) {
} if (rawNBT.startsWith("nbt:{") && rawNBT.endsWith("}")) {
rawNBT.substring(4);
@Override NBTTagCompound NBT = parseRawNBT(rawNBT);
public String toString(NBTTagCompound compound, int arg1) { if (NBT.toString().equals("{}")) {
return compound.toString(); return null;
} }
return NBT;
@Override }
public String toVariableNameString(NBTTagCompound compound) { return null;
return "nbt:" + compound.toString(); }
}
})); @Override
public String toString(NBTTagCompound compound, int arg1) {
} return compound.toString();
}
@Override
public void registerNBTListClassInfo() { @Override
Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() { public String toVariableNameString(NBTTagCompound compound) {
return "nbt:" + compound.toString();
@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(Float[].class, Double[].class, String[].class, NBTTagCompound[].class, Integer[].class, NBTTagList[].class); @Override
} public void registerNBTListClassInfo() {
return null; Classes.registerClass(new ClassInfo<NBTTagList>(NBTTagList.class, "nbtlist").user("nbt ?list ?(tag)?").name("NBT List").changer(new Changer<NBTTagList>() {
}
@SuppressWarnings("unchecked")
@Override @Override
public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) { @Nullable
int typeId = 0; public Class<?>[] acceptChange(ChangeMode mode) {
if (delta instanceof Float[]) { if (mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
typeId = 5; return CollectionUtils.array(Float[].class, Double[].class, String[].class, NBTTagCompound[].class, Integer[].class, NBTTagList[].class);
} else if (delta instanceof Double[]) { }
typeId = 6; return null;
} else if (delta instanceof String[]) { }
typeId = 8;
} else if (delta instanceof NBTTagList[]) { @Override
typeId = 9; public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) {
} else if (delta instanceof NBTTagCompound[]) { int typeId = 0;
typeId = 10; if (delta instanceof Float[]) {
} else if (delta instanceof Integer[]) { typeId = 5;
typeId = 11; } else if (delta instanceof Double[]) {
} else { typeId = 6;
return; } else if (delta instanceof String[]) {
} typeId = 8;
if (mode == ChangeMode.SET) { } else if (delta instanceof NBTTagList[]) {
if (typeId == 9) typeId = 9;
nbtList[0] = (NBTTagList) delta[0]; } else if (delta instanceof NBTTagCompound[]) {
} else if (mode == ChangeMode.ADD) { typeId = 10;
if (getContentsId(nbtList[0]) == typeId) { } else if (delta instanceof Integer[]) {
if (typeId == 5) { typeId = 11;
NBTTagFloat floatTag = new NBTTagFloat((float) delta[0]); } else {
addToList(nbtList[0], floatTag); return;
} else if (typeId == 6) { }
NBTTagDouble doubleTag = new NBTTagDouble((double) delta[0]); if (mode == ChangeMode.SET) {
addToList(nbtList[0], doubleTag); if (typeId == 9)
} else if (typeId == 8) { nbtList[0] = (NBTTagList) delta[0];
NBTTagString stringTag = new NBTTagString((String) delta [0]); } else if (mode == ChangeMode.ADD) {
addToList(nbtList[0], stringTag); if (getContentsId(nbtList[0]) == typeId) {
} else if (typeId == 10) { if (typeId == 5) {
addToList(nbtList[0], delta[0]); NBTTagFloat floatTag = new NBTTagFloat((float) delta[0]);
} else if (typeId == 11) { addToList(nbtList[0], floatTag);
NBTTagInt intTag = new NBTTagInt((int) delta[0]); } else if (typeId == 6) {
addToList(nbtList[0], intTag); NBTTagDouble doubleTag = new NBTTagDouble((double) delta[0]);
} addToList(nbtList[0], doubleTag);
} } else if (typeId == 8) {
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { NBTTagString stringTag = new NBTTagString((String) delta [0]);
nbtList[0] = new NBTTagList(); addToList(nbtList[0], stringTag);
} } else if (typeId == 10) {
} addToList(nbtList[0], delta[0]);
}).parser(new Parser<NBTTagList>() { } else if (typeId == 11) {
NBTTagInt intTag = new NBTTagInt((int) delta[0]);
@Override addToList(nbtList[0], intTag);
public String getVariableNamePattern() { }
return ".+"; }
} } else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
nbtList[0] = new NBTTagList();
@Override }
@Nullable }
public NBTTagList parse(String ignored, ParseContext context) { }).parser(new Parser<NBTTagList>() {
return null;
} @Override
public String getVariableNamePattern() {
@Override return ".+";
public String toString(NBTTagList nbtList, int arg1) { }
return nbtList.toString();
} @Override
@Nullable
@Override public NBTTagList parse(String ignored, ParseContext context) {
public String toVariableNameString(NBTTagList nbtList) { return null;
return nbtList.toString(); }
}
})); @Override
} public String toString(NBTTagList nbtList, int arg1) {
return nbtList.toString();
@Override }
public Object getEntityNBT(Entity entity) {
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle(); @Override
NBTTagCompound NBT = new NBTTagCompound(); public String toVariableNameString(NBTTagList nbtList) {
nmsEntity.e(NBT); return nbtList.toString();
return NBT; }
} }));
}
@Override
public Object getTileNBT(Block block) { @Override
NBTTagCompound NBT = new NBTTagCompound(); public NBTTagCompound getEntityNBT(Entity entity) {
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle();
TileEntity tileEntity = nmsWorld.getTileEntity(block.getX(), block.getY(), block.getZ()); NBTTagCompound NBT = new NBTTagCompound();
if (tileEntity == null) nmsEntity.e(NBT);
return null; return NBT;
tileEntity.b(NBT); }
return NBT;
} @Override
public NBTTagCompound getTileNBT(Block block) {
@Override NBTTagCompound NBT = new NBTTagCompound();
public Object getItemNBT(ItemStack itemStack) { World nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
if (itemStack.getType() == Material.AIR) TileEntity tileEntity = nmsWorld.getTileEntity(block.getX(), block.getY(), block.getZ());
return null; if (tileEntity == null)
NBTTagCompound NBT = new NBTTagCompound(); return null;
net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); tileEntity.b(NBT);
NBT = nmsItem.getTag(); return NBT;
if (NBT == null || NBT.toString().equals("{}")) //Null or empty. }
return null;
return new Object[] { NBT }; @Override
} public NBTTagCompound getItemNBT(ItemStack itemStack) {
if (itemStack.getType() == Material.AIR)
@Override return null;
public void setEntityNBT(Entity entity, Object newCompound) { NBTTagCompound NBT = new NBTTagCompound();
if (newCompound instanceof NBTTagCompound) { net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle(); NBT = nmsItem.getTag();
nmsEntity.f((NBTTagCompound) newCompound); if (NBT == null || NBT.toString().equals("{}")) //Null or empty.
} return null;
} return NBT;
}
@Override
public void setTileNBT(Block block, Object newCompound) { @Override
if (newCompound instanceof NBTTagCompound) { public void setEntityNBT(Entity entity, Object newCompound) {
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); if (newCompound instanceof NBTTagCompound) {
TileEntity tileEntity = nmsWorld.getTileEntity(block.getX(), block.getY(), block.getZ()); net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (tileEntity == null) nmsEntity.f((NBTTagCompound) newCompound);
return; }
tileEntity.a((NBTTagCompound) newCompound); }
tileEntity.update();
nmsWorld.notify(tileEntity.x, tileEntity.y, tileEntity.z); @Override
} public void setTileNBT(Block block, Object newCompound) {
} if (newCompound instanceof NBTTagCompound) {
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
@Override TileEntity tileEntity = nmsWorld.getTileEntity(block.getX(), block.getY(), block.getZ());
public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) { if (tileEntity == null)
if (compound instanceof NBTTagCompound) { return;
if (itemStack.getType() == Material.AIR || itemStack == null) tileEntity.a((NBTTagCompound) newCompound);
return null; tileEntity.update();
if (compound == null || compound.toString().equals("{}")) nmsWorld.notify(tileEntity.x, tileEntity.y, tileEntity.z);
return itemStack; }
net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); }
nmsItem.setTag((NBTTagCompound) compound);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem); @Override
return newItem; public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) {
} if (compound instanceof NBTTagCompound) {
return null; if (itemStack.getType() == Material.AIR || itemStack == null)
} return null;
if (compound == null || compound.toString().equals("{}"))
@Override return itemStack;
public Object getFileNBT(File file) { net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
FileInputStream fis = null; nmsItem.setTag((NBTTagCompound) compound);
try { ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
fis = new FileInputStream(file); return newItem;
} catch (FileNotFoundException ex) { }
return null; //File doesn't exist. return null;
} }
NBTTagCompound fileNBT = null;
try { @Override
fileNBT = NBTCompressedStreamTools.a(fis); public NBTTagCompound getFileNBT(File file) {
fis.close(); FileInputStream fis = null;
} catch (IOException ex) { try {
ex.printStackTrace(); fis = new FileInputStream(file);
} finally { } catch (FileNotFoundException ex) {
try { return null; //File doesn't exist.
fis.close(); }
} catch (IOException ex) { NBTTagCompound fileNBT = null;
ex.printStackTrace(); try {
} fileNBT = NBTCompressedStreamTools.a(fis);
} fis.close();
return fileNBT; } catch (IOException ex) {
} ex.printStackTrace();
} finally {
@Override try {
public void setFileNBT(File file, Object newCompound) { fis.close();
OutputStream os = null; } catch (IOException ex) {
try { ex.printStackTrace();
os = new FileOutputStream(file); }
} catch (FileNotFoundException ex) { }
ex.printStackTrace(); return fileNBT;
} }
try {
NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os); @Override
os.close(); public void setFileNBT(File file, Object newCompound) {
} catch (Exception ex) { OutputStream os = null;
if (ex instanceof EOFException) { try {
; //Ignore, just end of the file os = new FileOutputStream(file);
} else { } catch (FileNotFoundException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} finally { try {
try { NBTCompressedStreamTools.a((NBTTagCompound) newCompound, os);
os.close(); os.close();
} catch (Exception ex) { } catch (Exception ex) {
if (ex instanceof EOFException) { if (ex instanceof EOFException) {
; //Ignore. ; //Ignore, just end of the file
} else { } else {
ex.printStackTrace(); ex.printStackTrace();
} }
} } finally {
} try {
} os.close();
} catch (Exception ex) {
if (ex instanceof EOFException) {
; //Ignore.
} else {
ex.printStackTrace();
}
}
}
}
public NBTTagByte convertToNBT(byte b) {
return new NBTTagByte(b);
}
public NBTTagShort convertToNBT(short s) {
return new NBTTagShort(s);
}
public NBTTagInt convertToNBT(int i) {
return new NBTTagInt(i);
}
public NBTTagLong convertToNBT(long l) {
return new NBTTagLong(l);
}
public NBTTagFloat convertToNBT(float f) {
return new NBTTagFloat(f);
}
public NBTTagDouble convertToNBT(double d) {
return new NBTTagDouble(d);
}
public NBTTagString convertToNBT(String string) {
return new NBTTagString(string);
}
@Override
public Object convertToNBT(Number number) {
if (number instanceof Byte)
return convertToNBT((byte) number);
else if (number instanceof Short)
return convertToNBT((short) number);
else if (number instanceof Integer)
return convertToNBT((int) number);
else if (number instanceof Long)
return convertToNBT((long) number);
else if (number instanceof Float)
return convertToNBT((float) number);
else if (number instanceof Double)
return convertToNBT((double) number);
return number;
}
} }

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,562 @@
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_9_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_9_R1.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_9_R1.BlockPosition;
import net.minecraft.server.v1_9_R1.EntityInsentient;
import net.minecraft.server.v1_9_R1.IBlockData;
import net.minecraft.server.v1_9_R1.MojangsonParseException;
import net.minecraft.server.v1_9_R1.MojangsonParser;
import net.minecraft.server.v1_9_R1.NBTBase;
import net.minecraft.server.v1_9_R1.NBTCompressedStreamTools;
import net.minecraft.server.v1_9_R1.NBTTagByte;
import net.minecraft.server.v1_9_R1.NBTTagCompound;
import net.minecraft.server.v1_9_R1.NBTTagDouble;
import net.minecraft.server.v1_9_R1.NBTTagFloat;
import net.minecraft.server.v1_9_R1.NBTTagInt;
import net.minecraft.server.v1_9_R1.NBTTagList;
import net.minecraft.server.v1_9_R1.NBTTagLong;
import net.minecraft.server.v1_9_R1.NBTTagShort;
import net.minecraft.server.v1_9_R1.NBTTagString;
import net.minecraft.server.v1_9_R1.PathfinderGoal;
import net.minecraft.server.v1_9_R1.PathfinderGoalSelector;
import net.minecraft.server.v1_9_R1.TileEntity;
import net.minecraft.server.v1_9_R1.World;
public class NMS_v1_9_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;
try {
parsedNBT = MojangsonParser.parse(rawNBT);
} catch (MojangsonParseException ex) {
Skript.warning("Error when parsing NBT - " + ex.getMessage());
}
return parsedNBT;
}
@Override
public int getContentsId(Object nbtList) {
if (nbtList instanceof NBTTagList) {
return ((NBTTagList) nbtList).d();
}
return 0;
}
@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).remove(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).h(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 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 || mode == ChangeMode.SET) {
return CollectionUtils.array(String[].class, NBTTagCompound[].class);
}
return null;
}
@Override
public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) {
if (mode == ChangeMode.SET) {
if (delta[0] instanceof NBTTagCompound) {
NBT[0] = (NBTTagCompound) delta[0];
} else {
NBTTagCompound parsedNBT = null;
parsedNBT = parseRawNBT((String) delta[0]);
NBT[0] = parsedNBT;
}
} else if (mode == ChangeMode.ADD) {
if (delta[0] instanceof String) {
NBTTagCompound parsedNBT = null;
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 "nbt:" + 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 = null;
compound = parseRawNBT(s);
return compound;
}
@Override
@Nullable
public NBTTagCompound deserialize(String s) {
NBTTagCompound compound = null;
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(Float[].class, Double[].class, String[].class, NBTTagCompound[].class, Integer[].class, NBTTagList[].class);
}
return null;
}
@Override
public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) {
int typeId = 0;
if (delta instanceof Byte[]) {
typeId = 1;
} else if (delta instanceof Short[]) {
typeId = 2;
} else if (delta instanceof Integer[]) {
typeId = 3;
} else if (delta instanceof Long[]) {
typeId = 4;
} else if (delta instanceof Float[]) {
typeId = 5;
} else if (delta instanceof Double[]) {
typeId = 6;
} else if (delta instanceof String[]) {
typeId = 8;
} else if (delta instanceof NBTTagList[]) {
typeId = 9;
} else if (delta instanceof NBTTagCompound[]) {
typeId = 10;
} else {
return;
}
if (mode == ChangeMode.SET) {
if (typeId == 9)
nbtList[0] = (NBTTagList) delta[0];
} else if (mode == ChangeMode.ADD) {
if (getContentsId(nbtList[0]) == typeId) {
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 NBTTagCompound || delta[0] instanceof NBTTagList)
addToList(nbtList, delta[0]);
}
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
nbtList[0] = new NBTTagList();
}
}
}).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 = null;
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 = null;
tempNBT = parseRawNBT("{SkStuffIsCool:" + s + "}");
NBTTagList nbtList = (NBTTagList) tempNBT.get("SkStuffIsCool");
return nbtList;
}
@Override
@Nullable
public NBTTagList deserialize(String s) {
NBTTagCompound tempNBT = null;
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_9_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.save(NBT);
return NBT;
}
@Override
public NBTTagCompound getItemNBT(ItemStack itemStack) {
if (itemStack.getType() == Material.AIR)
return null;
NBTTagCompound itemNBT = CraftItemStack.asNMSCopy(itemStack).getTag();
if (String.valueOf(itemNBT).equals("{}"))
itemNBT = null;
return itemNBT;
}
@Override
public void setEntityNBT(Entity entity, Object newCompound) {
if (newCompound instanceof NBTTagCompound) {
net.minecraft.server.v1_9_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();
IBlockData tileEntType = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ()));
nmsWorld.notify(tileEntity.getPosition(), tileEntType, tileEntType, 3);
}
}
@Override
public ItemStack getItemWithNBT(ItemStack itemStack, Object compound) {
net.minecraft.server.v1_9_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);
}
}

View File

@ -1,64 +1,74 @@
package me.TheBukor.SkStuff.util; package me.TheBukor.SkStuff.util;
import java.lang.reflect.Field; import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import org.bukkit.Bukkit;
import org.bukkit.Bukkit;
public class ReflectionUtils {
public class ReflectionUtils {
public static Class<?> getNMSClass(String classString, boolean isArray) {
String version = getVersion(); public static Class<?> getNMSClass(String classString) {
String name = "net.minecraft.server." + version + classString; String version = getVersion();
if (isArray) String name = "net.minecraft.server." + version + classString;
name = "[L" + name + ";"; Class<?> nmsClass = null;
Class<?> nmsClass = null; try {
try { nmsClass = Class.forName(name);
nmsClass = Class.forName(name); } catch (ClassNotFoundException ex) {
} catch (ClassNotFoundException ex) { Bukkit.getLogger().warning("Unable to get NMS class \'" + name + "\'! You are probably running an unsupported version!");
Bukkit.getLogger().warning("Unable to get NMS class \'" + name + "\'! You are probably running an unsupported version!"); return null;
return null; }
} return nmsClass;
return nmsClass; }
}
public static Class<?> getOBCClass(String classString) {
public static Class<?> getOBCClass(String classString) { String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + ".";
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + "."; String name = "org.bukkit.craftbukkit." + version + classString;
String name = "org.bukkit.craftbukkit." + version + classString; Class<?> obcClass = null;
Class<?> obcClass = null; try {
try { obcClass = Class.forName(name);
obcClass = Class.forName(name); } catch (ClassNotFoundException ex) {
} catch (ClassNotFoundException ex) { Bukkit.getLogger().warning("Unable to get OBC class \'" + name + "\'! You are probably running an unsupported version!");
Bukkit.getLogger().warning("Unable to get OBC class \'" + name + "\'! You are probably running an unsupported version!"); return null;
return null; }
} return obcClass;
return obcClass; }
}
public static Object getField(String field, Class<?> clazz, Object object) {
public static Object getField(String field, Class<?> clazz, Object object) { Field f = null;
Field f = null; Object obj = null;
Object obj = null; try {
try { f = clazz.getDeclaredField(field);
f = clazz.getDeclaredField(field); f.setAccessible(true);
f.setAccessible(true); obj = f.get(object);
obj = f.get(object); } catch (Exception ex) {
} catch (Exception ex) { ex.printStackTrace();
ex.printStackTrace(); }
} return obj;
return obj; }
}
public static void setField(String field, Class<?> clazz, Object object, Object toSet) {
public static void setField(String field, Class<?> clazz, Object object, Object toSet) { Field f = null;
Field f = null; try {
try { f = clazz.getDeclaredField(field);
f = clazz.getDeclaredField(field); f.setAccessible(true);
f.setAccessible(true); f.set(object, toSet);
f.set(object, toSet); } catch (Exception ex) {
} catch (Exception ex) { ex.printStackTrace();
ex.printStackTrace(); }
} }
}
public static Constructor<?> getConstructor(String constructor, Class<?> clazz, Object object, Class<?> ... params) {
public static String getVersion() { Constructor<?> constr = null;
return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + "."; try {
} constr = clazz.getDeclaredConstructor(params);
constr.setAccessible(true);
} catch (Exception ex) {
ex.printStackTrace();
}
return constr;
}
public static String getVersion() {
return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + ".";
}
} }