From 925e92673eea29ba13fe5151e1aa7aec9357f9ca Mon Sep 17 00:00:00 2001 From: Richard Date: Sat, 12 Dec 2015 18:17:45 -0200 Subject: [PATCH] New WorldEdit effects, "Tag of compound" expression now settable. Also probably broke some stuff. --- src/me/TheBukor/SkStuff.java | 219 +++++++++--------- src/me/TheBukor/effects/EffDrawLineWE.java | 35 +-- src/me/TheBukor/effects/EffMakePyramid.java | 68 ++++++ src/me/TheBukor/effects/EffMakeSphere.java | 74 ++++++ .../TheBukor/effects/EffRememberChanges.java | 42 ++++ .../TheBukor/effects/EffUndoRedoSession.java | 4 +- .../expressions/ExprTagOfv1_7_R1.java | 90 ++++++- .../expressions/ExprTagOfv1_7_R2.java | 90 ++++++- .../expressions/ExprTagOfv1_7_R3.java | 90 ++++++- .../expressions/ExprTagOfv1_7_R4.java | 90 ++++++- .../expressions/ExprTagOfv1_8_R1.java | 90 ++++++- .../expressions/ExprTagOfv1_8_R2.java | 90 ++++++- .../expressions/ExprTagOfv1_8_R3.java | 83 +++++++ 13 files changed, 923 insertions(+), 142 deletions(-) create mode 100644 src/me/TheBukor/effects/EffMakePyramid.java create mode 100644 src/me/TheBukor/effects/EffMakeSphere.java create mode 100644 src/me/TheBukor/effects/EffRememberChanges.java diff --git a/src/me/TheBukor/SkStuff.java b/src/me/TheBukor/SkStuff.java index 52b12a6..aaf1e9f 100644 --- a/src/me/TheBukor/SkStuff.java +++ b/src/me/TheBukor/SkStuff.java @@ -17,6 +17,9 @@ import ch.njol.skript.lang.ParseContext; import ch.njol.skript.registrations.Classes; import me.TheBukor.conditions.CondSelectionContains; import me.TheBukor.effects.EffDrawLineWE; +import me.TheBukor.effects.EffMakePyramid; +import me.TheBukor.effects.EffMakeSphere; +import me.TheBukor.effects.EffRememberChanges; import me.TheBukor.effects.EffUndoRedoSession; import me.TheBukor.expressions.ExprAreaOfSchematic; import me.TheBukor.expressions.ExprAreaOfSelection; @@ -67,6 +70,7 @@ public class SkStuff extends JavaPlugin { private int exprAmount = 0; private int typeAmount = 0; private int effAmount = 0; + public void onEnable() { if (Bukkit.getPluginManager().getPlugin("Skript") != null) { Skript.registerAddon(this); @@ -79,23 +83,26 @@ public class SkStuff extends JavaPlugin { Skript.registerExpression(ExprItemNBTv1_7_R1.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOfv1_7_R1.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%"); //WARNING! HIGHLY EXPERIMENTAL, IT CAN CORRUPT WORLDS AT CURRENT VERSION, USE AT YOUR OWN RISK! - //Skript.registerExpression(ExprFileNBTv1_7_R1.class, net.minecraft.server.v1_7_R1.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%"); - Classes.registerClass(new ClassInfo(net.minecraft.server.v1_7_R1.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { + //Skript.registerExpression(ExprFileNBTv1_7_R1.class, net.minecraft.server.v1_7_R1.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%"); + Classes.registerClass(new ClassInfo(net.minecraft.server.v1_7_R1.NBTTagCompound.class, "compound").name("NBT Tag Compound").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser() { @Override public String getVariableNamePattern() { - return ".+"; + return "{.+:.+}"; } @Override @Nullable public net.minecraft.server.v1_7_R1.NBTTagCompound parse(String s, ParseContext context) { - net.minecraft.server.v1_7_R1.NBTTagCompound NBT = new net.minecraft.server.v1_7_R1.NBTTagCompound(); - net.minecraft.server.v1_7_R1.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R1.NBTTagCompound) net.minecraft.server.v1_7_R1.MojangsonParser.a(s); - NBT.set("", NBT1); - if (NBT.isEmpty() || NBT == null) { - return null; + if (s.startsWith("{")) { + net.minecraft.server.v1_7_R1.NBTTagCompound NBT = new net.minecraft.server.v1_7_R1.NBTTagCompound(); + net.minecraft.server.v1_7_R1.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R1.NBTTagCompound) net.minecraft.server.v1_7_R1.MojangsonParser.a(s); + NBT.set("", NBT1); + if (NBT.isEmpty() || NBT == null) { + return null; + } + return NBT; } - return NBT; + return null; } @Override @@ -117,23 +124,26 @@ public class SkStuff extends JavaPlugin { Skript.registerExpression(ExprItemNBTv1_7_R2.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOfv1_7_R2.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%"); //WARNING! HIGHLY EXPERIMENTAL, IT CAN CORRUPT WORLDS AT CURRENT VERSION, USE AT YOUR OWN RISK! - //Skript.registerExpression(ExprFileNBTv1_7_R2.class, net.minecraft.server.v1_7_R2.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%"); - Classes.registerClass(new ClassInfo(net.minecraft.server.v1_7_R2.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { + //Skript.registerExpression(ExprFileNBTv1_7_R2.class, net.minecraft.server.v1_7_R2.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%"); + Classes.registerClass(new ClassInfo(net.minecraft.server.v1_7_R2.NBTTagCompound.class, "compound").name("NBT Tag Compound").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser() { @Override public String getVariableNamePattern() { - return ".+"; + return "nbt:{.+:.+}"; } @Override @Nullable public net.minecraft.server.v1_7_R2.NBTTagCompound parse(String s, ParseContext context) { - net.minecraft.server.v1_7_R2.NBTTagCompound NBT = new net.minecraft.server.v1_7_R2.NBTTagCompound(); - net.minecraft.server.v1_7_R2.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R2.NBTTagCompound) net.minecraft.server.v1_7_R2.MojangsonParser.parse(s); - NBT.set("", NBT1); - if (NBT.isEmpty() || NBT == null) { - return null; + if (s.startsWith("{")) { + net.minecraft.server.v1_7_R2.NBTTagCompound NBT = new net.minecraft.server.v1_7_R2.NBTTagCompound(); + net.minecraft.server.v1_7_R2.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R2.NBTTagCompound) net.minecraft.server.v1_7_R2.MojangsonParser.parse(s); + NBT.set("", NBT1); + if (NBT.isEmpty() || NBT == null) { + return null; + } + return NBT; } - return NBT; + return null; } @Override @@ -143,7 +153,7 @@ public class SkStuff extends JavaPlugin { @Override public String toVariableNameString(net.minecraft.server.v1_7_R2.NBTTagCompound compound) { - return compound.toString(); + return "nbt:" + compound.toString(); } })); } @@ -155,23 +165,26 @@ public class SkStuff extends JavaPlugin { Skript.registerExpression(ExprItemNBTv1_7_R3.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOfv1_7_R3.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%"); //WARNING! HIGHLY EXPERIMENTAL, IT CAN CORRUPT WORLDS AT CURRENT VERSION, USE AT YOUR OWN RISK! - //Skript.registerExpression(ExprFileNBTv1_7_R3.class, net.minecraft.server.v1_7_R3.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%"); - Classes.registerClass(new ClassInfo(net.minecraft.server.v1_7_R3.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { + //Skript.registerExpression(ExprFileNBTv1_7_R3.class, net.minecraft.server.v1_7_R3.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%"); + Classes.registerClass(new ClassInfo(net.minecraft.server.v1_7_R3.NBTTagCompound.class, "compound").name("NBT Tag Compound").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser() { @Override public String getVariableNamePattern() { - return ".+"; + return "nbt:{.+:.+}"; } @Override @Nullable public net.minecraft.server.v1_7_R3.NBTTagCompound parse(String s, ParseContext context) { - net.minecraft.server.v1_7_R3.NBTTagCompound NBT = new net.minecraft.server.v1_7_R3.NBTTagCompound(); - net.minecraft.server.v1_7_R3.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R3.NBTTagCompound) net.minecraft.server.v1_7_R3.MojangsonParser.parse(s); - NBT.set("", NBT1); - if (NBT.isEmpty() || NBT == null) { - return null; + if (s.startsWith("{")) { + net.minecraft.server.v1_7_R3.NBTTagCompound NBT = new net.minecraft.server.v1_7_R3.NBTTagCompound(); + net.minecraft.server.v1_7_R3.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R3.NBTTagCompound) net.minecraft.server.v1_7_R3.MojangsonParser.parse(s); + NBT.set("", NBT1); + if (NBT.isEmpty() || NBT == null) { + return null; + } + return NBT; } - return NBT; + return null; } @Override @@ -181,7 +194,7 @@ public class SkStuff extends JavaPlugin { @Override public String toVariableNameString(net.minecraft.server.v1_7_R3.NBTTagCompound compound) { - return compound.toString(); + return "nbt:" + compound.toString(); } })); } @@ -193,24 +206,27 @@ public class SkStuff extends JavaPlugin { Skript.registerExpression(ExprItemNBTv1_7_R4.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOfv1_7_R4.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%"); //WARNING! HIGHLY EXPERIMENTAL, IT CAN CORRUPT WORLDS AT CURRENT VERSION, USE AT YOUR OWN RISK! - //Skript.registerExpression(ExprFileNBTv1_7_R4.class, net.minecraft.server.v1_7_R4.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%"); - Classes.registerClass(new ClassInfo(net.minecraft.server.v1_7_R4.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { + //Skript.registerExpression(ExprFileNBTv1_7_R4.class, net.minecraft.server.v1_7_R4.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%"); + Classes.registerClass(new ClassInfo(net.minecraft.server.v1_7_R4.NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Tag Compound").parser(new Parser() { @Override public String getVariableNamePattern() { - return ".+"; + return "nbt:{.+:.+}"; } @Override @Nullable public net.minecraft.server.v1_7_R4.NBTTagCompound parse(String s, ParseContext context) { - net.minecraft.server.v1_7_R4.NBTTagCompound NBT = new net.minecraft.server.v1_7_R4.NBTTagCompound(); - net.minecraft.server.v1_7_R4.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R4.NBTTagCompound) net.minecraft.server.v1_7_R4.MojangsonParser.parse(s); - NBT.set("", NBT1); - if (NBT.isEmpty() || NBT == null) { - return null; + if (s.startsWith("{")) { + net.minecraft.server.v1_7_R4.NBTTagCompound NBT = new net.minecraft.server.v1_7_R4.NBTTagCompound(); + net.minecraft.server.v1_7_R4.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R4.NBTTagCompound) net.minecraft.server.v1_7_R4.MojangsonParser.parse(s); + NBT.set("", NBT1); + if (NBT.isEmpty() || NBT == null) { + return null; + } + return NBT; } - return NBT; + return null; } @Override @@ -220,7 +236,7 @@ public class SkStuff extends JavaPlugin { @Override public String toVariableNameString(net.minecraft.server.v1_7_R4.NBTTagCompound compound) { - return compound.toString(); + return "nbt:" + compound.toString(); } })); } @@ -232,24 +248,28 @@ public class SkStuff extends JavaPlugin { Skript.registerExpression(ExprItemNBTv1_8_R1.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOfv1_8_R1.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%"); //WARNING! HIGHLY EXPERIMENTAL, IT CAN CORRUPT WORLDS AT CURRENT VERSION, USE AT YOUR OWN RISK! - Skript.registerExpression(ExprFileNBTv1_8_R1.class, NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%"); - Classes.registerClass(new ClassInfo(NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { + Skript.registerExpression(ExprFileNBTv1_8_R1.class, NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%"); + Classes.registerClass(new ClassInfo(NBTTagCompound.class, "compound").name("NBT Tag Compound").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser() { @Override public String getVariableNamePattern() { - return ".+"; + return "nbt:{.+:.+}"; } @Override @Nullable public NBTTagCompound parse(String s, ParseContext context) { - NBTTagCompound NBT = new NBTTagCompound(); - NBTTagCompound NBT1 = MojangsonParser.parse(s); - NBT.a(NBT1); - if (NBT.isEmpty() || NBT == null) { - return null; + if (s.startsWith("{")) { + NBTTagCompound NBT = new NBTTagCompound(); + NBTTagCompound NBT1 = null; + NBT1 = MojangsonParser.parse(s); + NBT.a(NBT1); + if (NBT.isEmpty() || NBT == null) { + return null; + } + return NBT; } - return NBT; + return null; } @Override @@ -259,7 +279,7 @@ public class SkStuff extends JavaPlugin { @Override public String toVariableNameString(NBTTagCompound compound) { - return compound.toString(); + return "nbt:" + compound.toString(); } })); } @@ -271,28 +291,31 @@ public class SkStuff extends JavaPlugin { Skript.registerExpression(ExprItemNBTv1_8_R2.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOfv1_8_R2.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%"); //WARNING! HIGHLY EXPERIMENTAL, IT CAN CORRUPT WORLDS AT CURRENT VERSION, USE AT YOUR OWN RISK! - Skript.registerExpression(ExprFileNBTv1_8_R2.class, net.minecraft.server.v1_8_R2.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%"); - Classes.registerClass(new ClassInfo(net.minecraft.server.v1_8_R2.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { + Skript.registerExpression(ExprFileNBTv1_8_R2.class, net.minecraft.server.v1_8_R2.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%"); + Classes.registerClass(new ClassInfo(net.minecraft.server.v1_8_R2.NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Tag Compound").parser(new Parser() { @Override public String getVariableNamePattern() { - return ".+"; + return "nbt:{.+:.+}"; } @Override @Nullable public net.minecraft.server.v1_8_R2.NBTTagCompound parse(String s, ParseContext context) { - net.minecraft.server.v1_8_R2.NBTTagCompound NBT = new net.minecraft.server.v1_8_R2.NBTTagCompound(); - try { - net.minecraft.server.v1_8_R2.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R2.MojangsonParser.parse(s); - NBT.a(NBT1); - } catch (MojangsonParseException ex) { - Skript.warning("Error when parsing NBT - " + ex.getMessage()); + if (s.startsWith("{")) { + net.minecraft.server.v1_8_R2.NBTTagCompound NBT = new net.minecraft.server.v1_8_R2.NBTTagCompound(); + try { + net.minecraft.server.v1_8_R2.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R2.MojangsonParser.parse(s); + NBT.a(NBT1); + } catch (MojangsonParseException ex) { + Skript.warning("Error when parsing NBT - " + ex.getMessage()); + } + if (NBT.isEmpty() || NBT == null) { + return null; + } + return NBT; } - if (NBT.isEmpty() || NBT == null) { - return null; - } - return NBT; + return null; } @Override @@ -302,7 +325,7 @@ public class SkStuff extends JavaPlugin { @Override public String toVariableNameString(net.minecraft.server.v1_8_R2.NBTTagCompound compound) { - return compound.toString(); + return "nbt:" + compound.toString(); } })); } @@ -314,28 +337,31 @@ public class SkStuff extends JavaPlugin { Skript.registerExpression(ExprItemNBTv1_8_R3.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOfv1_8_R3.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%"); //WARNING! HIGHLY EXPERIMENTAL, IT CAN CORRUPT WORLDS AT CURRENT VERSION, USE AT YOUR OWN RISK! - Skript.registerExpression(ExprFileNBTv1_8_R3.class, net.minecraft.server.v1_8_R3.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%"); - Classes.registerClass(new ClassInfo(net.minecraft.server.v1_8_R3.NBTTagCompound.class, "compound").name("NBT Compound").parser(new Parser() { + Skript.registerExpression(ExprFileNBTv1_8_R3.class, net.minecraft.server.v1_8_R3.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%"); + Classes.registerClass(new ClassInfo(net.minecraft.server.v1_8_R3.NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").parser(new Parser() { @Override public String getVariableNamePattern() { - return ".+"; + return "nbt:{.+:.+}"; } @Override @Nullable public net.minecraft.server.v1_8_R3.NBTTagCompound parse(String s, ParseContext context) { - net.minecraft.server.v1_8_R3.NBTTagCompound NBT = new net.minecraft.server.v1_8_R3.NBTTagCompound(); - try { - net.minecraft.server.v1_8_R3.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R3.MojangsonParser.parse(s); - NBT.a(NBT1); - } catch (net.minecraft.server.v1_8_R3.MojangsonParseException ex) { - return null; + if (s.startsWith("{")) { + net.minecraft.server.v1_8_R3.NBTTagCompound NBT = new net.minecraft.server.v1_8_R3.NBTTagCompound(); + try { + net.minecraft.server.v1_8_R3.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R3.MojangsonParser.parse(s); + NBT.a(NBT1); + } catch (net.minecraft.server.v1_8_R3.MojangsonParseException ex) { + return null; + } + if (NBT.isEmpty() || NBT == null) { + return null; + } + return NBT; } - if (NBT.isEmpty() || NBT == null) { - return null; - } - return NBT; + return null; } @Override @@ -345,7 +371,7 @@ public class SkStuff extends JavaPlugin { @Override public String toVariableNameString(net.minecraft.server.v1_8_R3.NBTTagCompound compound) { - return compound.toString(); + return "nbt:" + compound.toString(); } })); } @@ -357,11 +383,14 @@ public class SkStuff extends JavaPlugin { typeAmount += 1; 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%"); // EXPERIMENTAL EFFECTS/EXPRESSIONS - Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a] (no(n|t)(-| )hollow|filled) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block] %itemstack% [(and|with)] thick[ness] %double%", "(create|draw|make) [a] hollow line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block] %itemstack% [(and|with)] thick[ness] %double%"); - Skript.registerEffect(EffUndoRedoSession.class, "undo [last] (change|edit)[s] (of|from) [edit[ ]session] %editsession%", "redo [last] (change|edit)[s] (of|from) [edit[ ]session] %editsession%"); + Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a] (0¦[(no(n|t)(-| )hollow|filled|)]|1¦hollow) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstack% [(and|with)] thick[ness] %double%"); + Skript.registerEffect(EffUndoRedoSession.class, "(0¦undo|1¦redo) [last] (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(EffMakeSphere.class, "(create|make) [a] (0¦[(no(n|t)(-| )hollow|filled|)]|1¦hollow) (ellipsoid|sphere) [centered] at %location% [with] radius [of] %number%, %number%(,| and) %number% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstack%"); + Skript.registerEffect(EffMakePyramid.class, "(create|make) [a] (0¦[(no(n|t)(-| )hollow|filled|)]|1¦hollow) pyramid at %location% [with] radius [of] %integer% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstack%"); Skript.registerExpression(ExprEditSessionLimit.class, Integer.class, ExpressionType.PROPERTY, "[block] limit [change] of [edit[ ]session] %editsession%"); Skript.registerExpression(ExprChangedBlocksSession.class, Integer.class, ExpressionType.PROPERTY, "number of [all] changed blocks (in|of) [edit[ ]session] %editsession%"); - Skript.registerExpression(ExprNewEditSession.class, EditSession.class, ExpressionType.PROPERTY, "[create] [a] 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%"); // END OF EXPERIMENTAL EFFS/EXPRS Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection"); Skript.registerExpression(ExprSelectionPos1.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ]1 of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ]1"); @@ -376,35 +405,7 @@ public class SkStuff extends JavaPlugin { Skript.registerExpression(ExprHeightOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(y( |-)size|height) of schem[atic] [from] %string%"); Skript.registerExpression(ExprLengthOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(z( |-)size|length) of schem[atic] [from] %string%"); Skript.registerExpression(ExprAreaOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "area of schem[atic] [from] %string%"); - Classes.registerClass(new ClassInfo(EditSession.class, "editsession").name("Edit Session").parser(new Parser() { - - @Override - public String getVariableNamePattern() { - return ".+"; - } - - @Override - @Nullable - public EditSession parse(String s, ParseContext context) { - return null; - } - - @Override - public boolean canParse(ParseContext context) { - return false; - } - - @Override - public String toString(EditSession editSession, int arg1) { - return null; - } - - @Override - public String toVariableNameString(EditSession editSession) { - return null; - } - - })); + Classes.registerClass(new ClassInfo(EditSession.class, "editsession").name("Edit Session").user("edit ?sessions?")); } getLogger().info("Everything ready! Loaded a total of " + condAmount + (condAmount == 1 ? " condition, " : " conditions, ") + effAmount + (effAmount == 1 ? " effect, " : " effects, ") + exprAmount + (exprAmount == 1 ? " expression" : " expressions and ") + typeAmount + (typeAmount == 1 ? " type!" : " types!")); } else { diff --git a/src/me/TheBukor/effects/EffDrawLineWE.java b/src/me/TheBukor/effects/EffDrawLineWE.java index 81296a2..29088c4 100644 --- a/src/me/TheBukor/effects/EffDrawLineWE.java +++ b/src/me/TheBukor/effects/EffDrawLineWE.java @@ -8,9 +8,10 @@ import org.bukkit.inventory.ItemStack; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.patterns.Pattern; import ch.njol.skript.lang.Effect; @@ -23,25 +24,25 @@ public class EffDrawLineWE extends Effect { private Expression location1; private Expression location2; private Expression editSession; - private Expression block; + private Expression blockList; private Expression thickness; private boolean filled = true; @SuppressWarnings("unchecked") @Override - public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { location1 = (Expression) expr[0]; location2 = (Expression) expr[1]; editSession = (Expression) expr[2]; - block = (Expression) expr[3]; + blockList = (Expression) expr[3]; thickness = (Expression) expr[4]; - if (matchedPattern == 1) filled = false; + if (result.mark == 1) filled = false; return true; } @Override public String toString(@Nullable Event e, boolean arg1) { - return "draw a line from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " using an edit session with " + block.toString(e, false) + " and thickness " + thickness.toString(e, false); + return "draw a line from " + location1.toString(e, false) + " to " + location2.toString(e, false) + " using an edit session with " + blockList.toString(e, false) + " and thickness " + thickness.toString(e, false); } @Override @@ -49,15 +50,23 @@ public class EffDrawLineWE extends Effect { Location pos1 = location1.getSingle(e); Location pos2 = location2.getSingle(e); EditSession session = editSession.getSingle(e); - ItemStack b = block.getSingle(e); + ItemStack[] blocks = blockList.getAll(e); Double thick = thickness.getSingle(e); - if (b.getType().isBlock()) { - try { - session.drawLine((Pattern) new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2), thick, filled); - session.flushQueue(); - } catch (MaxChangedBlocksException ex) { - return; + RandomPattern random = new RandomPattern(); + for (ItemStack b : blocks) { + if (b.getType().isBlock()) { + try { + random.add(new BlockPattern(BukkitUtil.toBlock(BukkitUtil.getLocalWorld(pos1.getWorld()), b)), 50); + } catch (WorldEditException ex) { + ex.printStackTrace(); + } } } + try { + session.drawLine((Pattern) random, BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2), thick, filled); + session.flushQueue(); + } catch (MaxChangedBlocksException ex) { + return; + } } } diff --git a/src/me/TheBukor/effects/EffMakePyramid.java b/src/me/TheBukor/effects/EffMakePyramid.java new file mode 100644 index 0000000..9b329e6 --- /dev/null +++ b/src/me/TheBukor/effects/EffMakePyramid.java @@ -0,0 +1,68 @@ +package me.TheBukor.effects; + +import javax.annotation.Nullable; + +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.bukkit.BukkitUtil; +import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.RandomPattern; +import com.sk89q.worldedit.patterns.Pattern; + +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; + +@SuppressWarnings("deprecation") +public class EffMakePyramid extends Effect { + private Expression location; + private Expression radius; + private Expression editSession; + private Expression blockList; + private boolean filled = true; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { + location = (Expression) expr[0]; + radius = (Expression) expr[1]; + editSession = (Expression) expr[2]; + blockList = (Expression) expr[3]; + if (result.mark == 1) filled = false; + return true; + } + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "create a pyramid at " + location.toString(e, false) + " with a radius of " + radius.toString(e, false) + " using an edit session with " + blockList.toString(e, false); + } + + @Override + protected void execute(Event e) { + Location loc = location.getSingle(e); + Integer rad = radius.getSingle(e); + EditSession session = editSession.getSingle(e); + ItemStack[] blocks = blockList.getAll(e); + RandomPattern random = new RandomPattern(); + for (ItemStack b : blocks) { + if (b.getType().isBlock()) { + try { + random.add(new BlockPattern(BukkitUtil.toBlock(BukkitUtil.getLocalWorld(loc.getWorld()), b)), 50); + } catch (WorldEditException ex) { + ex.printStackTrace(); + } + } + } + try { + session.makePyramid(BukkitUtil.toVector(loc), (Pattern) random, rad, filled); + session.flushQueue(); + } catch (MaxChangedBlocksException ex) { + return; + } + } +} \ No newline at end of file diff --git a/src/me/TheBukor/effects/EffMakeSphere.java b/src/me/TheBukor/effects/EffMakeSphere.java new file mode 100644 index 0000000..43f30fd --- /dev/null +++ b/src/me/TheBukor/effects/EffMakeSphere.java @@ -0,0 +1,74 @@ +package me.TheBukor.effects; + +import javax.annotation.Nullable; + +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.bukkit.BukkitUtil; +import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.RandomPattern; +import com.sk89q.worldedit.patterns.Pattern; + +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; + +@SuppressWarnings("deprecation") +public class EffMakeSphere extends Effect { + private Expression location; + private Expression radius1; + private Expression radius2; + private Expression radius3; + private Expression editSession; + private Expression blockList; + private boolean filled = true; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { + location = (Expression) expr[0]; + radius1 = (Expression) expr[1]; + radius2 = (Expression) expr[2]; + radius3 = (Expression) expr[3]; + editSession = (Expression) expr[4]; + blockList = (Expression) expr[5]; + if (result.mark == 1) filled = false; + return true; + } + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "create a sphere centered at " + location.toString(e, false) + " with a radius of " + radius1.toString(e, false) + " " + radius2.toString(e, false) + " " + radius3.toString(e, false) + " using an edit session with " + blockList.toString(e, false); + } + + @Override + protected void execute(Event e) { + Location loc = location.getSingle(e); + Double rad1 = radius1.getSingle(e); + Double rad2 = radius2.getSingle(e); + Double rad3 = radius3.getSingle(e); + EditSession session = editSession.getSingle(e); + ItemStack[] blocks = blockList.getAll(e); + RandomPattern random = new RandomPattern(); + for (ItemStack b : blocks) { + if (b.getType().isBlock()) { + try { + random.add(new BlockPattern(BukkitUtil.toBlock(BukkitUtil.getLocalWorld(loc.getWorld()), b)), 50); + } catch (WorldEditException ex) { + ex.printStackTrace(); + } + } + } + try { + session.makeSphere(BukkitUtil.toVector(loc), (Pattern) random, rad1, rad2, rad3, filled); + session.flushQueue(); + } catch (MaxChangedBlocksException ex) { + return; + } + } +} \ No newline at end of file diff --git a/src/me/TheBukor/effects/EffRememberChanges.java b/src/me/TheBukor/effects/EffRememberChanges.java new file mode 100644 index 0000000..4a06c9f --- /dev/null +++ b/src/me/TheBukor/effects/EffRememberChanges.java @@ -0,0 +1,42 @@ +package me.TheBukor.effects; + +import javax.annotation.Nullable; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; + +public class EffRememberChanges extends Effect { + private Expression player; + private Expression editSession; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + player = (Expression) expr[0]; + editSession = (Expression) expr[1]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "make " + player.toString(e, false) + " remember changes from edit session"; + } + + @Override + protected void execute(Event e) { + WorldEditPlugin we = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); + Player p = player.getSingle(e); + EditSession session = editSession.getSingle(e); + if (we.getSession(p) == null) return; + we.getSession(p).remember(session); + } +} \ No newline at end of file diff --git a/src/me/TheBukor/effects/EffUndoRedoSession.java b/src/me/TheBukor/effects/EffUndoRedoSession.java index d4b4fda..63d9e67 100644 --- a/src/me/TheBukor/effects/EffUndoRedoSession.java +++ b/src/me/TheBukor/effects/EffUndoRedoSession.java @@ -17,9 +17,9 @@ public class EffUndoRedoSession extends Effect { @SuppressWarnings("unchecked") @Override - public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { editSession = (Expression) expr[0]; - if (matchedPattern == 1) redo = true; + if (result.mark == 1) redo = true; return true; } diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_7_R1.java b/src/me/TheBukor/expressions/ExprTagOfv1_7_R1.java index 431adca..680fdec 100644 --- a/src/me/TheBukor/expressions/ExprTagOfv1_7_R1.java +++ b/src/me/TheBukor/expressions/ExprTagOfv1_7_R1.java @@ -2,14 +2,16 @@ package me.TheBukor.expressions; import javax.annotation.Nullable; +import org.bukkit.Bukkit; import org.bukkit.event.Event; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; import net.minecraft.server.v1_7_R1.NBTTagCompound; -import net.minecraft.server.v1_7_R1.NBTTagList; public class ExprTagOfv1_7_R1 extends SimpleExpression { private Expression string; @@ -39,7 +41,7 @@ public class ExprTagOfv1_7_R1 extends SimpleExpression { @Nullable protected Object[] get(Event e) { NBTTagCompound NBT = compound.getSingle(e); - if (NBT.isEmpty() || NBT == null) return null; //The NBT can be empty/inexistant for items + if (NBT == null || NBT.isEmpty()) return null; //The NBT can be empty/inexistant for items String tag = string.getSingle(e); if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return . Byte id = NBT.get(tag).getTypeId(); @@ -68,7 +70,8 @@ public class ExprTagOfv1_7_R1 extends SimpleExpression { returned = new String[] { NBT.getString(tag) }; break; case 9: //List, will need to make a new type if getCompound() doesn't work here - returned = new NBTTagList[] { NBT.getList(tag, 5) }; //Is the int argument the type ID? + Bukkit.broadcastMessage("LIST!"); + returned = new Object[] { NBT.getList(tag, 0).toString() }; //Is the int argument the type ID? break; case 10: returned = new NBTTagCompound[] { NBT.getCompound(tag) }; @@ -80,4 +83,85 @@ public class ExprTagOfv1_7_R1 extends SimpleExpression { } return returned; } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + NBTTagCompound NBT = compound.getSingle(e); + if (NBT == null) NBT = new NBTTagCompound(); //If the NBT isn't set, create an empty one + String tag = string.getSingle(e); + Object newValue = delta[0]; + if (mode == ChangeMode.SET) { + if (newValue instanceof Byte) { + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + NBT.setInt(tag, (int) newValue);; + } else if (newValue instanceof Long) { + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + NBT.setDouble(tag, (double) newValue); + } else if (newValue instanceof String) { + NBT.setString(tag, (String) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.ADD) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) + (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) + (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) + (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) + (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) + (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) + (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.REMOVE) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) - (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) - (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) - (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) - (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) - (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) - (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { + return CollectionUtils.array(Object.class); + } + return null; + } } \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_7_R2.java b/src/me/TheBukor/expressions/ExprTagOfv1_7_R2.java index cc474cf..cea46b2 100644 --- a/src/me/TheBukor/expressions/ExprTagOfv1_7_R2.java +++ b/src/me/TheBukor/expressions/ExprTagOfv1_7_R2.java @@ -2,14 +2,16 @@ package me.TheBukor.expressions; import javax.annotation.Nullable; +import org.bukkit.Bukkit; import org.bukkit.event.Event; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; import net.minecraft.server.v1_7_R2.NBTTagCompound; -import net.minecraft.server.v1_7_R2.NBTTagList; public class ExprTagOfv1_7_R2 extends SimpleExpression { private Expression string; @@ -39,7 +41,7 @@ public class ExprTagOfv1_7_R2 extends SimpleExpression { @Nullable protected Object[] get(Event e) { NBTTagCompound NBT = compound.getSingle(e); - if (NBT.isEmpty() || NBT == null) return null; //The NBT can be empty/inexistant for items + if (NBT == null || NBT.isEmpty()) return null; //The NBT can be empty/inexistant for items String tag = string.getSingle(e); if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return . Byte id = NBT.get(tag).getTypeId(); @@ -68,7 +70,8 @@ public class ExprTagOfv1_7_R2 extends SimpleExpression { returned = new String[] { NBT.getString(tag) }; break; case 9: //List, will need to make a new type if getCompound() doesn't work here - returned = new NBTTagList[] { NBT.getList(tag, 5) }; //Is the int argument the type ID? + Bukkit.broadcastMessage("LIST!"); + returned = new Object[] { NBT.getList(tag, 0).toString() }; //Is the int argument the type ID? break; case 10: returned = new NBTTagCompound[] { NBT.getCompound(tag) }; @@ -80,4 +83,85 @@ public class ExprTagOfv1_7_R2 extends SimpleExpression { } return returned; } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + NBTTagCompound NBT = compound.getSingle(e); + if (NBT == null) NBT = new NBTTagCompound(); //If the NBT isn't set, create an empty one + String tag = string.getSingle(e); + Object newValue = delta[0]; + if (mode == ChangeMode.SET) { + if (newValue instanceof Byte) { + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + NBT.setInt(tag, (int) newValue);; + } else if (newValue instanceof Long) { + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + NBT.setDouble(tag, (double) newValue); + } else if (newValue instanceof String) { + NBT.setString(tag, (String) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.ADD) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) + (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) + (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) + (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) + (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) + (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) + (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.REMOVE) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) - (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) - (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) - (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) - (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) - (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) - (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { + return CollectionUtils.array(Object.class); + } + return null; + } } \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_7_R3.java b/src/me/TheBukor/expressions/ExprTagOfv1_7_R3.java index 395b74d..2486ec2 100644 --- a/src/me/TheBukor/expressions/ExprTagOfv1_7_R3.java +++ b/src/me/TheBukor/expressions/ExprTagOfv1_7_R3.java @@ -2,14 +2,16 @@ package me.TheBukor.expressions; import javax.annotation.Nullable; +import org.bukkit.Bukkit; import org.bukkit.event.Event; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; import net.minecraft.server.v1_7_R3.NBTTagCompound; -import net.minecraft.server.v1_7_R3.NBTTagList; public class ExprTagOfv1_7_R3 extends SimpleExpression { private Expression string; @@ -39,7 +41,7 @@ public class ExprTagOfv1_7_R3 extends SimpleExpression { @Nullable protected Object[] get(Event e) { NBTTagCompound NBT = compound.getSingle(e); - if (NBT.isEmpty() || NBT == null) return null; //The NBT can be empty/inexistant for items + if (NBT == null || NBT.isEmpty()) return null; //The NBT can be empty/inexistant for items String tag = string.getSingle(e); if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return . Byte id = NBT.get(tag).getTypeId(); @@ -68,7 +70,8 @@ public class ExprTagOfv1_7_R3 extends SimpleExpression { returned = new String[] { NBT.getString(tag) }; break; case 9: //List, will need to make a new type if getCompound() doesn't work here - returned = new NBTTagList[] { NBT.getList(tag, 5) }; //Is the int argument the type ID? + Bukkit.broadcastMessage("LIST!"); + returned = new Object[] { NBT.getList(tag, 0).toString() }; //Is the int argument the type ID? break; case 10: returned = new NBTTagCompound[] { NBT.getCompound(tag) }; @@ -80,4 +83,85 @@ public class ExprTagOfv1_7_R3 extends SimpleExpression { } return returned; } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + NBTTagCompound NBT = compound.getSingle(e); + if (NBT == null) NBT = new NBTTagCompound(); //If the NBT isn't set, create an empty one + String tag = string.getSingle(e); + Object newValue = delta[0]; + if (mode == ChangeMode.SET) { + if (newValue instanceof Byte) { + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + NBT.setInt(tag, (int) newValue);; + } else if (newValue instanceof Long) { + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + NBT.setDouble(tag, (double) newValue); + } else if (newValue instanceof String) { + NBT.setString(tag, (String) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.ADD) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) + (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) + (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) + (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) + (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) + (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) + (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.REMOVE) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) - (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) - (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) - (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) - (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) - (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) - (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { + return CollectionUtils.array(Object.class); + } + return null; + } } \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_7_R4.java b/src/me/TheBukor/expressions/ExprTagOfv1_7_R4.java index a75d818..ec74167 100644 --- a/src/me/TheBukor/expressions/ExprTagOfv1_7_R4.java +++ b/src/me/TheBukor/expressions/ExprTagOfv1_7_R4.java @@ -2,14 +2,16 @@ package me.TheBukor.expressions; import javax.annotation.Nullable; +import org.bukkit.Bukkit; import org.bukkit.event.Event; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; import net.minecraft.server.v1_7_R4.NBTTagCompound; -import net.minecraft.server.v1_7_R4.NBTTagList; public class ExprTagOfv1_7_R4 extends SimpleExpression { private Expression string; @@ -39,7 +41,7 @@ public class ExprTagOfv1_7_R4 extends SimpleExpression { @Nullable protected Object[] get(Event e) { NBTTagCompound NBT = compound.getSingle(e); - if (NBT.isEmpty() || NBT == null) return null; //The NBT can be empty/inexistant for items + if (NBT == null || NBT.isEmpty()) return null; //The NBT can be empty/inexistant for items String tag = string.getSingle(e); if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return . Byte id = NBT.get(tag).getTypeId(); @@ -68,7 +70,8 @@ public class ExprTagOfv1_7_R4 extends SimpleExpression { returned = new String[] { NBT.getString(tag) }; break; case 9: //List, will need to make a new type if getCompound() doesn't work here - returned = new NBTTagList[] { NBT.getList(tag, 5) }; //Is the int argument the type ID? + Bukkit.broadcastMessage("LIST!"); + returned = new Object[] { NBT.getList(tag, 0).toString() }; //Is the int argument the type ID? break; case 10: returned = new NBTTagCompound[] { NBT.getCompound(tag) }; @@ -80,4 +83,85 @@ public class ExprTagOfv1_7_R4 extends SimpleExpression { } return returned; } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + NBTTagCompound NBT = compound.getSingle(e); + if (NBT == null) NBT = new NBTTagCompound(); //If the NBT isn't set, create an empty one + String tag = string.getSingle(e); + Object newValue = delta[0]; + if (mode == ChangeMode.SET) { + if (newValue instanceof Byte) { + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + NBT.setInt(tag, (int) newValue);; + } else if (newValue instanceof Long) { + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + NBT.setDouble(tag, (double) newValue); + } else if (newValue instanceof String) { + NBT.setString(tag, (String) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.ADD) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) + (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) + (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) + (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) + (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) + (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) + (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.REMOVE) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) - (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) - (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) - (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) - (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) - (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) - (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { + return CollectionUtils.array(Object.class); + } + return null; + } } \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java b/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java index 283b9fd..b4c5186 100644 --- a/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java +++ b/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java @@ -2,14 +2,16 @@ package me.TheBukor.expressions; import javax.annotation.Nullable; +import org.bukkit.Bukkit; import org.bukkit.event.Event; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; import net.minecraft.server.v1_8_R1.NBTTagCompound; -import net.minecraft.server.v1_8_R1.NBTTagList; public class ExprTagOfv1_8_R1 extends SimpleExpression { private Expression string; @@ -39,7 +41,7 @@ public class ExprTagOfv1_8_R1 extends SimpleExpression { @Nullable protected Object[] get(Event e) { NBTTagCompound NBT = compound.getSingle(e); - if (NBT.isEmpty() || NBT == null) return null; //The NBT can be empty/inexistant for items + if (NBT == null || NBT.isEmpty()) return null; //The NBT can be empty/inexistant for items String tag = string.getSingle(e); if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return . Byte id = NBT.get(tag).getTypeId(); @@ -68,7 +70,8 @@ public class ExprTagOfv1_8_R1 extends SimpleExpression { returned = new String[] { NBT.getString(tag) }; break; case 9: //List, will need to make a new type if getCompound() doesn't work here - returned = new NBTTagList[] { NBT.getList(tag, 5) }; //Is the int argument the type ID? + Bukkit.broadcastMessage("LIST!"); + returned = new Object[] { NBT.getList(tag, 0).toString() }; //Is the int argument the type ID? break; case 10: returned = new NBTTagCompound[] { NBT.getCompound(tag) }; @@ -80,4 +83,85 @@ public class ExprTagOfv1_8_R1 extends SimpleExpression { } return returned; } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + NBTTagCompound NBT = compound.getSingle(e); + if (NBT == null) NBT = new NBTTagCompound(); //If the NBT isn't set, create an empty one + String tag = string.getSingle(e); + Object newValue = delta[0]; + if (mode == ChangeMode.SET) { + if (newValue instanceof Byte) { + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + NBT.setInt(tag, (int) newValue);; + } else if (newValue instanceof Long) { + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + NBT.setDouble(tag, (double) newValue); + } else if (newValue instanceof String) { + NBT.setString(tag, (String) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.ADD) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) + (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) + (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) + (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) + (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) + (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) + (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.REMOVE) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) - (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) - (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) - (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) - (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) - (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) - (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { + return CollectionUtils.array(Object.class); + } + return null; + } } \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java b/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java index fb41e5e..84abf4f 100644 --- a/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java +++ b/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java @@ -2,14 +2,16 @@ package me.TheBukor.expressions; import javax.annotation.Nullable; +import org.bukkit.Bukkit; import org.bukkit.event.Event; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; import net.minecraft.server.v1_8_R2.NBTTagCompound; -import net.minecraft.server.v1_8_R2.NBTTagList; public class ExprTagOfv1_8_R2 extends SimpleExpression { private Expression string; @@ -39,7 +41,7 @@ public class ExprTagOfv1_8_R2 extends SimpleExpression { @Nullable protected Object[] get(Event e) { NBTTagCompound NBT = compound.getSingle(e); - if (NBT.isEmpty() || NBT == null) return null; //The NBT can be empty/inexistant for items + if (NBT == null || NBT.isEmpty()) return null; //The NBT can be empty/inexistant for items String tag = string.getSingle(e); if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return . Byte id = NBT.get(tag).getTypeId(); @@ -68,7 +70,8 @@ public class ExprTagOfv1_8_R2 extends SimpleExpression { returned = new String[] { NBT.getString(tag) }; break; case 9: //List, will need to make a new type if getCompound() doesn't work here - returned = new NBTTagList[] { NBT.getList(tag, 5) }; //Is the int argument the type ID? + Bukkit.broadcastMessage("LIST!"); + returned = new Object[] { NBT.getList(tag, 0).toString() }; //Is the int argument the type ID? break; case 10: returned = new NBTTagCompound[] { NBT.getCompound(tag) }; @@ -80,4 +83,85 @@ public class ExprTagOfv1_8_R2 extends SimpleExpression { } return returned; } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + NBTTagCompound NBT = compound.getSingle(e); + if (NBT == null) NBT = new NBTTagCompound(); //If the NBT isn't set, create an empty one + String tag = string.getSingle(e); + Object newValue = delta[0]; + if (mode == ChangeMode.SET) { + if (newValue instanceof Byte) { + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + NBT.setInt(tag, (int) newValue);; + } else if (newValue instanceof Long) { + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + NBT.setDouble(tag, (double) newValue); + } else if (newValue instanceof String) { + NBT.setString(tag, (String) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.ADD) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) + (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) + (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) + (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) + (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) + (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) + (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.REMOVE) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) - (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) - (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) - (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) - (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) - (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) - (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { + return CollectionUtils.array(Object.class); + } + return null; + } } \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java b/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java index 0b9f265..1813d79 100644 --- a/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java +++ b/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java @@ -5,10 +5,12 @@ import javax.annotation.Nullable; import org.bukkit.Bukkit; import org.bukkit.event.Event; +import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; import net.minecraft.server.v1_8_R3.NBTTagCompound; public class ExprTagOfv1_8_R3 extends SimpleExpression { @@ -81,4 +83,85 @@ public class ExprTagOfv1_8_R3 extends SimpleExpression { } return returned; } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + NBTTagCompound NBT = compound.getSingle(e); + if (NBT == null) NBT = new NBTTagCompound(); //If the NBT isn't set, create an empty one + String tag = string.getSingle(e); + Object newValue = delta[0]; + if (mode == ChangeMode.SET) { + if (newValue instanceof Byte) { + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + NBT.setInt(tag, (int) newValue);; + } else if (newValue instanceof Long) { + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + NBT.setDouble(tag, (double) newValue); + } else if (newValue instanceof String) { + NBT.setString(tag, (String) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.ADD) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) + (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) + (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) + (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) + (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) + (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) + (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } else if (mode == ChangeMode.REMOVE) { + if (newValue instanceof Byte) { + newValue = NBT.getByte(tag) - (byte) newValue; + NBT.setByte(tag, (byte) newValue); + } else if (newValue instanceof Short) { + newValue = NBT.getShort(tag) - (short) newValue; + NBT.setShort(tag, (short) newValue); + } else if (newValue instanceof Integer) { + newValue = NBT.getInt(tag) - (int) newValue; + NBT.setInt(tag, (int) newValue); + } else if (newValue instanceof Long) { + newValue = NBT.getLong(tag) - (long) newValue; + NBT.setLong(tag, (long) newValue); + } else if (newValue instanceof Float) { + newValue = NBT.getFloat(tag) - (float) newValue; + NBT.setFloat(tag, (float) newValue); + } else if (newValue instanceof Double) { + newValue = NBT.getDouble(tag) - (double) newValue; + NBT.setDouble(tag, (double) newValue); + } else { + return; //Non-supported type or maybe an error occured? + } + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { + return CollectionUtils.array(Object.class); + } + return null; + } } \ No newline at end of file