New WorldEdit effects, "Tag of compound" expression now settable.

Also probably broke some stuff.
This commit is contained in:
Richard 2015-12-12 18:17:45 -02:00
parent 700cfe2c38
commit 925e92673e
13 changed files with 923 additions and 142 deletions

View File

@ -17,6 +17,9 @@ import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.registrations.Classes; import ch.njol.skript.registrations.Classes;
import me.TheBukor.conditions.CondSelectionContains; import me.TheBukor.conditions.CondSelectionContains;
import me.TheBukor.effects.EffDrawLineWE; 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.effects.EffUndoRedoSession;
import me.TheBukor.expressions.ExprAreaOfSchematic; import me.TheBukor.expressions.ExprAreaOfSchematic;
import me.TheBukor.expressions.ExprAreaOfSelection; import me.TheBukor.expressions.ExprAreaOfSelection;
@ -67,6 +70,7 @@ public class SkStuff extends JavaPlugin {
private int exprAmount = 0; private int exprAmount = 0;
private int typeAmount = 0; private int typeAmount = 0;
private int effAmount = 0; private int effAmount = 0;
public void onEnable() { public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("Skript") != null) { if (Bukkit.getPluginManager().getPlugin("Skript") != null) {
Skript.registerAddon(this); 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(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%"); 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! //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%"); //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>(net.minecraft.server.v1_7_R1.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_7_R1.NBTTagCompound>() { Classes.registerClass(new ClassInfo<net.minecraft.server.v1_7_R1.NBTTagCompound>(net.minecraft.server.v1_7_R1.NBTTagCompound.class, "compound").name("NBT Tag Compound").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser<net.minecraft.server.v1_7_R1.NBTTagCompound>() {
@Override @Override
public String getVariableNamePattern() { public String getVariableNamePattern() {
return ".+"; return "{.+:.+}";
} }
@Override @Override
@Nullable @Nullable
public net.minecraft.server.v1_7_R1.NBTTagCompound parse(String s, ParseContext context) { 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(); if (s.startsWith("{")) {
net.minecraft.server.v1_7_R1.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R1.NBTTagCompound) net.minecraft.server.v1_7_R1.MojangsonParser.a(s); net.minecraft.server.v1_7_R1.NBTTagCompound NBT = new net.minecraft.server.v1_7_R1.NBTTagCompound();
NBT.set("", NBT1); net.minecraft.server.v1_7_R1.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R1.NBTTagCompound) net.minecraft.server.v1_7_R1.MojangsonParser.a(s);
if (NBT.isEmpty() || NBT == null) { NBT.set("", NBT1);
return null; if (NBT.isEmpty() || NBT == null) {
return null;
}
return NBT;
} }
return NBT; return null;
} }
@Override @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(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%"); 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! //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%"); //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>(net.minecraft.server.v1_7_R2.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_7_R2.NBTTagCompound>() { Classes.registerClass(new ClassInfo<net.minecraft.server.v1_7_R2.NBTTagCompound>(net.minecraft.server.v1_7_R2.NBTTagCompound.class, "compound").name("NBT Tag Compound").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser<net.minecraft.server.v1_7_R2.NBTTagCompound>() {
@Override @Override
public String getVariableNamePattern() { public String getVariableNamePattern() {
return ".+"; return "nbt:{.+:.+}";
} }
@Override @Override
@Nullable @Nullable
public net.minecraft.server.v1_7_R2.NBTTagCompound parse(String s, ParseContext context) { 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(); if (s.startsWith("{")) {
net.minecraft.server.v1_7_R2.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R2.NBTTagCompound) net.minecraft.server.v1_7_R2.MojangsonParser.parse(s); net.minecraft.server.v1_7_R2.NBTTagCompound NBT = new net.minecraft.server.v1_7_R2.NBTTagCompound();
NBT.set("", NBT1); net.minecraft.server.v1_7_R2.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R2.NBTTagCompound) net.minecraft.server.v1_7_R2.MojangsonParser.parse(s);
if (NBT.isEmpty() || NBT == null) { NBT.set("", NBT1);
return null; if (NBT.isEmpty() || NBT == null) {
return null;
}
return NBT;
} }
return NBT; return null;
} }
@Override @Override
@ -143,7 +153,7 @@ public class SkStuff extends JavaPlugin {
@Override @Override
public String toVariableNameString(net.minecraft.server.v1_7_R2.NBTTagCompound compound) { 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(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%"); 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! //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%"); //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>(net.minecraft.server.v1_7_R3.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_7_R3.NBTTagCompound>() { Classes.registerClass(new ClassInfo<net.minecraft.server.v1_7_R3.NBTTagCompound>(net.minecraft.server.v1_7_R3.NBTTagCompound.class, "compound").name("NBT Tag Compound").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser<net.minecraft.server.v1_7_R3.NBTTagCompound>() {
@Override @Override
public String getVariableNamePattern() { public String getVariableNamePattern() {
return ".+"; return "nbt:{.+:.+}";
} }
@Override @Override
@Nullable @Nullable
public net.minecraft.server.v1_7_R3.NBTTagCompound parse(String s, ParseContext context) { 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(); if (s.startsWith("{")) {
net.minecraft.server.v1_7_R3.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R3.NBTTagCompound) net.minecraft.server.v1_7_R3.MojangsonParser.parse(s); net.minecraft.server.v1_7_R3.NBTTagCompound NBT = new net.minecraft.server.v1_7_R3.NBTTagCompound();
NBT.set("", NBT1); net.minecraft.server.v1_7_R3.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R3.NBTTagCompound) net.minecraft.server.v1_7_R3.MojangsonParser.parse(s);
if (NBT.isEmpty() || NBT == null) { NBT.set("", NBT1);
return null; if (NBT.isEmpty() || NBT == null) {
return null;
}
return NBT;
} }
return NBT; return null;
} }
@Override @Override
@ -181,7 +194,7 @@ public class SkStuff extends JavaPlugin {
@Override @Override
public String toVariableNameString(net.minecraft.server.v1_7_R3.NBTTagCompound compound) { 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(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%"); 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! //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%"); //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>(net.minecraft.server.v1_7_R4.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_7_R4.NBTTagCompound>() { Classes.registerClass(new ClassInfo<net.minecraft.server.v1_7_R4.NBTTagCompound>(net.minecraft.server.v1_7_R4.NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_7_R4.NBTTagCompound>() {
@Override @Override
public String getVariableNamePattern() { public String getVariableNamePattern() {
return ".+"; return "nbt:{.+:.+}";
} }
@Override @Override
@Nullable @Nullable
public net.minecraft.server.v1_7_R4.NBTTagCompound parse(String s, ParseContext context) { 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(); if (s.startsWith("{")) {
net.minecraft.server.v1_7_R4.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R4.NBTTagCompound) net.minecraft.server.v1_7_R4.MojangsonParser.parse(s); net.minecraft.server.v1_7_R4.NBTTagCompound NBT = new net.minecraft.server.v1_7_R4.NBTTagCompound();
NBT.set("", NBT1); net.minecraft.server.v1_7_R4.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R4.NBTTagCompound) net.minecraft.server.v1_7_R4.MojangsonParser.parse(s);
if (NBT.isEmpty() || NBT == null) { NBT.set("", NBT1);
return null; if (NBT.isEmpty() || NBT == null) {
return null;
}
return NBT;
} }
return NBT; return null;
} }
@Override @Override
@ -220,7 +236,7 @@ public class SkStuff extends JavaPlugin {
@Override @Override
public String toVariableNameString(net.minecraft.server.v1_7_R4.NBTTagCompound compound) { 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(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%"); 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! //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%"); Skript.registerExpression(ExprFileNBTv1_8_R1.class, NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%");
Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<NBTTagCompound>() { Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").name("NBT Tag Compound").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser<NBTTagCompound>() {
@Override @Override
public String getVariableNamePattern() { public String getVariableNamePattern() {
return ".+"; return "nbt:{.+:.+}";
} }
@Override @Override
@Nullable @Nullable
public NBTTagCompound parse(String s, ParseContext context) { public NBTTagCompound parse(String s, ParseContext context) {
NBTTagCompound NBT = new NBTTagCompound(); if (s.startsWith("{")) {
NBTTagCompound NBT1 = MojangsonParser.parse(s); NBTTagCompound NBT = new NBTTagCompound();
NBT.a(NBT1); NBTTagCompound NBT1 = null;
if (NBT.isEmpty() || NBT == null) { NBT1 = MojangsonParser.parse(s);
return null; NBT.a(NBT1);
if (NBT.isEmpty() || NBT == null) {
return null;
}
return NBT;
} }
return NBT; return null;
} }
@Override @Override
@ -259,7 +279,7 @@ public class SkStuff extends JavaPlugin {
@Override @Override
public String toVariableNameString(NBTTagCompound compound) { 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(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%"); 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! //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%"); 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>(net.minecraft.server.v1_8_R2.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_8_R2.NBTTagCompound>() { Classes.registerClass(new ClassInfo<net.minecraft.server.v1_8_R2.NBTTagCompound>(net.minecraft.server.v1_8_R2.NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_8_R2.NBTTagCompound>() {
@Override @Override
public String getVariableNamePattern() { public String getVariableNamePattern() {
return ".+"; return "nbt:{.+:.+}";
} }
@Override @Override
@Nullable @Nullable
public net.minecraft.server.v1_8_R2.NBTTagCompound parse(String s, ParseContext context) { 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(); if (s.startsWith("{")) {
try { net.minecraft.server.v1_8_R2.NBTTagCompound NBT = new net.minecraft.server.v1_8_R2.NBTTagCompound();
net.minecraft.server.v1_8_R2.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R2.MojangsonParser.parse(s); try {
NBT.a(NBT1); net.minecraft.server.v1_8_R2.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R2.MojangsonParser.parse(s);
} catch (MojangsonParseException ex) { NBT.a(NBT1);
Skript.warning("Error when parsing NBT - " + ex.getMessage()); } 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 null;
}
return NBT;
} }
@Override @Override
@ -302,7 +325,7 @@ public class SkStuff extends JavaPlugin {
@Override @Override
public String toVariableNameString(net.minecraft.server.v1_8_R2.NBTTagCompound compound) { 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(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%"); 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! //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%"); 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>(net.minecraft.server.v1_8_R3.NBTTagCompound.class, "compound").name("NBT Compound").parser(new Parser<net.minecraft.server.v1_8_R3.NBTTagCompound>() { Classes.registerClass(new ClassInfo<net.minecraft.server.v1_8_R3.NBTTagCompound>(net.minecraft.server.v1_8_R3.NBTTagCompound.class, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").parser(new Parser<net.minecraft.server.v1_8_R3.NBTTagCompound>() {
@Override @Override
public String getVariableNamePattern() { public String getVariableNamePattern() {
return ".+"; return "nbt:{.+:.+}";
} }
@Override @Override
@Nullable @Nullable
public net.minecraft.server.v1_8_R3.NBTTagCompound parse(String s, ParseContext context) { 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(); if (s.startsWith("{")) {
try { net.minecraft.server.v1_8_R3.NBTTagCompound NBT = new net.minecraft.server.v1_8_R3.NBTTagCompound();
net.minecraft.server.v1_8_R3.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R3.MojangsonParser.parse(s); try {
NBT.a(NBT1); net.minecraft.server.v1_8_R3.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R3.MojangsonParser.parse(s);
} catch (net.minecraft.server.v1_8_R3.MojangsonParseException ex) { NBT.a(NBT1);
return null; } 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 null;
}
return NBT;
} }
@Override @Override
@ -345,7 +371,7 @@ public class SkStuff extends JavaPlugin {
@Override @Override
public String toVariableNameString(net.minecraft.server.v1_8_R3.NBTTagCompound compound) { 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; 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%"); 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 // 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(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, "undo [last] (change|edit)[s] (of|from) [edit[ ]session] %editsession%", "redo [last] (change|edit)[s] (of|from) [edit[ ]session] %editsession%"); 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(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, "[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 // 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(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"); 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(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(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%"); Skript.registerExpression(ExprAreaOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "area of schem[atic] [from] %string%");
Classes.registerClass(new ClassInfo<EditSession>(EditSession.class, "editsession").name("Edit Session").parser(new Parser<EditSession>() { Classes.registerClass(new ClassInfo<EditSession>(EditSession.class, "editsession").name("Edit Session").user("edit ?sessions?"));
@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;
}
}));
} }
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!")); 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 { } else {

View File

@ -8,9 +8,10 @@ import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; 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.bukkit.BukkitUtil;
import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.RandomPattern;
import com.sk89q.worldedit.patterns.Pattern; import com.sk89q.worldedit.patterns.Pattern;
import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Effect;
@ -23,25 +24,25 @@ public class EffDrawLineWE extends Effect {
private Expression<Location> location1; private Expression<Location> location1;
private Expression<Location> location2; private Expression<Location> location2;
private Expression<EditSession> editSession; private Expression<EditSession> editSession;
private Expression<ItemStack> block; private Expression<ItemStack> blockList;
private Expression<Double> thickness; private Expression<Double> thickness;
private boolean filled = true; private boolean filled = 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 result) {
location1 = (Expression<Location>) expr[0]; location1 = (Expression<Location>) expr[0];
location2 = (Expression<Location>) expr[1]; location2 = (Expression<Location>) expr[1];
editSession = (Expression<EditSession>) expr[2]; editSession = (Expression<EditSession>) expr[2];
block = (Expression<ItemStack>) expr[3]; blockList = (Expression<ItemStack>) expr[3];
thickness = (Expression<Double>) expr[4]; thickness = (Expression<Double>) expr[4];
if (matchedPattern == 1) filled = false; if (result.mark == 1) filled = false;
return true; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean arg1) { 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 @Override
@ -49,15 +50,23 @@ public class EffDrawLineWE extends Effect {
Location pos1 = location1.getSingle(e); Location pos1 = location1.getSingle(e);
Location pos2 = location2.getSingle(e); Location pos2 = location2.getSingle(e);
EditSession session = editSession.getSingle(e); EditSession session = editSession.getSingle(e);
ItemStack b = block.getSingle(e); ItemStack[] blocks = blockList.getAll(e);
Double thick = thickness.getSingle(e); Double thick = thickness.getSingle(e);
if (b.getType().isBlock()) { RandomPattern random = new RandomPattern();
try { for (ItemStack b : blocks) {
session.drawLine((Pattern) new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2), thick, filled); if (b.getType().isBlock()) {
session.flushQueue(); try {
} catch (MaxChangedBlocksException ex) { random.add(new BlockPattern(BukkitUtil.toBlock(BukkitUtil.getLocalWorld(pos1.getWorld()), b)), 50);
return; } catch (WorldEditException ex) {
ex.printStackTrace();
}
} }
} }
try {
session.drawLine((Pattern) random, BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2), thick, filled);
session.flushQueue();
} catch (MaxChangedBlocksException ex) {
return;
}
} }
} }

View File

@ -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> location;
private Expression<Integer> radius;
private Expression<EditSession> editSession;
private Expression<ItemStack> blockList;
private boolean filled = true;
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
location = (Expression<Location>) expr[0];
radius = (Expression<Integer>) expr[1];
editSession = (Expression<EditSession>) expr[2];
blockList = (Expression<ItemStack>) 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;
}
}
}

View File

@ -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> location;
private Expression<Double> radius1;
private Expression<Double> radius2;
private Expression<Double> radius3;
private Expression<EditSession> editSession;
private Expression<ItemStack> blockList;
private boolean filled = true;
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
location = (Expression<Location>) expr[0];
radius1 = (Expression<Double>) expr[1];
radius2 = (Expression<Double>) expr[2];
radius3 = (Expression<Double>) expr[3];
editSession = (Expression<EditSession>) expr[4];
blockList = (Expression<ItemStack>) 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;
}
}
}

View File

@ -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> player;
private Expression<EditSession> editSession;
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
player = (Expression<Player>) expr[0];
editSession = (Expression<EditSession>) 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);
}
}

View File

@ -17,9 +17,9 @@ public class EffUndoRedoSession extends Effect {
@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 result) {
editSession = (Expression<EditSession>) expr[0]; editSession = (Expression<EditSession>) expr[0];
if (matchedPattern == 1) redo = true; if (result.mark == 1) redo = true;
return true; return true;
} }

View File

@ -2,14 +2,16 @@ package me.TheBukor.expressions;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
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 net.minecraft.server.v1_7_R1.NBTTagCompound; import net.minecraft.server.v1_7_R1.NBTTagCompound;
import net.minecraft.server.v1_7_R1.NBTTagList;
public class ExprTagOfv1_7_R1 extends SimpleExpression<Object> { public class ExprTagOfv1_7_R1 extends SimpleExpression<Object> {
private Expression<String> string; private Expression<String> string;
@ -39,7 +41,7 @@ public class ExprTagOfv1_7_R1 extends SimpleExpression<Object> {
@Nullable @Nullable
protected Object[] get(Event e) { protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(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); String tag = string.getSingle(e);
if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>. if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>.
Byte id = NBT.get(tag).getTypeId(); Byte id = NBT.get(tag).getTypeId();
@ -68,7 +70,8 @@ public class ExprTagOfv1_7_R1 extends SimpleExpression<Object> {
returned = new String[] { NBT.getString(tag) }; returned = new String[] { NBT.getString(tag) };
break; break;
case 9: //List, will need to make a new type if getCompound() doesn't work here 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; break;
case 10: case 10:
returned = new NBTTagCompound[] { NBT.getCompound(tag) }; returned = new NBTTagCompound[] { NBT.getCompound(tag) };
@ -80,4 +83,85 @@ public class ExprTagOfv1_7_R1 extends SimpleExpression<Object> {
} }
return returned; 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;
}
} }

View File

@ -2,14 +2,16 @@ package me.TheBukor.expressions;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
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 net.minecraft.server.v1_7_R2.NBTTagCompound; import net.minecraft.server.v1_7_R2.NBTTagCompound;
import net.minecraft.server.v1_7_R2.NBTTagList;
public class ExprTagOfv1_7_R2 extends SimpleExpression<Object> { public class ExprTagOfv1_7_R2 extends SimpleExpression<Object> {
private Expression<String> string; private Expression<String> string;
@ -39,7 +41,7 @@ public class ExprTagOfv1_7_R2 extends SimpleExpression<Object> {
@Nullable @Nullable
protected Object[] get(Event e) { protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(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); String tag = string.getSingle(e);
if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>. if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>.
Byte id = NBT.get(tag).getTypeId(); Byte id = NBT.get(tag).getTypeId();
@ -68,7 +70,8 @@ public class ExprTagOfv1_7_R2 extends SimpleExpression<Object> {
returned = new String[] { NBT.getString(tag) }; returned = new String[] { NBT.getString(tag) };
break; break;
case 9: //List, will need to make a new type if getCompound() doesn't work here 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; break;
case 10: case 10:
returned = new NBTTagCompound[] { NBT.getCompound(tag) }; returned = new NBTTagCompound[] { NBT.getCompound(tag) };
@ -80,4 +83,85 @@ public class ExprTagOfv1_7_R2 extends SimpleExpression<Object> {
} }
return returned; 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;
}
} }

View File

@ -2,14 +2,16 @@ package me.TheBukor.expressions;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
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 net.minecraft.server.v1_7_R3.NBTTagCompound; import net.minecraft.server.v1_7_R3.NBTTagCompound;
import net.minecraft.server.v1_7_R3.NBTTagList;
public class ExprTagOfv1_7_R3 extends SimpleExpression<Object> { public class ExprTagOfv1_7_R3 extends SimpleExpression<Object> {
private Expression<String> string; private Expression<String> string;
@ -39,7 +41,7 @@ public class ExprTagOfv1_7_R3 extends SimpleExpression<Object> {
@Nullable @Nullable
protected Object[] get(Event e) { protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(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); String tag = string.getSingle(e);
if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>. if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>.
Byte id = NBT.get(tag).getTypeId(); Byte id = NBT.get(tag).getTypeId();
@ -68,7 +70,8 @@ public class ExprTagOfv1_7_R3 extends SimpleExpression<Object> {
returned = new String[] { NBT.getString(tag) }; returned = new String[] { NBT.getString(tag) };
break; break;
case 9: //List, will need to make a new type if getCompound() doesn't work here 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; break;
case 10: case 10:
returned = new NBTTagCompound[] { NBT.getCompound(tag) }; returned = new NBTTagCompound[] { NBT.getCompound(tag) };
@ -80,4 +83,85 @@ public class ExprTagOfv1_7_R3 extends SimpleExpression<Object> {
} }
return returned; 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;
}
} }

View File

@ -2,14 +2,16 @@ package me.TheBukor.expressions;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
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 net.minecraft.server.v1_7_R4.NBTTagCompound; import net.minecraft.server.v1_7_R4.NBTTagCompound;
import net.minecraft.server.v1_7_R4.NBTTagList;
public class ExprTagOfv1_7_R4 extends SimpleExpression<Object> { public class ExprTagOfv1_7_R4 extends SimpleExpression<Object> {
private Expression<String> string; private Expression<String> string;
@ -39,7 +41,7 @@ public class ExprTagOfv1_7_R4 extends SimpleExpression<Object> {
@Nullable @Nullable
protected Object[] get(Event e) { protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(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); String tag = string.getSingle(e);
if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>. if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>.
Byte id = NBT.get(tag).getTypeId(); Byte id = NBT.get(tag).getTypeId();
@ -68,7 +70,8 @@ public class ExprTagOfv1_7_R4 extends SimpleExpression<Object> {
returned = new String[] { NBT.getString(tag) }; returned = new String[] { NBT.getString(tag) };
break; break;
case 9: //List, will need to make a new type if getCompound() doesn't work here 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; break;
case 10: case 10:
returned = new NBTTagCompound[] { NBT.getCompound(tag) }; returned = new NBTTagCompound[] { NBT.getCompound(tag) };
@ -80,4 +83,85 @@ public class ExprTagOfv1_7_R4 extends SimpleExpression<Object> {
} }
return returned; 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;
}
} }

View File

@ -2,14 +2,16 @@ package me.TheBukor.expressions;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
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 net.minecraft.server.v1_8_R1.NBTTagCompound; import net.minecraft.server.v1_8_R1.NBTTagCompound;
import net.minecraft.server.v1_8_R1.NBTTagList;
public class ExprTagOfv1_8_R1 extends SimpleExpression<Object> { public class ExprTagOfv1_8_R1 extends SimpleExpression<Object> {
private Expression<String> string; private Expression<String> string;
@ -39,7 +41,7 @@ public class ExprTagOfv1_8_R1 extends SimpleExpression<Object> {
@Nullable @Nullable
protected Object[] get(Event e) { protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(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); String tag = string.getSingle(e);
if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>. if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>.
Byte id = NBT.get(tag).getTypeId(); Byte id = NBT.get(tag).getTypeId();
@ -68,7 +70,8 @@ public class ExprTagOfv1_8_R1 extends SimpleExpression<Object> {
returned = new String[] { NBT.getString(tag) }; returned = new String[] { NBT.getString(tag) };
break; break;
case 9: //List, will need to make a new type if getCompound() doesn't work here 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; break;
case 10: case 10:
returned = new NBTTagCompound[] { NBT.getCompound(tag) }; returned = new NBTTagCompound[] { NBT.getCompound(tag) };
@ -80,4 +83,85 @@ public class ExprTagOfv1_8_R1 extends SimpleExpression<Object> {
} }
return returned; 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;
}
} }

View File

@ -2,14 +2,16 @@ package me.TheBukor.expressions;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
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 net.minecraft.server.v1_8_R2.NBTTagCompound; import net.minecraft.server.v1_8_R2.NBTTagCompound;
import net.minecraft.server.v1_8_R2.NBTTagList;
public class ExprTagOfv1_8_R2 extends SimpleExpression<Object> { public class ExprTagOfv1_8_R2 extends SimpleExpression<Object> {
private Expression<String> string; private Expression<String> string;
@ -39,7 +41,7 @@ public class ExprTagOfv1_8_R2 extends SimpleExpression<Object> {
@Nullable @Nullable
protected Object[] get(Event e) { protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(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); String tag = string.getSingle(e);
if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>. if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return <none>.
Byte id = NBT.get(tag).getTypeId(); Byte id = NBT.get(tag).getTypeId();
@ -68,7 +70,8 @@ public class ExprTagOfv1_8_R2 extends SimpleExpression<Object> {
returned = new String[] { NBT.getString(tag) }; returned = new String[] { NBT.getString(tag) };
break; break;
case 9: //List, will need to make a new type if getCompound() doesn't work here 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; break;
case 10: case 10:
returned = new NBTTagCompound[] { NBT.getCompound(tag) }; returned = new NBTTagCompound[] { NBT.getCompound(tag) };
@ -80,4 +83,85 @@ public class ExprTagOfv1_8_R2 extends SimpleExpression<Object> {
} }
return returned; 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;
}
} }

View File

@ -5,10 +5,12 @@ import javax.annotation.Nullable;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
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 net.minecraft.server.v1_8_R3.NBTTagCompound; import net.minecraft.server.v1_8_R3.NBTTagCompound;
public class ExprTagOfv1_8_R3 extends SimpleExpression<Object> { public class ExprTagOfv1_8_R3 extends SimpleExpression<Object> {
@ -81,4 +83,85 @@ public class ExprTagOfv1_8_R3 extends SimpleExpression<Object> {
} }
return returned; 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;
}
} }