Moved to reflection (code looks 45% uglier), added new expression for...

entities: NoClip and Fireproof. 
Added support to NBT List tags for the TagOf expression.
This commit is contained in:
Richard 2016-01-17 22:10:38 -02:00
parent bf02ac09a4
commit a872fe6de9
41 changed files with 1121 additions and 3922 deletions

View File

@ -2,7 +2,6 @@
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/spigot.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/plugins/Skript.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/plugins/Skript.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.3.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.3.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.jar"/>
@ -11,5 +10,6 @@
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.9.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.9.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.5.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.5.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.2.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.2.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.7.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

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

View File

@ -1,5 +1,7 @@
package me.TheBukor.SkStuff; package me.TheBukor.SkStuff;
import java.lang.reflect.InvocationTargetException;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -35,49 +37,20 @@ import me.TheBukor.SkStuff.effects.EffSimulateSnow;
import me.TheBukor.SkStuff.effects.EffUndoRedoSession; import me.TheBukor.SkStuff.effects.EffUndoRedoSession;
import me.TheBukor.SkStuff.events.EvtWorldEditChange; import me.TheBukor.SkStuff.events.EvtWorldEditChange;
import me.TheBukor.SkStuff.events.WorldEditChangeHandler; import me.TheBukor.SkStuff.events.WorldEditChangeHandler;
import me.TheBukor.SkStuff.expressions.ExprAreaOfSchematic;
import me.TheBukor.SkStuff.expressions.ExprAreaOfSelection;
import me.TheBukor.SkStuff.expressions.ExprChangedBlocksSession; import me.TheBukor.SkStuff.expressions.ExprChangedBlocksSession;
import me.TheBukor.SkStuff.expressions.ExprEditSessionLimit; import me.TheBukor.SkStuff.expressions.ExprEditSessionLimit;
import me.TheBukor.SkStuff.expressions.ExprFileNBTv1_8_R1; import me.TheBukor.SkStuff.expressions.ExprFileNBT;
import me.TheBukor.SkStuff.expressions.ExprFileNBTv1_8_R2; import me.TheBukor.SkStuff.expressions.ExprFireProof;
import me.TheBukor.SkStuff.expressions.ExprFileNBTv1_8_R3; import me.TheBukor.SkStuff.expressions.ExprItemNBT;
import me.TheBukor.SkStuff.expressions.ExprHeightOfSchematic; import me.TheBukor.SkStuff.expressions.ExprNBTOf;
import me.TheBukor.SkStuff.expressions.ExprHeightOfSelection;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_7_R1;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_7_R2;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_7_R3;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_7_R4;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_8_R1;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_8_R2;
import me.TheBukor.SkStuff.expressions.ExprItemNBTv1_8_R3;
import me.TheBukor.SkStuff.expressions.ExprLengthOfSchematic;
import me.TheBukor.SkStuff.expressions.ExprLengthOfSelection;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_7_R1;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_7_R2;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_7_R3;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_7_R4;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_8_R1;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_8_R2;
import me.TheBukor.SkStuff.expressions.ExprNBTv1_8_R3;
import me.TheBukor.SkStuff.expressions.ExprNewEditSession; import me.TheBukor.SkStuff.expressions.ExprNewEditSession;
import me.TheBukor.SkStuff.expressions.ExprNoClip;
import me.TheBukor.SkStuff.expressions.ExprSchematicArea;
import me.TheBukor.SkStuff.expressions.ExprSelectionArea;
import me.TheBukor.SkStuff.expressions.ExprSelectionOfPlayer; import me.TheBukor.SkStuff.expressions.ExprSelectionOfPlayer;
import me.TheBukor.SkStuff.expressions.ExprSelectionPos1; import me.TheBukor.SkStuff.expressions.ExprSelectionPos;
import me.TheBukor.SkStuff.expressions.ExprSelectionPos2; import me.TheBukor.SkStuff.expressions.ExprTagOf;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_7_R1; import me.TheBukor.SkStuff.util.ReflectionUtils;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_7_R2;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_7_R3;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_7_R4;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_8_R1;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_8_R2;
import me.TheBukor.SkStuff.expressions.ExprTagOfv1_8_R3;
import me.TheBukor.SkStuff.expressions.ExprVolumeOfSchematic;
import me.TheBukor.SkStuff.expressions.ExprVolumeOfSelection;
import me.TheBukor.SkStuff.expressions.ExprWidthOfSchematic;
import me.TheBukor.SkStuff.expressions.ExprWidthOfSelection;
import net.minecraft.server.v1_8_R1.MojangsonParser;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
import net.minecraft.server.v1_8_R2.MojangsonParseException;
public class SkStuff extends JavaPlugin { public class SkStuff extends JavaPlugin {
private int condAmount = 0; private int condAmount = 0;
@ -86,315 +59,78 @@ public class SkStuff extends JavaPlugin {
private int effAmount = 0; private int effAmount = 0;
private boolean evtWE = false; private boolean evtWE = false;
private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
private Class<?> nbtParserClass = ReflectionUtils.getNMSClass("MojangsonParser");
private Class<?> nbtParseExClass = ReflectionUtils.getNMSClass("MojangsonParseException");
@SuppressWarnings("unchecked")
public void onEnable() { public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("Skript") != null) { if (Bukkit.getPluginManager().getPlugin("Skript") != null && Skript.isAcceptRegistrations()) {
Skript.registerAddon(this); Skript.registerAddon(this);
getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully enabled!"); getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully enabled!");
if (Bukkit.getVersion().contains("(MC: 1.7.2)")) { getLogger().info("Trying to register version specific stuff...");
getLogger().info("Successfully found 1.7.2! Registering version specific expressions..."); typeAmount += 1;
exprAmount += 3; exprAmount += 6;
typeAmount += 1; Skript.registerExpression(ExprNBTOf.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]");
Skript.registerExpression(ExprNBTv1_7_R1.class, net.minecraft.server.v1_7_R1.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]"); Skript.registerExpression(ExprItemNBT.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%");
Skript.registerExpression(ExprItemNBTv1_7_R1.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOf.class, Object.class, ExpressionType.PROPERTY, "[nbt[ ]]tag %string% of [[nbt] compound] %compound%");
Skript.registerExpression(ExprTagOfv1_7_R1.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%"); Skript.registerExpression(ExprFileNBT.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%");
//WARNING! HIGHLY EXPERIMENTAL, IT CAN CORRUPT WORLDS AT CURRENT VERSION, USE AT YOUR OWN RISK! Skript.registerExpression(ExprNoClip.class, Boolean.class, ExpressionType.PROPERTY, "no[( |-)]clip (state|mode) of %entity%", "%entity%'s no[( |-)]clip (state|mode)");
//Skript.registerExpression(ExprFileNBTv1_7_R1.class, net.minecraft.server.v1_7_R1.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] from [file] %string%"); Skript.registerExpression(ExprFireProof.class, Boolean.class, ExpressionType.PROPERTY, "fire[ ]proof (state|mode) of %entity%", "%entity%'s fire[ ]proof (state|mode)");
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 Classes.registerClass(new ClassInfo<Object>((Class<Object>) nbtClass, "compound").user("((nbt)?( ?tag)?) ?compounds?").name("NBT Compound").parser(new Parser<Object>() {
public String getVariableNamePattern() {
return "{.+:.+}";
}
@Override @Override
@Nullable public String getVariableNamePattern() {
public net.minecraft.server.v1_7_R1.NBTTagCompound parse(String s, ParseContext context) { return "nbt:{.+:.+}";
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); @Override
NBT.set("", NBT1); @Nullable
if (NBT.isEmpty() || NBT == null) { public Object parse(String s, ParseContext context) {
return null; if (s.startsWith("{")) {
} Object NBT = null;
return NBT; try {
NBT = nbtClass.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
ex.printStackTrace();
} }
return null; try {
} Object NBT1 = null;
NBT1 = nbtParserClass.getMethod("parse", String.class).invoke(NBT1, s);
@Override nbtClass.getMethod("a", nbtClass).invoke(NBT, NBT1);
public String toString(net.minecraft.server.v1_7_R1.NBTTagCompound compound, int arg1) { } catch (Exception ex) {
return compound.toString(); if (ex instanceof InvocationTargetException) {
} if (ex.getCause().getClass().equals(nbtParseExClass) ) {
return null;
@Override }
public String toVariableNameString(net.minecraft.server.v1_7_R1.NBTTagCompound compound) { ex.printStackTrace();
return compound.toString();
}
}));
}
if (Bukkit.getVersion().contains("(MC: 1.7.5)")) {
getLogger().info("Successfully found 1.7.5! Registering version specific expressions...");
exprAmount += 3;
typeAmount += 1;
Skript.registerExpression(ExprNBTv1_7_R2.class, net.minecraft.server.v1_7_R2.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]");
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]] 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").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser<net.minecraft.server.v1_7_R2.NBTTagCompound>() {
@Override
public String getVariableNamePattern() {
return "nbt:{.+:.+}";
}
@Override
@Nullable
public net.minecraft.server.v1_7_R2.NBTTagCompound parse(String s, ParseContext context) {
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; ex.printStackTrace();
} }
return null; if (NBT.toString().equals("{}") || NBT == null) {
} return null;
@Override
public String toString(net.minecraft.server.v1_7_R2.NBTTagCompound compound, int arg1) {
return compound.toString();
}
@Override
public String toVariableNameString(net.minecraft.server.v1_7_R2.NBTTagCompound compound) {
return "nbt:" + compound.toString();
}
}));
}
if (Bukkit.getVersion().contains("(MC: 1.7.9)")) {
getLogger().info("Successfully found 1.7.9! Registering version specific expressions...");
exprAmount += 3;
typeAmount += 1;
Skript.registerExpression(ExprNBTv1_7_R3.class, net.minecraft.server.v1_7_R3.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]");
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]] 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").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser<net.minecraft.server.v1_7_R3.NBTTagCompound>() {
@Override
public String getVariableNamePattern() {
return "nbt:{.+:.+}";
}
@Override
@Nullable
public net.minecraft.server.v1_7_R3.NBTTagCompound parse(String s, ParseContext context) {
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 null; return NBT;
} }
return null;
}
@Override @Override
public String toString(net.minecraft.server.v1_7_R3.NBTTagCompound compound, int arg1) { public String toString(Object compound, int arg1) {
return compound.toString(); return compound.toString();
} }
@Override @Override
public String toVariableNameString(net.minecraft.server.v1_7_R3.NBTTagCompound compound) { public String toVariableNameString(Object compound) {
return "nbt:" + compound.toString(); return "nbt:" + compound.toString();
} }
})); }));
}
if (Bukkit.getVersion().contains("(MC: 1.7.10)")) {
getLogger().info("Successfully found 1.7.10! Registering version specific expressions...");
exprAmount += 3;
typeAmount += 1;
Skript.registerExpression(ExprNBTv1_7_R4.class, net.minecraft.server.v1_7_R4.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]");
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]] from [file] %string%");
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
public String getVariableNamePattern() {
return "nbt:{.+:.+}";
}
@Override
@Nullable
public net.minecraft.server.v1_7_R4.NBTTagCompound parse(String s, ParseContext context) {
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 null;
}
@Override
public String toString(net.minecraft.server.v1_7_R4.NBTTagCompound compound, int arg1) {
return compound.toString();
}
@Override
public String toVariableNameString(net.minecraft.server.v1_7_R4.NBTTagCompound compound) {
return "nbt:" + compound.toString();
}
}));
}
if (Bukkit.getVersion().contains("(MC: 1.8)")) {
getLogger().info("Successfully found 1.8! Registering version specific expressions...");
exprAmount += 4;
typeAmount += 1;
Skript.registerExpression(ExprNBTv1_8_R1.class, NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]");
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]] from [file] %string%");
Classes.registerClass(new ClassInfo<NBTTagCompound>(NBTTagCompound.class, "compound").name("NBT Tag Compound").user("((nbt)?( ?tag)?) ?compounds?").parser(new Parser<NBTTagCompound>() {
@Override
public String getVariableNamePattern() {
return "nbt:{.+:.+}";
}
@Override
@Nullable
public NBTTagCompound parse(String s, ParseContext context) {
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 null;
}
@Override
public String toString(NBTTagCompound compound, int arg1) {
return compound.toString();
}
@Override
public String toVariableNameString(NBTTagCompound compound) {
return "nbt:" + compound.toString();
}
}));
}
if (Bukkit.getVersion().contains("(MC: 1.8.3)")) {
getLogger().info("Successfully found 1.8.3! Registering version specific expressions...");
exprAmount += 4;
typeAmount += 1;
Skript.registerExpression(ExprNBTv1_8_R2.class, net.minecraft.server.v1_8_R2.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]");
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]] from [file] %string%");
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
public String getVariableNamePattern() {
return "nbt:{.+:.+}";
}
@Override
@Nullable
public net.minecraft.server.v1_8_R2.NBTTagCompound parse(String s, ParseContext context) {
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;
}
return null;
}
@Override
public String toString(net.minecraft.server.v1_8_R2.NBTTagCompound compound, int arg1) {
return compound.toString();
}
@Override
public String toVariableNameString(net.minecraft.server.v1_8_R2.NBTTagCompound compound) {
return "nbt:" + compound.toString();
}
}));
}
if (Bukkit.getVersion().contains("(MC: 1.8.4)") || Bukkit.getVersion().contains("(MC: 1.8.5)") || Bukkit.getVersion().contains("(MC: 1.8.6)") || Bukkit.getVersion().contains("(MC: 1.8.7)") || Bukkit.getVersion().contains("(MC: 1.8.8)")) {
getLogger().info("Successfully found 1.8.4 - 1.8.8! Registering version specific expressions...");
exprAmount += 4;
typeAmount += 1;
Skript.registerExpression(ExprNBTv1_8_R3.class, net.minecraft.server.v1_8_R3.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]");
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]] from [file] %string%");
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
public String getVariableNamePattern() {
return "nbt:{.+:.+}";
}
@Override
@Nullable
public net.minecraft.server.v1_8_R3.NBTTagCompound parse(String s, ParseContext context) {
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;
}
return null;
}
@Override
public String toString(net.minecraft.server.v1_8_R3.NBTTagCompound compound, int arg1) {
return compound.toString();
}
@Override
public String toVariableNameString(net.minecraft.server.v1_8_R3.NBTTagCompound compound) {
return "nbt:" + compound.toString();
}
}));
}
if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) { if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) {
getLogger().info("WorldEdit found! Registering WorldEdit stuff..."); getLogger().info("WorldEdit found! Registering WorldEdit stuff...");
condAmount += 1; condAmount += 1;
effAmount += 12; effAmount += 12;
exprAmount += 16; exprAmount += 7;
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%");
Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks% [with] thick[ness] %double%"); Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks% [with] thick[ness] %double%");
@ -411,20 +147,11 @@ public class SkStuff extends JavaPlugin {
Skript.registerEffect(EffReplaceBlocksWE.class, "replace [all] %itemstacks% (from|between) %location% (to|and) %location% with %itemstacks% (using|with) [edit[ ]session] %editsession%"); Skript.registerEffect(EffReplaceBlocksWE.class, "replace [all] %itemstacks% (from|between) %location% (to|and) %location% with %itemstacks% (using|with) [edit[ ]session] %editsession%");
Skript.registerExpression(ExprEditSessionLimit.class, Integer.class, ExpressionType.PROPERTY, "[block] limit [change] of [edit[ ]session] %editsession%"); Skript.registerExpression(ExprEditSessionLimit.class, Integer.class, ExpressionType.PROPERTY, "[block] limit [change] of [edit[ ]session] %editsession%");
Skript.registerExpression(ExprChangedBlocksSession.class, Integer.class, ExpressionType.PROPERTY, "number of [all] changed blocks (in|of) [edit[ ]session] %editsession%"); Skript.registerExpression(ExprChangedBlocksSession.class, Integer.class, ExpressionType.PROPERTY, "number of [all] changed blocks (in|of) [edit[ ]session] %editsession%");
Skript.registerExpression(ExprNewEditSession.class, EditSession.class, ExpressionType.PROPERTY, "new edit[ ]session in [world] %world% [with] [max[imum]] [block] limit [change] [of] %integer%"); Skript.registerExpression(ExprNewEditSession.class, EditSession.class, ExpressionType.PROPERTY, "[new] edit[ ]session in [world] %world% [with] [max[imum]] [block] limit [change] [of] %integer%");
Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection"); Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection");
Skript.registerExpression(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(ExprSelectionPos.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ](0¦1|1¦2) of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ](0¦1|1¦2)");
Skript.registerExpression(ExprSelectionPos2.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ]2 of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ]2"); Skript.registerExpression(ExprSelectionArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)3¦(z( |-)size|length)4¦area) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection (0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)3¦(z( |-)size|length)4¦area)");
Skript.registerExpression(ExprVolumeOfSelection.class, Integer.class, ExpressionType.SIMPLE, "volume of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection volume"); Skript.registerExpression(ExprSchematicArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)3¦(z( |-)size|length)4¦area) of schem[atic] [from] %string%");
Skript.registerExpression(ExprWidthOfSelection.class, Integer.class, ExpressionType.SIMPLE, "(x( |-)size|width) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection (x( |-)size|width)");
Skript.registerExpression(ExprLengthOfSelection.class, Integer.class, ExpressionType.SIMPLE, "(z( |-)size|length) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we) ]selection (z( |-)size|length)");
Skript.registerExpression(ExprHeightOfSelection.class, Integer.class, ExpressionType.SIMPLE, "(y( |-)size|height) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we) ]selection (y( |-)size|height)");
Skript.registerExpression(ExprAreaOfSelection.class, Integer.class, ExpressionType.SIMPLE, "area of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection area");
Skript.registerExpression(ExprVolumeOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "volume of schem[atic] [from] %string%");
Skript.registerExpression(ExprWidthOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(x( |-)size|width) 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(ExprAreaOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "area of schem[atic] [from] %string%");
Classes.registerClass(new ClassInfo<EditSession>(EditSession.class, "editsession").name("Edit Session").user("edit ?sessions?")); Classes.registerClass(new ClassInfo<EditSession>(EditSession.class, "editsession").name("Edit Session").user("edit ?sessions?"));
try { try {
Class.forName("com.sk89q.worldedit.extent.logging.AbstractLoggingExtent"); Class.forName("com.sk89q.worldedit.extent.logging.AbstractLoggingExtent");
@ -451,7 +178,7 @@ public class SkStuff extends JavaPlugin {
} }
getLogger().info("Everything ready! Loaded a total of " + condAmount + (condAmount == 1 ? " condition, " : " conditions, ") + effAmount + (effAmount == 1 ? " effect, " : " effects, ") + (evtWE ? "1 event, " : "") + 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, ") + (evtWE ? "1 event, " : "") + exprAmount + (exprAmount == 1 ? " expression" : " expressions and ") + typeAmount + (typeAmount == 1 ? " type!" : " types!"));
} else { } else {
getLogger().info("Unable to find Skript, disabling SkStuff..."); getLogger().info("Unable to find Skript or Skript isn't accepting registrations, disabling SkStuff...");
Bukkit.getPluginManager().disablePlugin(this);; Bukkit.getPluginManager().disablePlugin(this);;
} }
} }
@ -459,4 +186,4 @@ public class SkStuff extends JavaPlugin {
public void onDisable() { public void onDisable() {
getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully disabled."); getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully disabled.");
} }
} }

View File

@ -0,0 +1,171 @@
package me.TheBukor.SkStuff.expressions;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import ch.njol.skript.Skript;
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 me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprFileNBT extends SimpleExpression<Object> {
private Expression<String> input;
private boolean using1_7 = false;
private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase");
private Class<?> nbtToolsClass = ReflectionUtils.getNMSClass("NBTCompressedStreamTools");
private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
private Class<?> nbtParseExClass = ReflectionUtils.getNMSClass("MojangsonParseException");
private Class<?> nbtParserClass = ReflectionUtils.getNMSClass("MojangsonParser");
@Override
public Class<? extends Object> getReturnType() {
return nbtClass;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
input = (Expression<String>) expr[0];
String bukkitVersion = ReflectionUtils.getVersion();
if (bukkitVersion.startsWith("v1_7_R")) {
using1_7 = true;
}
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT from file " + input.toString(e, false);
}
@Override
@Nullable
public Object[] get(Event e) {
Object NBT = null;
File file = new File(input.getSingle(e));
InputStream fis;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException ex) {
return null; // File doesn't exist
}
try {
NBT = nbtToolsClass.getMethod("a", FileInputStream.class).invoke(NBT, fis);
fis.close();
} catch (Exception ex) {
if (ex instanceof InvocationTargetException) {
if (ex.getCause().getClass().equals(nbtParseExClass)) {
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
}
ex.printStackTrace();
}
ex.printStackTrace();
} finally {
try {
fis.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return new Object[] { NBT };
}
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
File file = new File(input.getSingle(e));
String tags = (String) delta[0];
OutputStream os = null;
InputStream fis = null;
try {
os = new FileOutputStream(file);
fis = new FileInputStream(file);
} catch (FileNotFoundException ex) {
return; // File doesn't exist.
}
if (mode == ChangeMode.ADD) {
try {
Object NBT = null;
NBT = nbtToolsClass.getMethod("a", FileInputStream.class).invoke(NBT, fis);
Object NBT1 = null;
NBT1 = nbtParserClass.getMethod("parse", nbtClass).invoke(NBT1, tags);
if (!using1_7) {
NBT.getClass().getMethod("a", nbtClass).invoke(NBT, NBT1);
} else {
NBT.getClass().getMethod("set", String.class, nbtBaseClass).invoke(NBT, "", NBT1);
}
nbtToolsClass.getMethod("a", nbtClass, FileOutputStream.class).invoke(nbtToolsClass.newInstance(), NBT, os);
fis.close();
os.close();
} catch (Exception ex) {
if (ex instanceof InvocationTargetException) {
if (ex.getCause().getClass().equals(nbtParseExClass) ) {
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
}
ex.printStackTrace();
}
ex.printStackTrace();
} finally {
try {
fis.close();
os.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
} else if (mode == ChangeMode.REMOVE) {
try {
Object NBT = null;
NBT = nbtToolsClass.getMethod("a", FileInputStream.class).invoke(NBT, fis);
for (Object s : delta) {
nbtClass.getMethod("remove", String.class).invoke(NBT, s);
}
nbtToolsClass.getMethod("a", nbtClass, FileOutputStream.class).invoke(nbtToolsClass.newInstance(), NBT, os);
Bukkit.broadcastMessage("\n\nSecond: " + NBT.toString());
fis.close();
os.close();
} catch (Exception ex) {
if (ex instanceof InvocationTargetException) {
if (ex.getCause().getClass().equals(nbtParseExClass)) {
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
}
ex.printStackTrace();
} else if (ex instanceof EOFException) {
//No actual error, just end of the file. Ignore it.
}
ex.printStackTrace();
}
}
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
return CollectionUtils.array(String.class);
}
return null;
}
}

View File

@ -1,123 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipException;
import javax.annotation.Nullable;
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.MojangsonParser;
import net.minecraft.server.v1_8_R1.NBTCompressedStreamTools;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
public class ExprFileNBTv1_8_R1 extends SimpleExpression<NBTTagCompound> {
private Expression<String> input;
@Override
public Class<? extends NBTTagCompound> getReturnType() {
return NBTTagCompound.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
input = (Expression<String>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of file from file " + input.toString(e, false);
}
@Override
@Nullable
protected NBTTagCompound[] get(Event e) {
NBTTagCompound NBT = null;
File file = new File(input.getSingle(e));
if (file.exists()) {
try {
InputStream fis = new FileInputStream(file);
NBT = NBTCompressedStreamTools.a(fis);
fis.close();
} catch (EOFException ex) {
//End of file, no error.
} catch (ZipException ex) {
return null; //Not a valid file (not compressed in GZIP format)
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
return null; // Specified file doesn't exist
}
return new NBTTagCompound[] { NBT };
}
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
File file = new File(input.getSingle(e));
String tags = (String) delta[0];
if (mode == ChangeMode.ADD) {
try {
InputStream fis = new FileInputStream(file);
NBTTagCompound NBT = NBTCompressedStreamTools.a(fis);
OutputStream os = new FileOutputStream(file);
NBTTagCompound NBT1 = MojangsonParser.parse(tags);
NBT.a(NBT1);
NBTCompressedStreamTools.a(NBT, os);
fis.close();
os.close();
} catch (EOFException ex) {
//End of file, no error.
} catch (ZipException ex) {
return; //Not a valid file (not compressed in GZIP format)
} catch (IOException ex) {
ex.printStackTrace();
}
} else if (mode == ChangeMode.REMOVE) {
try {
InputStream fis = new FileInputStream(file);
NBTTagCompound NBT = NBTCompressedStreamTools.a(fis);
OutputStream os = new FileOutputStream(file);
NBT.remove(tags);
NBTCompressedStreamTools.a(NBT, os);
fis.close();
os.close();
} catch (EOFException ex) {
//End of file, no error.
} catch (ZipException ex) {
return; //Not a valid file (not compressed in GZIP format)
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
return CollectionUtils.array(String.class);
}
return null;
}
}

View File

@ -1,127 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipException;
import javax.annotation.Nullable;
import org.bukkit.event.Event;
import ch.njol.skript.Skript;
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.MojangsonParseException;
import net.minecraft.server.v1_8_R2.MojangsonParser;
import net.minecraft.server.v1_8_R2.NBTCompressedStreamTools;
import net.minecraft.server.v1_8_R2.NBTTagCompound;
public class ExprFileNBTv1_8_R2 extends SimpleExpression<NBTTagCompound> {
private Expression<String> input;
@Override
public Class<? extends NBTTagCompound> getReturnType() {
return NBTTagCompound.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
input = (Expression<String>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of file from file " + input.toString(e, false);
}
@Override
@Nullable
protected NBTTagCompound[] get(Event e) {
NBTTagCompound NBT = null;
File file = new File(input.getSingle(e));
if (file.exists()) {
try {
InputStream fis = new FileInputStream(file);
NBT = NBTCompressedStreamTools.a(fis);
fis.close();
} catch (EOFException ex) {
//End of file, no error.
} catch (ZipException ex) {
return null; //Not a valid file (not compressed in GZIP format)
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
return null; // Specified file doesn't exist
}
return new NBTTagCompound[] { NBT };
}
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
File file = new File(input.getSingle(e));
String tags = (String) delta[0];
if (mode == ChangeMode.ADD) {
try {
InputStream fis = new FileInputStream(file);
NBTTagCompound NBT = NBTCompressedStreamTools.a(fis);
OutputStream os = new FileOutputStream(file);
NBTTagCompound NBT1 = MojangsonParser.parse(tags);
NBT.a(NBT1);
NBTCompressedStreamTools.a(NBT, os);
fis.close();
os.close();
} catch (EOFException ex) {
//End of file, no error.
} catch (ZipException ex) {
return; //Not a valid file (not compressed in GZIP format)
} catch (IOException ex) {
ex.printStackTrace();
} catch (MojangsonParseException ex) {
Skript.warning("Error when parsing NBT - " + ex.getMessage());
}
} else if (mode == ChangeMode.REMOVE) {
try {
InputStream fis = new FileInputStream(file);
NBTTagCompound NBT = NBTCompressedStreamTools.a(fis);
OutputStream os = new FileOutputStream(file);
NBT.remove(tags);
NBTCompressedStreamTools.a(NBT, os);
fis.close();
os.close();
} catch (EOFException ex) {
//End of file, no error.
} catch (ZipException ex) {
return; //Not a valid file (not compressed in GZIP format)
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) {
return CollectionUtils.array(String.class);
}
return null;
}
}

View File

@ -0,0 +1,111 @@
package me.TheBukor.SkStuff.expressions;
import java.lang.reflect.Field;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
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 me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprFireProof extends SimpleExpression<Boolean> {
private Expression<Entity> entity;
private Class<?> craftEntClass = ReflectionUtils.getOBCClass("entity.CraftEntity");
private Class<?> entityClass = ReflectionUtils.getNMSClass("Entity");
@Override
public Class<? extends Boolean> getReturnType() {
return Boolean.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
entity = (Expression<Entity>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "fireproof state of " + entity.toString(e, false);
}
@Override
@Nullable
protected Boolean[] get(Event e) {
Entity ent = entity.getSingle(e);
if (ent == null)
return null;
Object nmsEnt;
Boolean fireProof = null;
try {
nmsEnt = craftEntClass.getMethod("getHandle").invoke(ent);
fireProof = (Boolean) nmsEnt.getClass().getMethod("isFireProof").invoke(nmsEnt);
} catch (Exception ex) {
ex.printStackTrace();
}
return new Boolean[] { fireProof };
}
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
Entity ent = entity.getSingle(e);
if (ent == null)
return;
Object nmsEnt = null;
try {
nmsEnt = craftEntClass.getMethod("getHandle").invoke(ent);
} catch (Exception ex) {
ex.printStackTrace();
}
if (mode == ChangeMode.SET) {
Boolean newValue = (Boolean) delta[0];
try {
//Field field = nmsEnt.getClass().getDeclaredField("fireProof");
Bukkit.broadcastMessage("Looping all declared fields...");
Field field = null;
int i = 1;
for (Field f : entityClass.getDeclaredFields()) {
Bukkit.broadcastMessage("Field #" + i + " = \u00A7b" + f.getName());
if (f.getName().toLowerCase().contains("fire")) {
field = f;
}
i++;
}
if (field == null) {
Bukkit.broadcastMessage("No field containing \"fire\" was found...");
return;
}
field.setAccessible(true);
field.setBoolean(nmsEnt, newValue);
field.setAccessible(false);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.SET) {
return CollectionUtils.array(Boolean.class);
}
return null;
}
}

View File

@ -1,51 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.Selection;
import javax.annotation.Nullable;
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;
public class ExprHeightOfSelection extends SimpleExpression<Integer> {
private Expression<Player> player;
@Override
public Class<? extends Integer> getReturnType() {
return Integer.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
player = (Expression<Player>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the height of the WorldEdit selection of " + player.toString(e, false);
}
@Override
@Nullable
protected Integer[] get(Event e) {
WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
Selection sel = we.getSelection(player.getSingle(e));
if (sel == null)
return null;
return new Integer[] { sel.getHeight() };
}
}

View File

@ -0,0 +1,89 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprItemNBT extends SimpleExpression<ItemStack> {
private Boolean useParseException = true;
private Expression<ItemStack> itemStack;
private Expression<String> string;
private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
private Class<?> nbtParseClass = ReflectionUtils.getNMSClass("MojangsonParser");
private Class<?> nbtParseExClass = ReflectionUtils.getNMSClass("MojangsonParseException");
private Class<?> nmsItemClass = ReflectionUtils.getNMSClass("ItemStack");
private Class<?> craftItemClass = ReflectionUtils.getOBCClass("inventory.CraftItemStack");
@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
itemStack = (Expression<ItemStack>) expr[0];
string = (Expression<String>) expr[1];
String bukkitVersion = ReflectionUtils.getVersion();
if (bukkitVersion.contains("v1_7_R") || bukkitVersion.equals("v1_8_R1")) {
useParseException = false;
}
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return itemStack.toString(e, false) + " with custom NBT " + string.toString(e, false);
}
@Override
@Nullable
public ItemStack[] get(Event e) {
ItemStack item = itemStack.getSingle(e);
String newTags = string.getSingle(e);
if (item.getType() == Material.AIR || item == null) {
return null;
}
Object nmsItem = null;
try {
nmsItem = craftItemClass.getMethod("asNMSCopy", ItemStack.class).invoke(item, item);
} catch (Exception ex) {
ex.printStackTrace();
}
try {
Object NBT = null;
NBT = nbtParseClass.getMethod("parse", String.class).invoke(NBT, newTags);
if (NBT == null || NBT.toString().equals("{}")) { //"{}" is an empty compound.
return new ItemStack[] { item }; //There's no NBT involved, so just give a normal item.
}
nmsItem.getClass().getMethod("setTag", nbtClass).invoke(nmsItem, NBT);
} catch (Exception ex) {
if (useParseException && ex.getClass().equals(nbtParseExClass))
Skript.warning(ChatColor.RED + "Error when parsing NBT - " + ex.getMessage());
}
Object newItem = null;
try {
newItem = craftItemClass.getMethod("asCraftMirror", nmsItemClass).invoke(newItem, nmsItem);
} catch (Exception ex) {
ex.printStackTrace();
}
return new ItemStack[] { (ItemStack) newItem };
}
}

View File

@ -1,61 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
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 net.minecraft.server.v1_7_R1.MojangsonParser;
import net.minecraft.server.v1_7_R1.NBTTagCompound;
public class ExprItemNBTv1_7_R1 extends SimpleExpression<ItemStack> {
private Expression<ItemStack> itemStack;
private Expression<String> string;
@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
itemStack = (Expression<ItemStack>) expr[0];
string = (Expression<String>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return itemStack.toString(e, false) + " with custom NBT";
}
@Override
@Nullable
public ItemStack[] get(Event e) {
ItemStack item = itemStack.getSingle(e);
String newTags = string.getSingle(e);
if (item.getType() == Material.AIR || item == null) {
return null;
}
net.minecraft.server.v1_7_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = (NBTTagCompound) MojangsonParser.a(newTags);
if (NBT == null || NBT.isEmpty()) {
return new ItemStack[] { item };
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
return new ItemStack[] { newItem };
}
}

View File

@ -1,61 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftItemStack;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
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 net.minecraft.server.v1_7_R2.MojangsonParser;
import net.minecraft.server.v1_7_R2.NBTTagCompound;
public class ExprItemNBTv1_7_R2 extends SimpleExpression<ItemStack> {
private Expression<ItemStack> itemStack;
private Expression<String> string;
@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
itemStack = (Expression<ItemStack>) expr[0];
string = (Expression<String>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return itemStack.toString(e, false) + " with custom NBT";
}
@Override
@Nullable
public ItemStack[] get(Event e) {
ItemStack item = itemStack.getSingle(e);
String newTags = string.getSingle(e);
if (item.getType() == Material.AIR || item == null) {
return null;
}
net.minecraft.server.v1_7_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = (NBTTagCompound) MojangsonParser.parse(newTags);
if (NBT == null || NBT.isEmpty()) {
return new ItemStack[] { item };
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
return new ItemStack[] { newItem };
}
}

View File

@ -1,61 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
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 net.minecraft.server.v1_7_R3.MojangsonParser;
import net.minecraft.server.v1_7_R3.NBTTagCompound;
public class ExprItemNBTv1_7_R3 extends SimpleExpression<ItemStack> {
private Expression<ItemStack> itemStack;
private Expression<String> string;
@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
itemStack = (Expression<ItemStack>) expr[0];
string = (Expression<String>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return itemStack.toString(e, false) + " with custom NBT";
}
@Override
@Nullable
public ItemStack[] get(Event e) {
ItemStack item = itemStack.getSingle(e);
String newTags = string.getSingle(e);
if (item.getType() == Material.AIR || item == null) {
return null;
}
net.minecraft.server.v1_7_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = (NBTTagCompound) MojangsonParser.parse(newTags);
if (NBT == null || NBT.isEmpty()) {
return new ItemStack[] { item };
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
return new ItemStack[] { newItem };
}
}

View File

@ -1,61 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
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 net.minecraft.server.v1_7_R4.MojangsonParser;
import net.minecraft.server.v1_7_R4.NBTTagCompound;
public class ExprItemNBTv1_7_R4 extends SimpleExpression<ItemStack> {
private Expression<ItemStack> itemStack;
private Expression<String> string;
@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
itemStack = (Expression<ItemStack>) expr[0];
string = (Expression<String>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return itemStack.toString(e, false) + " with custom NBT";
}
@Override
@Nullable
public ItemStack[] get(Event e) {
ItemStack item = itemStack.getSingle(e);
String newTags = string.getSingle(e);
if (item.getType() == Material.AIR || item == null) {
return null;
}
net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = (NBTTagCompound) MojangsonParser.parse(newTags);
if (NBT == null || NBT.isEmpty()) {
return new ItemStack[] { item };
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
return new ItemStack[] { newItem };
}
}

View File

@ -1,61 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
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 net.minecraft.server.v1_8_R1.MojangsonParser;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
public class ExprItemNBTv1_8_R1 extends SimpleExpression<ItemStack> {
private Expression<ItemStack> itemStack;
private Expression<String> string;
@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
itemStack = (Expression<ItemStack>) expr[0];
string = (Expression<String>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return itemStack.toString(e, false) + " with custom NBT";
}
@Override
@Nullable
public ItemStack[] get(Event e) {
ItemStack item = itemStack.getSingle(e);
String newTags = string.getSingle(e);
if (item.getType() == Material.AIR || item == null) {
return null;
}
net.minecraft.server.v1_8_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = MojangsonParser.parse(newTags);
if (NBT == null || NBT.isEmpty()) {
return new ItemStack[] { item };
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
return new ItemStack[] { newItem };
}
}

View File

@ -1,68 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import net.minecraft.server.v1_8_R2.MojangsonParseException;
import net.minecraft.server.v1_8_R2.MojangsonParser;
import net.minecraft.server.v1_8_R2.NBTTagCompound;
public class ExprItemNBTv1_8_R2 extends SimpleExpression<ItemStack> {
private Expression<ItemStack> itemStack;
private Expression<String> string;
@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
itemStack = (Expression<ItemStack>) expr[0];
string = (Expression<String>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return itemStack.toString(e, false) + " with custom NBT";
}
@Override
@Nullable
public ItemStack[] get(Event e) {
ItemStack item = itemStack.getSingle(e);
String newTags = string.getSingle(e);
if (item.getType() == Material.AIR || item == null) {
return null;
}
net.minecraft.server.v1_8_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
try {
NBTTagCompound NBT = MojangsonParser.parse(newTags);
if (NBT == null || NBT.isEmpty()) {
return new ItemStack[] { item };
}
nmsItem.setTag(NBT);
} catch (MojangsonParseException ex) {
Skript.warning(ChatColor.RED + "Error when parsing NBT - " + ex.getMessage());
}
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
return new ItemStack[] { newItem };
}
}

View File

@ -1,68 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import net.minecraft.server.v1_8_R3.MojangsonParseException;
import net.minecraft.server.v1_8_R3.MojangsonParser;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
public class ExprItemNBTv1_8_R3 extends SimpleExpression<ItemStack> {
private Expression<ItemStack> itemStack;
private Expression<String> string;
@Override
public Class<? extends ItemStack> getReturnType() {
return ItemStack.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
itemStack = (Expression<ItemStack>) expr[0];
string = (Expression<String>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return itemStack.toString(e, false) + " with custom NBT";
}
@Override
@Nullable
public ItemStack[] get(Event e) {
ItemStack item = itemStack.getSingle(e);
String newTags = string.getSingle(e);
if (item.getType() == Material.AIR || item == null) {
return null;
}
net.minecraft.server.v1_8_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
try {
NBTTagCompound NBT = MojangsonParser.parse(newTags);
if (NBT == null || NBT.isEmpty()) {
return new ItemStack[] { item };
}
nmsItem.setTag(NBT);
} catch (MojangsonParseException ex) {
Skript.warning(ChatColor.RED + "Error when parsing NBT - " + ex.getMessage());
}
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
return new ItemStack[] { newItem };
}
}

View File

@ -1,51 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.Selection;
import javax.annotation.Nullable;
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;
public class ExprLengthOfSelection extends SimpleExpression<Integer> {
private Expression<Player> player;
@Override
public Class<? extends Integer> getReturnType() {
return Integer.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
player = (Expression<Player>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the length of the WorldEdit selection of " + player.toString(e, false);
}
@Override
@Nullable
protected Integer[] get(Event e) {
WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
Selection sel = we.getSelection(player.getSingle(e));
if (sel == null)
return null;
return new Integer[] { sel.getLength() };
}
}

View File

@ -0,0 +1,327 @@
package me.TheBukor.SkStuff.expressions;
import java.lang.reflect.InvocationTargetException;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
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.skript.util.Slot;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprNBTOf extends SimpleExpression<Object> {
private Boolean using1_7 = false;
private Expression<?> target;
private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase");
private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
private Class<?> nbtParseExClass = ReflectionUtils.getNMSClass("MojangsonParseException");
private Class<?> nbtParserClass = ReflectionUtils.getNMSClass("MojangsonParser");
private Class<?> nmsPosClass = ReflectionUtils.getNMSClass("BlockPosition");
private Class<?> nmsItemClass = ReflectionUtils.getNMSClass("ItemStack");
private Class<?> craftEntClass = ReflectionUtils.getOBCClass("entity.CraftEntity");
private Class<?> craftItemClass = ReflectionUtils.getOBCClass("inventory.CraftItemStack");
private Class<?> craftWorldClass = ReflectionUtils.getOBCClass("CraftWorld");
@Override
public Class<? extends Object> getReturnType() {
return nbtClass;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
target = expr[0];
String bukkitVersion = ReflectionUtils.getVersion();
if (bukkitVersion.startsWith("v1_7_R")) {
using1_7 = true;
}
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of " + target.toString(e, false);
}
@Override
@Nullable
public Object[] get(Event e) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
Object NBT = null;
try {
Object nmsEnt = craftEntClass.getMethod("getHandle").invoke(tar);
NBT = nbtClass.newInstance();
nmsEnt.getClass().getMethod("e", nbtClass).invoke(nmsEnt, NBT);
} catch (Exception ex) {
ex.printStackTrace();
}
return new Object[] { NBT };
} else if (tar instanceof Block) {
Block block = (Block) tar;
Object NBT = null;
Object tileEntity = null;
try {
NBT = nbtClass.newInstance();
Object craftWorld = craftWorldClass.cast(block.getWorld());
Object nmsWorld = craftWorld.getClass().getMethod("getHandle").invoke(craftWorld);
tileEntity = nmsWorld.getClass().getMethod("getTileEntity", nmsPosClass).invoke(nmsWorld, nmsPosClass.getConstructor(int.class, int.class, int.class).newInstance(block.getX(), block.getY(), block.getZ()));
} catch (Exception ex) {
ex.printStackTrace();
}
if (tileEntity == null) {
return null;
}
try {
tileEntity.getClass().getMethod("b", nbtClass).invoke(tileEntity, NBT);
} catch (Exception ex) {
ex.printStackTrace();
}
return new Object[] { NBT };
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return null;
}
Object NBT = null;
try {
Object nmsItem = craftItemClass.getMethod("asNMSCopy", ItemStack.class).invoke(item, item);
NBT = nmsItem.getClass().getMethod("getTag").invoke(nmsItem);
} catch (Exception ex) {
ex.printStackTrace();
}
if (NBT == null || NBT.toString().equals("{}")) { //Null or empty.
return null;
}
return new Object[] { NBT };
}
return null;
}
@Override
public void change(Event e, Object[] delta, ChangeMode mode) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
Object NBT = null;
Object nmsEnt = null;
try {
nmsEnt = craftEntClass.getMethod("getHandle").invoke(tar);
NBT = nbtClass.newInstance();
nmsEnt.getClass().getMethod("e", nbtClass).invoke(nmsEnt, NBT);
} catch (Exception ex) {
ex.printStackTrace();
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
try {
Object NBT1 = null;
NBT1 = nbtParserClass.getMethod("parse", String.class).invoke(NBT1, newTags);
NBT1.getClass().getMethod("remove", String.class).invoke(NBT1, "UUIDMost");
NBT1.getClass().getMethod("remove", String.class).invoke(NBT1, "UUIDLeast");
NBT1.getClass().getMethod("remove", String.class).invoke(NBT1, "WorldUUIDMost");
NBT1.getClass().getMethod("remove", String.class).invoke(NBT1, "WorldUUIDLeast");
NBT1.getClass().getMethod("remove", String.class).invoke(NBT1, "Bukkit.updateLevel");
if (!using1_7) {
NBT.getClass().getMethod("a", nbtClass).invoke(NBT, NBT1);
} else {
NBT.getClass().getMethod("set", String.class, nbtBaseClass).invoke(NBT, "", NBT1);
}
nmsEnt.getClass().getMethod("f", nbtClass).invoke(nmsEnt, NBT);
} catch (Exception ex) {
if (ex instanceof InvocationTargetException) {
if (ex.getCause().getClass().equals(nbtParseExClass) ) {
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
}
ex.printStackTrace();
}
ex.printStackTrace();
}
} else if (mode == ChangeMode.REMOVE) {
for (Object s : delta) {
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast" || s != "Bukkit.updateLevel") {
try {
NBT.getClass().getMethod("remove", String.class).invoke(NBT, (String) s);
nmsEnt.getClass().getMethod("f", nbtClass).invoke(nmsEnt, NBT);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
} else if (tar instanceof Block) {
Block block = (Block) tar;
Object NBT = null;
Object tileEntity = null;
Object nmsWorld = null;
try {
NBT = nbtClass.newInstance();
Object craftWorld = craftWorldClass.cast(block.getWorld());
nmsWorld = craftWorld.getClass().getMethod("getHandle").invoke(craftWorld);
tileEntity = nmsWorld.getClass().getMethod("getTileEntity", nmsPosClass).invoke(nmsWorld, nmsPosClass.getConstructor(int.class, int.class, int.class).newInstance(block.getX(), block.getY(), block.getZ()));
} catch (Exception ex) {
ex.printStackTrace();
}
if (tileEntity == null) {
return;
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
try {
tileEntity.getClass().getMethod("b", nbtClass).invoke(tileEntity, NBT);
} catch (Exception ex) {
ex.printStackTrace();
}
try {
Object NBT1 = null;
NBT1 = nbtParserClass.getMethod("parse", String.class).invoke(NBT1, newTags);
if (!using1_7) {
NBT.getClass().getMethod("a", nbtClass).invoke(NBT, NBT1);
} else {
NBT.getClass().getMethod("set", String.class, nbtBaseClass).invoke(NBT, "", NBT1);
}
NBT1.getClass().getMethod("setInt", String.class, int.class).invoke(NBT1, "x", block.getX());
NBT1.getClass().getMethod("setInt", String.class, int.class).invoke(NBT1, "y", block.getY());
NBT1.getClass().getMethod("setInt", String.class, int.class).invoke(NBT1, "z", block.getZ());
tileEntity.getClass().getMethod("a", nbtClass).invoke(tileEntity, NBT);
tileEntity.getClass().getMethod("update").invoke(tileEntity);
nmsWorld.getClass().getMethod("notify", nmsPosClass).invoke(nmsWorld, tileEntity.getClass().getMethod("getPosition").invoke(tileEntity));
} catch (Exception ex) {
if (ex instanceof InvocationTargetException) {
if (ex.getCause().getClass().equals(nbtParseExClass) ) {
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
}
ex.printStackTrace();
}
ex.printStackTrace();
}
} else if (mode == ChangeMode.REMOVE) {
try {
tileEntity.getClass().getMethod("b", nbtClass).invoke(tileEntity, NBT);
} catch (Exception ex) {
ex.printStackTrace();
}
for (Object s : delta) {
if (s != "x" || s != "y" || s != "z" || s != "id") {
try {
NBT.getClass().getMethod("remove", String.class).invoke(NBT, ((String) s));
tileEntity.getClass().getMethod("a", nbtClass).invoke(tileEntity, NBT);
tileEntity.getClass().getMethod("update").invoke(tileEntity);
nmsWorld.getClass().getMethod("notify", nmsPosClass).invoke(nmsWorld, tileEntity.getClass().getMethod("getPosition").invoke(tileEntity));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return;
}
Object nmsItem = null;
Object NBT = null;
try {
nmsItem = craftItemClass.getMethod("asNMSCopy", ItemStack.class).invoke(item, item);
NBT = nmsItem.getClass().getMethod("getTag").invoke(nmsItem);
} catch (Exception ex) {
ex.printStackTrace();
}
if (NBT == null) { //No need to check for "{}" (empty) NBT because a new instance of NBT is actually "{}".
try {
NBT = nbtClass.newInstance();
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
try {
Object NBT1 = null;
NBT1 = nbtParserClass.getMethod("parse", String.class).invoke(NBT1, newTags);
if (!using1_7) {
NBT.getClass().getMethod("a", nbtClass).invoke(NBT, NBT1);
} else {
NBT.getClass().getMethod("set", String.class, nbtBaseClass).invoke(NBT, "", NBT1);
}
nmsItem.getClass().getMethod("setTag", nbtClass).invoke(nmsItem, NBT);
Object newItem = null;
newItem = craftItemClass.getMethod("asCraftMirror", nmsItemClass).invoke(newItem, nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem((ItemStack) newItem);
} catch (Exception ex) {
if (ex instanceof InvocationTargetException) {
if (ex.getCause().getClass().equals(nbtParseExClass) ) {
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
}
ex.printStackTrace();
}
ex.printStackTrace();
}
} else if (mode == ChangeMode.REMOVE) {
if (NBT == null || NBT.toString().equals("{}")) { //Check for "{}" (empty) NBT because executing the remove is just useless.
return;
}
for (Object s : delta) {
try {
NBT.getClass().getMethod("remove", String.class).invoke(NBT ,((String) s));
} catch (Exception ex) {
ex.printStackTrace();
}
}
Object newItem = null;
try {
nmsItem.getClass().getMethod("setTag", nbtClass).invoke(nmsItem, NBT);
newItem = craftItemClass.getMethod("asCraftMirror", nmsItemClass).invoke(newItem, nmsItem);
} catch (Exception ex) {
ex.printStackTrace();
}
Object[] slot = target.getSource().getAll(e);
((Slot) slot[0]).setItem((ItemStack) newItem);
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
Object newItem = null;
try {
nmsItem.getClass().getMethod("setTag", nbtClass).invoke(nmsItem, nbtClass.newInstance());
newItem = craftItemClass.getMethod("asCraftMirror", nmsItemClass).invoke(newItem, nmsItem);
} catch (Exception ex) {
ex.printStackTrace();
}
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem((ItemStack) newItem);
}
}
}
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
return CollectionUtils.array(String[].class);
}
return null;
}
}

View File

@ -1,194 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
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.skript.util.Slot;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import net.minecraft.server.v1_7_R1.MojangsonParser;
import net.minecraft.server.v1_7_R1.NBTTagCompound;
import net.minecraft.server.v1_7_R1.TileEntity;
public class ExprNBTv1_7_R1 extends SimpleExpression<NBTTagCompound> {
private Expression<?> target;
private NBTTagCompound[] returned;
@Override
public Class<? extends NBTTagCompound> getReturnType() {
return NBTTagCompound.class;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
target = expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of " + target.toString(e, false);
}
@Override
@Nullable
public NBTTagCompound[] get(Event e) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return null;
}
tileEntity.b(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return null;
}
NBTTagCompound NBT = CraftItemStack.asNMSCopy(item).getTag();
if (NBT == null || NBT.isEmpty()) {
return null;
}
returned = new NBTTagCompound[] { NBT };
}
return returned;
}
@Override
public void change(Event e, Object[] delta, ChangeMode mode) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.a(newTags);
NBT1.remove("UUIDMost");
NBT1.remove("UUIDLeast");
NBT1.remove("WorldUUIDLeast");
NBT1.remove("WorldUUIDMost");
NBT1.remove("Bukkit.updateLevel");
NBT.set("", NBT1);
ent.getHandle().f(NBT);
} else if (mode == ChangeMode.REMOVE) {
ent.getHandle().e(NBT);
for (Object s : delta) {
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast"
|| s != "Bukkit.updateLevel") {
NBT.remove((String) s);
ent.getHandle().f(NBT);
}
}
}
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
tileEntity.b(NBT);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.a(newTags);
NBT.set("", NBT1);;
NBT.setInt("x", block.getX());
NBT.setInt("y", block.getY());
NBT.setInt("z", block.getZ());
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.x, tileEntity.y, tileEntity.z);;
} else if (mode == ChangeMode.REMOVE) {
tileEntity.b(NBT);
for (Object s : delta) {
if (s != "x" || s != "y" || s != "z" || s != "id") {
NBT.remove((String) s);
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.x, tileEntity.y, tileEntity.z);
}
}
}
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return;
}
net.minecraft.server.v1_7_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = nmsItem.getTag();
if (NBT == null) {
NBT = new NBTTagCompound();
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.a(newTags);
NBT.set("", NBT1);
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.REMOVE) {
NBT = nmsItem.getTag();
if (NBT == null || NBT.isEmpty()) {
return;
}
for (Object s : delta) {
NBT.remove((String) s);
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
nmsItem.setTag(new NBTTagCompound());
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
}
}
}
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE
|| mode == ChangeMode.RESET) {
return CollectionUtils.array(String.class);
}
return null;
}
}

View File

@ -1,194 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
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.skript.util.Slot;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import net.minecraft.server.v1_7_R2.MojangsonParser;
import net.minecraft.server.v1_7_R2.NBTTagCompound;
import net.minecraft.server.v1_7_R2.TileEntity;
public class ExprNBTv1_7_R2 extends SimpleExpression<NBTTagCompound> {
private Expression<?> target;
private NBTTagCompound[] returned;
@Override
public Class<? extends NBTTagCompound> getReturnType() {
return NBTTagCompound.class;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
target = expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of " + target.toString(e, false);
}
@Override
@Nullable
public NBTTagCompound[] get(Event e) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return null;
}
tileEntity.b(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return null;
}
NBTTagCompound NBT = CraftItemStack.asNMSCopy(item).getTag();
if (NBT == null || NBT.isEmpty()) {
return null;
}
returned = new NBTTagCompound[] { NBT };
}
return returned;
}
@Override
public void change(Event e, Object[] delta, ChangeMode mode) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.parse(newTags);
NBT1.remove("UUIDMost");
NBT1.remove("UUIDLeast");
NBT1.remove("WorldUUIDLeast");
NBT1.remove("WorldUUIDMost");
NBT1.remove("Bukkit.updateLevel");
NBT.set("", NBT1);
ent.getHandle().f(NBT);
} else if (mode == ChangeMode.REMOVE) {
ent.getHandle().e(NBT);
for (Object s : delta) {
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast"
|| s != "Bukkit.updateLevel") {
NBT.remove((String) s);
ent.getHandle().f(NBT);
}
}
}
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
tileEntity.b(NBT);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.parse(newTags);
NBT.set("", NBT1);;
NBT.setInt("x", block.getX());
NBT.setInt("y", block.getY());
NBT.setInt("z", block.getZ());
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.x, tileEntity.y, tileEntity.z);;
} else if (mode == ChangeMode.REMOVE) {
tileEntity.b(NBT);
for (Object s : delta) {
if (s != "x" || s != "y" || s != "z" || s != "id") {
NBT.remove((String) s);
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.x, tileEntity.y, tileEntity.z);
}
}
}
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return;
}
net.minecraft.server.v1_7_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = nmsItem.getTag();
if (NBT == null) {
NBT = new NBTTagCompound();
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.parse(newTags);
NBT.set("", NBT1);
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.REMOVE) {
NBT = nmsItem.getTag();
if (NBT == null || NBT.isEmpty()) {
return;
}
for (Object s : delta) {
NBT.remove((String) s);
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
nmsItem.setTag(new NBTTagCompound());
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
}
}
}
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE
|| mode == ChangeMode.RESET) {
return CollectionUtils.array(String.class);
}
return null;
}
}

View File

@ -1,194 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
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.skript.util.Slot;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import net.minecraft.server.v1_7_R3.MojangsonParser;
import net.minecraft.server.v1_7_R3.NBTTagCompound;
import net.minecraft.server.v1_7_R3.TileEntity;
public class ExprNBTv1_7_R3 extends SimpleExpression<NBTTagCompound> {
private Expression<?> target;
private NBTTagCompound[] returned;
@Override
public Class<? extends NBTTagCompound> getReturnType() {
return NBTTagCompound.class;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
target = expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of " + target.toString(e, false);
}
@Override
@Nullable
public NBTTagCompound[] get(Event e) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return null;
}
tileEntity.b(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return null;
}
NBTTagCompound NBT = CraftItemStack.asNMSCopy(item).getTag();
if (NBT == null || NBT.isEmpty()) {
return null;
}
returned = new NBTTagCompound[] { NBT };
}
return returned;
}
@Override
public void change(Event e, Object[] delta, ChangeMode mode) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.parse(newTags);
NBT1.remove("UUIDMost");
NBT1.remove("UUIDLeast");
NBT1.remove("WorldUUIDLeast");
NBT1.remove("WorldUUIDMost");
NBT1.remove("Bukkit.updateLevel");
NBT.set("", NBT1);
ent.getHandle().f(NBT);
} else if (mode == ChangeMode.REMOVE) {
ent.getHandle().e(NBT);
for (Object s : delta) {
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast"
|| s != "Bukkit.updateLevel") {
NBT.remove((String) s);
ent.getHandle().f(NBT);
}
}
}
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
tileEntity.b(NBT);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.parse(newTags);
NBT.set("", NBT1);;
NBT.setInt("x", block.getX());
NBT.setInt("y", block.getY());
NBT.setInt("z", block.getZ());
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.x, tileEntity.y, tileEntity.z);;
} else if (mode == ChangeMode.REMOVE) {
tileEntity.b(NBT);
for (Object s : delta) {
if (s != "x" || s != "y" || s != "z" || s != "id") {
NBT.remove((String) s);
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.x, tileEntity.y, tileEntity.z);
}
}
}
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return;
}
net.minecraft.server.v1_7_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
net.minecraft.server.v1_7_R3.NBTTagCompound NBT = nmsItem.getTag();
if (NBT == null) {
NBT = new NBTTagCompound();
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.parse(newTags);
NBT.set("", NBT1);
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.REMOVE) {
NBT = nmsItem.getTag();
if (NBT == null || NBT.isEmpty()) {
return;
}
for (Object s : delta) {
NBT.remove((String) s);
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
nmsItem.setTag(new NBTTagCompound());
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
}
}
}
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE
|| mode == ChangeMode.RESET) {
return CollectionUtils.array(String.class);
}
return null;
}
}

View File

@ -1,194 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
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.skript.util.Slot;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import net.minecraft.server.v1_7_R4.MojangsonParser;
import net.minecraft.server.v1_7_R4.NBTTagCompound;
import net.minecraft.server.v1_7_R4.TileEntity;
public class ExprNBTv1_7_R4 extends SimpleExpression<NBTTagCompound> {
private Expression<?> target;
private NBTTagCompound[] returned;
@Override
public Class<? extends NBTTagCompound> getReturnType() {
return NBTTagCompound.class;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
target = expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of " + target.toString(e, false);
}
@Override
@Nullable
public NBTTagCompound[] get(Event e) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return null;
}
tileEntity.b(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return null;
}
NBTTagCompound NBT = CraftItemStack.asNMSCopy(item).getTag();
if (NBT == null || NBT.isEmpty()) {
return null;
}
returned = new NBTTagCompound[] { NBT };
}
return returned;
}
@Override
public void change(Event e, Object[] delta, ChangeMode mode) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.parse(newTags);
NBT1.remove("UUIDMost");
NBT1.remove("UUIDLeast");
NBT1.remove("WorldUUIDLeast");
NBT1.remove("WorldUUIDMost");
NBT1.remove("Bukkit.updateLevel");
NBT.set("", NBT1);
ent.getHandle().f(NBT);
} else if (mode == ChangeMode.REMOVE) {
ent.getHandle().e(NBT);
for (Object s : delta) {
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast"
|| s != "Bukkit.updateLevel") {
NBT.remove((String) s);
ent.getHandle().f(NBT);
}
}
}
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle().getTileEntity(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
tileEntity.b(NBT);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.parse(newTags);
NBT.set("", NBT1);;
NBT.setInt("x", block.getX());
NBT.setInt("y", block.getY());
NBT.setInt("z", block.getZ());
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.x, tileEntity.y, tileEntity.z);;
} else if (mode == ChangeMode.REMOVE) {
tileEntity.b(NBT);
for (Object s : delta) {
if (s != "x" || s != "y" || s != "z" || s != "id") {
NBT.remove((String) s);
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.x, tileEntity.y, tileEntity.z);
}
}
}
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return;
}
net.minecraft.server.v1_7_R4.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = nmsItem.getTag();
if (NBT == null) {
NBT = new NBTTagCompound();
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
NBTTagCompound NBT1 = (NBTTagCompound) MojangsonParser.parse(newTags);
NBT.set("", NBT1);
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.REMOVE) {
NBT = nmsItem.getTag();
if (NBT == null || NBT.isEmpty()) {
return;
}
for (Object s : delta) {
NBT.remove((String) s);
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
nmsItem.setTag(new NBTTagCompound());
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
}
}
}
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE
|| mode == ChangeMode.RESET) {
return CollectionUtils.array(String.class);
}
return null;
}
}

View File

@ -1,197 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
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.skript.util.Slot;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import net.minecraft.server.v1_8_R1.BlockPosition;
import net.minecraft.server.v1_8_R1.MojangsonParser;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
import net.minecraft.server.v1_8_R1.TileEntity;
public class ExprNBTv1_8_R1 extends SimpleExpression<NBTTagCompound> {
private Expression<?> target;
private NBTTagCompound[] returned;
@Override
public Class<? extends NBTTagCompound> getReturnType() {
return NBTTagCompound.class;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
target = expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of " + target.toString(e, false);
}
@Override
@Nullable
public NBTTagCompound[] get(Event e) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (tileEntity == null) {
return null;
}
tileEntity.b(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return null;
}
NBTTagCompound NBT = CraftItemStack.asNMSCopy(item).getTag();
if (NBT == null || NBT.isEmpty()) {
return null;
}
returned = new NBTTagCompound[] { NBT };
}
return returned;
}
@Override
public void change(Event e, Object[] delta, ChangeMode mode) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
NBT1.remove("UUIDMost");
NBT1.remove("UUIDLeast");
NBT1.remove("WorldUUIDLeast");
NBT1.remove("WorldUUIDMost");
NBT1.remove("Bukkit.updateLevel");
NBT.a(NBT1);
ent.getHandle().f(NBT);
} else if (mode == ChangeMode.REMOVE) {
ent.getHandle().e(NBT);
for (Object s : delta) {
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast"
|| s != "Bukkit.updateLevel") {
NBT.remove((String) s);
ent.getHandle().f(NBT);
}
}
}
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (tileEntity == null) {
return;
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
tileEntity.b(NBT);
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
NBT.a(NBT1);
NBT1.setInt("x", block.getX());
NBT1.setInt("y", block.getY());
NBT1.setInt("z", block.getZ());
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
} else if (mode == ChangeMode.REMOVE) {
tileEntity.b(NBT);
for (Object s : delta) {
if (s != "x" || s != "y" || s != "z" || s != "id") {
NBT.remove((String) s);
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
}
}
}
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return;
}
net.minecraft.server.v1_8_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = nmsItem.getTag();
if (NBT == null) {
NBT = new NBTTagCompound();
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
NBT.a(NBT1);
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.REMOVE) {
NBT = nmsItem.getTag();
if (NBT == null || NBT.isEmpty()) {
return;
}
for (Object s : delta) {
NBT.remove((String) s);
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
nmsItem.setTag(new NBTTagCompound());
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
}
}
}
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE
|| mode == ChangeMode.RESET) {
return CollectionUtils.array(String.class);
}
return null;
}
}

View File

@ -1,211 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
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.skript.util.Slot;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import net.minecraft.server.v1_8_R2.BlockPosition;
import net.minecraft.server.v1_8_R2.MojangsonParseException;
import net.minecraft.server.v1_8_R2.MojangsonParser;
import net.minecraft.server.v1_8_R2.NBTTagCompound;
import net.minecraft.server.v1_8_R2.TileEntity;
public class ExprNBTv1_8_R2 extends SimpleExpression<NBTTagCompound> {
private Expression<?> target;
private NBTTagCompound[] returned;
@Override
public Class<? extends NBTTagCompound> getReturnType() {
return NBTTagCompound.class;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
target = expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of " + target.toString(e, false);
}
@Override
@Nullable
public NBTTagCompound[] get(Event e) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (tileEntity == null) {
return null;
}
tileEntity.b(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return null;
}
NBTTagCompound NBT = CraftItemStack.asNMSCopy(item).getTag();
if (NBT == null || NBT.isEmpty()) {
return null;
}
returned = new NBTTagCompound[] { NBT };
}
return returned;
}
@Override
public void change(Event e, Object[] delta, ChangeMode mode) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
try {
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
NBT1.remove("UUIDMost");
NBT1.remove("UUIDLeast");
NBT1.remove("WorldUUIDLeast");
NBT1.remove("WorldUUIDMost");
NBT1.remove("Bukkit.updateLevel");
NBT.a(NBT1);
ent.getHandle().f(NBT);
} catch (MojangsonParseException ex) {
Skript.warning("Error when parsing NBT - " + ex.getMessage());
}
} else if (mode == ChangeMode.REMOVE) {
ent.getHandle().e(NBT);
for (Object s : delta) {
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast"
|| s != "Bukkit.updateLevel") {
NBT.remove((String) s);
ent.getHandle().f(NBT);
}
}
}
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (tileEntity == null) {
return;
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
tileEntity.b(NBT);
try {
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
NBT.a(NBT1);
NBT1.setInt("x", block.getX());
NBT1.setInt("y", block.getY());
NBT1.setInt("z", block.getZ());
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
} catch (MojangsonParseException ex) {
Skript.warning("Error when parsing NBT - " + ex.getMessage());
}
} else if (mode == ChangeMode.REMOVE) {
tileEntity.b(NBT);
for (Object s : delta) {
if (s != "x" || s != "y" || s != "z" || s != "id") {
NBT.remove((String) s);
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
}
}
}
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return;
}
net.minecraft.server.v1_8_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = nmsItem.getTag();
if (NBT == null) {
NBT = new NBTTagCompound();
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
try {
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
NBT.a(NBT1);
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
} catch (MojangsonParseException ex) {
Skript.warning("Error when parsing NBT - " + ex.getMessage());
}
} else if (mode == ChangeMode.REMOVE) {
NBT = nmsItem.getTag();
if (NBT == null || NBT.isEmpty()) {
return;
}
for (Object s : delta) {
NBT.remove((String) s);
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
nmsItem.setTag(new NBTTagCompound());
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
}
}
}
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE
|| mode == ChangeMode.RESET) {
return CollectionUtils.array(String.class);
}
return null;
}
}

View File

@ -1,211 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.Skript;
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.skript.util.Slot;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.MojangsonParseException;
import net.minecraft.server.v1_8_R3.MojangsonParser;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.TileEntity;
public class ExprNBTv1_8_R3 extends SimpleExpression<NBTTagCompound> {
private Expression<?> target;
private NBTTagCompound[] returned;
@Override
public Class<? extends NBTTagCompound> getReturnType() {
return NBTTagCompound.class;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
target = expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the NBT of " + target.toString(e, false);
}
@Override
@Nullable
public NBTTagCompound[] get(Event e) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (tileEntity == null) {
return null;
}
tileEntity.b(NBT);
returned = new NBTTagCompound[] { NBT };
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return null;
}
NBTTagCompound NBT = CraftItemStack.asNMSCopy(item).getTag();
if (NBT == null || NBT.isEmpty()) {
return null;
}
returned = new NBTTagCompound[] { NBT };
}
return returned;
}
@Override
public void change(Event e, Object[] delta, ChangeMode mode) {
Object tar = target.getSingle(e);
if (tar instanceof Entity) {
CraftEntity ent = (CraftEntity) tar;
NBTTagCompound NBT = new NBTTagCompound();
ent.getHandle().e(NBT);
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
try {
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
NBT1.remove("UUIDMost");
NBT1.remove("UUIDLeast");
NBT1.remove("WorldUUIDLeast");
NBT1.remove("WorldUUIDMost");
NBT1.remove("Bukkit.updateLevel");
NBT.a(NBT1);
ent.getHandle().f(NBT);
} catch (MojangsonParseException ex) {
Skript.warning("Error when parsing NBT - " + ex.getMessage());
}
} else if (mode == ChangeMode.REMOVE) {
ent.getHandle().e(NBT);
for (Object s : delta) {
if (s != "UUIDMost" || s != "UUIDLeast" || s != "WorldUUIDMost" || s != "WorldUUIDLeast"
|| s != "Bukkit.updateLevel") {
NBT.remove((String) s);
ent.getHandle().f(NBT);
}
}
}
} else if (tar instanceof Block) {
Block block = (Block) tar;
NBTTagCompound NBT = new NBTTagCompound();
TileEntity tileEntity = ((CraftWorld) block.getWorld()).getHandle()
.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (tileEntity == null) {
return;
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
tileEntity.b(NBT);
try {
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
NBT.a(NBT1);
NBT1.setInt("x", block.getX());
NBT1.setInt("y", block.getY());
NBT1.setInt("z", block.getZ());
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
} catch (MojangsonParseException ex) {
Skript.warning("Error when parsing NBT - " + ex.getMessage());
}
} else if (mode == ChangeMode.REMOVE) {
tileEntity.b(NBT);
for (Object s : delta) {
if (s != "x" || s != "y" || s != "z" || s != "id") {
NBT.remove((String) s);
tileEntity.a(NBT);
tileEntity.update();
((CraftWorld) block.getWorld()).getHandle().notify(tileEntity.getPosition());
}
}
}
} else if (tar instanceof ItemStack) {
ItemStack item = (ItemStack) tar;
if (item.getType() == Material.AIR) {
return;
}
net.minecraft.server.v1_8_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
NBTTagCompound NBT = nmsItem.getTag();
if (NBT == null) {
NBT = new NBTTagCompound();
}
if (mode == ChangeMode.ADD) {
String newTags = (String) (delta[0]);
try {
NBTTagCompound NBT1 = MojangsonParser.parse(newTags);
NBT.a(NBT1);
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
} catch (MojangsonParseException ex) {
Skript.warning("Error when parsing NBT - " + ex.getMessage());
}
} else if (mode == ChangeMode.REMOVE) {
NBT = nmsItem.getTag();
if (NBT == null || NBT.isEmpty()) {
return;
}
for (Object s : delta) {
NBT.remove((String) s);
}
nmsItem.setTag(NBT);
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
((Slot) slot[0]).setItem(newItem);
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
nmsItem.setTag(new NBTTagCompound());
ItemStack newItem = CraftItemStack.asCraftMirror(nmsItem);
Object[] slot = target.getSource().getAll(e);
if (!(slot[0] instanceof Slot)) {
return;
}
((Slot) slot[0]).setItem(newItem);
}
}
}
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.DELETE
|| mode == ChangeMode.RESET) {
return CollectionUtils.array(String.class);
}
return null;
}
}

View File

@ -0,0 +1,70 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.Entity;
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;
public class ExprNoClip extends SimpleExpression<Boolean> {
private Expression<Entity> entity;
@Override
public Class<? extends Boolean> getReturnType() {
return Boolean.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
entity = (Expression<Entity>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "no clip state of " + entity.toString(e, false);
}
@Override
@Nullable
protected Boolean[] get(Event e) {
Entity ent = entity.getSingle(e);
if (ent == null)
return null;
return new Boolean[] { ((CraftEntity) ent).getHandle().noclip };
}
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
Entity ent = entity.getSingle(e);
if (ent == null)
return;
if (mode == ChangeMode.SET) {
Boolean newValue = (Boolean) delta[0];
((CraftEntity) ent).getHandle().noclip = newValue;
}
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.SET) {
return CollectionUtils.array(Boolean.class);
}
return null;
}
}

View File

@ -5,9 +5,10 @@ import java.io.IOException;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.schematic.MCEditSchematicFormat; import com.sk89q.worldedit.schematic.MCEditSchematicFormat;
import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.DataException;
@ -16,7 +17,7 @@ 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;
public class ExprVolumeOfSchematic extends SimpleExpression<Integer> { public class ExprSchematicArea extends SimpleExpression<Integer> {
private Expression<String> schematic; private Expression<String> schematic;
@Override @Override
@ -41,17 +42,19 @@ public class ExprVolumeOfSchematic extends SimpleExpression<Integer> {
return "the volume of the schematic from " + schematic.toString(e, false); return "the volume of the schematic from " + schematic.toString(e, false);
} }
@SuppressWarnings("deprecation")
@Override @Override
@Nullable @Nullable
protected Integer[] get(Event e) { protected Integer[] get(Event e) {
String schem = schematic.getSingle(e); String schem = schematic.getSingle(e);
File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic")));
Integer v = null; Vector v = null;
try { try {
v = ((Clipboard) MCEditSchematicFormat.getFormat(schemFile).load(schemFile)).getRegion().getArea(); v = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getSize();
} catch (DataException | IOException ex) { } catch (DataException | IOException ex) {
return null; return null;
} }
return new Integer[] { v }; Bukkit.broadcastMessage("vector: " + v.getX() + v.getY() + v.getZ());
return new Integer[] { 1 };
} }
} }

View File

@ -14,8 +14,10 @@ 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;
public class ExprAreaOfSelection extends SimpleExpression<Integer> { public class ExprSelectionArea extends SimpleExpression<Integer> {
private Expression<Player> player; private Expression<Player> player;
private Integer parseMark;
private String toStringMark;
@Override @Override
public Class<? extends Integer> getReturnType() { public Class<? extends Integer> getReturnType() {
@ -29,14 +31,26 @@ public class ExprAreaOfSelection extends SimpleExpression<Integer> {
@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) {
player = (Expression<Player>) expr[0]; player = (Expression<Player>) expr[0];
parseMark = result.mark;
if (parseMark == 0) {
toStringMark = "volume";
} else if (parseMark == 1) {
toStringMark = "width (x-size)";
} else if (parseMark == 2) {
toStringMark = "height (y-size)";
} else if (parseMark == 3) {
toStringMark = "length (z-size)";
} else if (parseMark == 4) {
toStringMark = "area";
}
return true; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean arg1) { public String toString(@Nullable Event e, boolean arg1) {
return "the area of the WorldEdit selection of " + player.toString(e, false); return "the " + toStringMark + " of the WorldEdit selection of " + player.toString(e, false);
} }
@Override @Override
@ -46,6 +60,18 @@ public class ExprAreaOfSelection extends SimpleExpression<Integer> {
Selection sel = we.getSelection(player.getSingle(e)); Selection sel = we.getSelection(player.getSingle(e));
if (sel == null) if (sel == null)
return null; return null;
return new Integer[] { sel.getWidth() * sel.getLength() }; Integer result = null;
if (parseMark == 0) {
result = sel.getArea();
} else if (parseMark == 1) {
result = sel.getWidth();
} else if (parseMark == 2) {
result = sel.getHeight();
} else if (parseMark == 3) {
result = sel.getLength();
} else if (parseMark == 4) {
result = (sel.getWidth() * sel.getLength());
}
return new Integer[] { result };
} }
} }

View File

@ -23,8 +23,9 @@ import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.CollectionUtils;
public class ExprSelectionPos2 extends SimpleExpression<Location> { public class ExprSelectionPos extends SimpleExpression<Location> {
private Expression<Player> player; private Expression<Player> player;
private boolean usePos2 = false;
private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
@Override @Override
@ -39,14 +40,17 @@ public class ExprSelectionPos2 extends SimpleExpression<Location> {
@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) {
player = (Expression<Player>) expr[0]; player = (Expression<Player>) expr[0];
if (result.mark == 1) {
usePos2 = true;
}
return true; return true;
} }
@Override @Override
public String toString(@Nullable Event e, boolean arg1) { public String toString(@Nullable Event e, boolean arg1) {
return "the WorldEdit point 2 selection of " + player.toString(e, false); return "the WorldEdit point " + (usePos2 ? "2" : "1") + " selection of " + player.toString(e, false);
} }
@Override @Override
@ -62,10 +66,15 @@ public class ExprSelectionPos2 extends SimpleExpression<Location> {
if (!(region instanceof CuboidRegion)) if (!(region instanceof CuboidRegion))
return null; //Who uses polygonal and other selection types anyways? return null; //Who uses polygonal and other selection types anyways?
CuboidRegion cuboid = (CuboidRegion) region; CuboidRegion cuboid = (CuboidRegion) region;
Vector pos = cuboid.getPos2(); Vector pos = null;
if (usePos2 == true) {
pos = cuboid.getPos2();
} else {
pos = cuboid.getPos1();
}
return new Location[] { BukkitUtil.toLocation(we.getSelection(p).getWorld(), pos) }; return new Location[] { BukkitUtil.toLocation(we.getSelection(p).getWorld(), pos) };
} }
@Override @Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
Player p = player.getSingle(e); Player p = player.getSingle(e);
@ -81,10 +90,14 @@ public class ExprSelectionPos2 extends SimpleExpression<Location> {
if (!(region instanceof CuboidRegion)) if (!(region instanceof CuboidRegion))
return; //Who uses polygonal and other selection types anyways? return; //Who uses polygonal and other selection types anyways?
CuboidRegion cuboid = (CuboidRegion) region; CuboidRegion cuboid = (CuboidRegion) region;
cuboid.setPos2(BukkitUtil.toVector(newLoc)); if (usePos2 == true) {
cuboid.setPos2(BukkitUtil.toVector(newLoc));
} else {
cuboid.setPos1(BukkitUtil.toVector(newLoc));
}
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
@Nullable @Nullable

View File

@ -1,97 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.world.World;
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;
public class ExprSelectionPos1 extends SimpleExpression<Location> {
private Expression<Player> player;
private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
@Override
public Class<? extends Location> getReturnType() {
return Location.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
player = (Expression<Player>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the WorldEdit point 1 selection of " + player.toString(e, false);
}
@Override
@Nullable
protected Location[] get(Event e) {
Player p = player.getSingle(e);
Region region = null;
try {
region = we.getSession(p).getSelection((World) BukkitUtil.getLocalWorld(we.getSelection(p).getWorld()));
} catch (IncompleteRegionException ex) {
return null;
}
if (!(region instanceof CuboidRegion))
return null; //Who uses polygonal and other selection types anyways?
CuboidRegion cuboid = (CuboidRegion) region;
Vector pos = cuboid.getPos1();
return new Location[] { BukkitUtil.toLocation(we.getSelection(p).getWorld(), pos) };
}
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
Player p = player.getSingle(e);
Location newLoc = (Location) delta[0];
if (mode == ChangeMode.SET) {
Region region = null;
try {
region = we.getSession(p).getSelection((World) BukkitUtil.getLocalWorld(we.getSelection(p).getWorld()));
} catch (IncompleteRegionException | NullPointerException ex) {
CuboidRegionSelector cuboidregion = new CuboidRegionSelector(BukkitUtil.getLocalWorld((org.bukkit.World) newLoc.getWorld()), BukkitUtil.toVector(newLoc), BukkitUtil.toVector(newLoc));
we.getSession(p).setRegionSelector((World) BukkitUtil.getLocalWorld(p.getWorld()), cuboidregion);
}
if (!(region instanceof CuboidRegion))
return; //Who uses polygonal and other selection types anyways?
CuboidRegion cuboid = (CuboidRegion) region;
cuboid.setPos1(BukkitUtil.toVector(newLoc));
}
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.SET) {
return CollectionUtils.array(Location.class);
}
return null;
}
}

View File

@ -0,0 +1,182 @@
package me.TheBukor.SkStuff.expressions;
import javax.annotation.Nullable;
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 me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprTagOf extends SimpleExpression<Object> {
private Expression<String> string;
private Expression<Object> compound;
private Class<?> nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound");
private Class<?> nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase");
@Override
public Class<? extends Object> getReturnType() {
return Object.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
string = (Expression<String>) expr[0];
compound = (Expression<Object>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the tag " + string.toString(e, false) + " of compound";
}
@Override
@Nullable
protected Object[] get(Event e) {
Object NBT = compound.getSingle(e);
if (NBT == null || NBT.toString().equals("{}")) return null; //The NBT can be empty/inexistant for items ("{}" is an empty compound).
String stringTag = string.getSingle(e);
Object tag = null;
try {
tag = NBT.getClass().getMethod("get", String.class).invoke(NBT, stringTag);
} catch (Exception ex) {
ex.printStackTrace();
}
if (tag == null)
return null; //The tag doesn't exist? Return <none>.
Byte id = null;
try {
id = (Byte) tag.getClass().getMethod("getTypeId").invoke(tag);
} catch (Exception ex) {
ex.printStackTrace();
}
try {
switch (id) {
case 1:
return new Byte[] { Byte.valueOf(NBT.getClass().getMethod("getByte", String.class).invoke(NBT, stringTag).toString()) };
case 2:
return new Short[] { Short.valueOf(NBT.getClass().getMethod("getShort", String.class).invoke(NBT, stringTag).toString()) };
case 3:
return new Integer[] { Integer.valueOf(NBT.getClass().getMethod("getInt", String.class).invoke(NBT, stringTag).toString()) };
case 4:
return new Long[] { Long.valueOf(NBT.getClass().getMethod("getLong", String.class).invoke(NBT, stringTag).toString()) };
case 5:
return new Float[] { Float.valueOf(NBT.getClass().getMethod("getFloat", String.class).invoke(NBT, stringTag).toString()) };
case 6:
return new Double[] { Double.valueOf(NBT.getClass().getMethod("getDouble", String.class).invoke(NBT, stringTag).toString()) };
case 7: //Byte array, only used in chunk files. Also doesn't have support for the MojangsonParser.
break;
case 8:
return new String[] { NBT.getClass().getMethod("getString", String.class).invoke(NBT, stringTag).toString() };
//Lists will be probably an ASS to implement when I get to them
case 9:
int i;
Object list = null;
for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside,
//since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list.
list = NBT.getClass().getMethod("getList", String.class, int.class).invoke(NBT, stringTag, i);
if (!list.toString().equals("[]")) { //If list is not empty.
break; //Stop loop.
}
}
String methodName = null;
switch (((int) list.getClass().getMethod("f").invoke(list))) { //list.f() gets the type of the tags in the list.
case 5: //Float
methodName = "e";
break;
case 6: //Double
methodName = "d";
break;
case 8: //String
methodName = "getString";
break;
case 10: //Compound
methodName = "get";
break;
case 11: //Integer array
methodName = "c";
break;
default:
break;
}
int listSize = (int) list.getClass().getMethod("size").invoke(list);
Object[] tags = new Object[listSize];
for (i = 0; i < listSize; i++) {
Object gottenTag = list.getClass().getMethod(methodName, int.class).invoke(list, i);
tags[i] = gottenTag;
}
return tags;
case 10:
return new Object[] { NBT.getClass().getMethod("getCompound", String.class).invoke(NBT, stringTag) };
case 11: //Integer array, this one is only used on the chunk files.
return new Object[] { NBT.getClass().getMethod("getIntArray", String.class).invoke(NBT, stringTag).toString() };
default: //This shouldn't happen, but it's better to have this just in case it spills errors everywhere.
break;
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
Object NBT = compound.getSingle(e);
if (NBT == null)
try {
NBT = nbtClass.newInstance(); //If the NBT isn't set, create an empty one
} catch (Exception ex) {
ex.printStackTrace();
}
String stringTag = string.getSingle(e);
if (mode == ChangeMode.SET) {
Object newValue = delta[0];
try {
if (newValue instanceof Byte) {
NBT.getClass().getMethod("setByte", String.class, byte.class).invoke(NBT, stringTag, (byte) newValue);
} else if (newValue instanceof Short) {
NBT.getClass().getMethod("setShort", String.class, short.class).invoke(NBT, stringTag, (short) newValue);
} else if (newValue instanceof Integer) {
NBT.getClass().getMethod("setInt", String.class, int.class).invoke(NBT, stringTag, (int) newValue);
} else if (newValue instanceof Long) {
NBT.getClass().getMethod("setLong", String.class, long.class).invoke(NBT, stringTag, (long) newValue);
} else if (newValue instanceof Float) {
NBT.getClass().getMethod("setFloat", String.class, float.class).invoke(NBT, stringTag, (float) newValue);
} else if (newValue instanceof Double) {
NBT.getClass().getMethod("setDouble", String.class, double.class).invoke(NBT, stringTag, (double) newValue);
} else if (newValue instanceof String) {
NBT.getClass().getMethod("setString", String.class, String.class).invoke(NBT, stringTag, (String) newValue);
} else {
return; //Something else like a list or entire compound.
}
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (mode == ChangeMode.RESET || mode == ChangeMode.DELETE) {
try {
NBT.getClass().getMethod("set", String.class, nbtBaseClass).invoke(NBT, stringTag, nbtBaseClass.newInstance());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
return CollectionUtils.array(Object.class);
}
return null;
}
}

View File

@ -1,167 +0,0 @@
package me.TheBukor.SkStuff.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;
public class ExprTagOfv1_7_R1 extends SimpleExpression<Object> {
private Expression<String> string;
private Expression<NBTTagCompound> compound;
private Object[] returned;
@Override
public Class<? extends Object> getReturnType() {
return Object.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
string = (Expression<String>) expr[0];
compound = (Expression<NBTTagCompound>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the tag " + string.toString(e, false) + " of compound";
}
@Override
@Nullable
protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(e);
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 <none>.
Byte id = NBT.get(tag).getTypeId();
switch (id) {
case 1:
returned = new Byte[] { NBT.getByte(tag) };
break;
case 2:
returned = new Short[] { NBT.getShort(tag) };
break;
case 3:
returned = new Integer[] { NBT.getInt(tag) };
break;
case 4:
returned = new Long[] { NBT.getLong(tag) };
break;
case 5:
returned = new Float[] { NBT.getFloat(tag) };
break;
case 6:
returned = new Double[] { NBT.getDouble(tag) };
break;
case 7: //Byte array, never seen this kind of tag (where is it used?)
break;
case 8:
returned = new String[] { NBT.getString(tag) };
break;
case 9: //List, will need to make a new type if getCompound() doesn't work here
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) };
break;
case 11: //Integer array, this one is only used on the chunk files I believe
break;
default:
break;
}
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

@ -1,167 +0,0 @@
package me.TheBukor.SkStuff.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;
public class ExprTagOfv1_7_R2 extends SimpleExpression<Object> {
private Expression<String> string;
private Expression<NBTTagCompound> compound;
private Object[] returned;
@Override
public Class<? extends Object> getReturnType() {
return Object.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
string = (Expression<String>) expr[0];
compound = (Expression<NBTTagCompound>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the tag " + string.toString(e, false) + " of compound";
}
@Override
@Nullable
protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(e);
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 <none>.
Byte id = NBT.get(tag).getTypeId();
switch (id) {
case 1:
returned = new Byte[] { NBT.getByte(tag) };
break;
case 2:
returned = new Short[] { NBT.getShort(tag) };
break;
case 3:
returned = new Integer[] { NBT.getInt(tag) };
break;
case 4:
returned = new Long[] { NBT.getLong(tag) };
break;
case 5:
returned = new Float[] { NBT.getFloat(tag) };
break;
case 6:
returned = new Double[] { NBT.getDouble(tag) };
break;
case 7: //Byte array, never seen this kind of tag (where is it used?)
break;
case 8:
returned = new String[] { NBT.getString(tag) };
break;
case 9: //List, will need to make a new type if getCompound() doesn't work here
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) };
break;
case 11: //Integer array, this one is only used on the chunk files I believe
break;
default:
break;
}
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

@ -1,167 +0,0 @@
package me.TheBukor.SkStuff.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;
public class ExprTagOfv1_7_R3 extends SimpleExpression<Object> {
private Expression<String> string;
private Expression<NBTTagCompound> compound;
private Object[] returned;
@Override
public Class<? extends Object> getReturnType() {
return Object.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
string = (Expression<String>) expr[0];
compound = (Expression<NBTTagCompound>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the tag " + string.toString(e, false) + " of compound";
}
@Override
@Nullable
protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(e);
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 <none>.
Byte id = NBT.get(tag).getTypeId();
switch (id) {
case 1:
returned = new Byte[] { NBT.getByte(tag) };
break;
case 2:
returned = new Short[] { NBT.getShort(tag) };
break;
case 3:
returned = new Integer[] { NBT.getInt(tag) };
break;
case 4:
returned = new Long[] { NBT.getLong(tag) };
break;
case 5:
returned = new Float[] { NBT.getFloat(tag) };
break;
case 6:
returned = new Double[] { NBT.getDouble(tag) };
break;
case 7: //Byte array, never seen this kind of tag (where is it used?)
break;
case 8:
returned = new String[] { NBT.getString(tag) };
break;
case 9: //List, will need to make a new type if getCompound() doesn't work here
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) };
break;
case 11: //Integer array, this one is only used on the chunk files I believe
break;
default:
break;
}
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

@ -1,167 +0,0 @@
package me.TheBukor.SkStuff.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;
public class ExprTagOfv1_7_R4 extends SimpleExpression<Object> {
private Expression<String> string;
private Expression<NBTTagCompound> compound;
private Object[] returned;
@Override
public Class<? extends Object> getReturnType() {
return Object.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
string = (Expression<String>) expr[0];
compound = (Expression<NBTTagCompound>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the tag " + string.toString(e, false) + " of compound";
}
@Override
@Nullable
protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(e);
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 <none>.
Byte id = NBT.get(tag).getTypeId();
switch (id) {
case 1:
returned = new Byte[] { NBT.getByte(tag) };
break;
case 2:
returned = new Short[] { NBT.getShort(tag) };
break;
case 3:
returned = new Integer[] { NBT.getInt(tag) };
break;
case 4:
returned = new Long[] { NBT.getLong(tag) };
break;
case 5:
returned = new Float[] { NBT.getFloat(tag) };
break;
case 6:
returned = new Double[] { NBT.getDouble(tag) };
break;
case 7: //Byte array, never seen this kind of tag (where is it used?)
break;
case 8:
returned = new String[] { NBT.getString(tag) };
break;
case 9: //List, will need to make a new type if getCompound() doesn't work here
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) };
break;
case 11: //Integer array, this one is only used on the chunk files I believe
break;
default:
break;
}
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

@ -1,167 +0,0 @@
package me.TheBukor.SkStuff.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;
public class ExprTagOfv1_8_R1 extends SimpleExpression<Object> {
private Expression<String> string;
private Expression<NBTTagCompound> compound;
private Object[] returned;
@Override
public Class<? extends Object> getReturnType() {
return Object.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
string = (Expression<String>) expr[0];
compound = (Expression<NBTTagCompound>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the tag " + string.toString(e, false) + " of compound";
}
@Override
@Nullable
protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(e);
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 <none>.
Byte id = NBT.get(tag).getTypeId();
switch (id) {
case 1:
returned = new Byte[] { NBT.getByte(tag) };
break;
case 2:
returned = new Short[] { NBT.getShort(tag) };
break;
case 3:
returned = new Integer[] { NBT.getInt(tag) };
break;
case 4:
returned = new Long[] { NBT.getLong(tag) };
break;
case 5:
returned = new Float[] { NBT.getFloat(tag) };
break;
case 6:
returned = new Double[] { NBT.getDouble(tag) };
break;
case 7: //Byte array, never seen this kind of tag (where is it used?)
break;
case 8:
returned = new String[] { NBT.getString(tag) };
break;
case 9: //List, will need to make a new type if getCompound() doesn't work here
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) };
break;
case 11: //Integer array, this one is only used on the chunk files I believe
break;
default:
break;
}
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

@ -1,167 +0,0 @@
package me.TheBukor.SkStuff.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;
public class ExprTagOfv1_8_R2 extends SimpleExpression<Object> {
private Expression<String> string;
private Expression<NBTTagCompound> compound;
private Object[] returned;
@Override
public Class<? extends Object> getReturnType() {
return Object.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
string = (Expression<String>) expr[0];
compound = (Expression<NBTTagCompound>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the tag " + string.toString(e, false) + " of compound";
}
@Override
@Nullable
protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(e);
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 <none>.
Byte id = NBT.get(tag).getTypeId();
switch (id) {
case 1:
returned = new Byte[] { NBT.getByte(tag) };
break;
case 2:
returned = new Short[] { NBT.getShort(tag) };
break;
case 3:
returned = new Integer[] { NBT.getInt(tag) };
break;
case 4:
returned = new Long[] { NBT.getLong(tag) };
break;
case 5:
returned = new Float[] { NBT.getFloat(tag) };
break;
case 6:
returned = new Double[] { NBT.getDouble(tag) };
break;
case 7: //Byte array, never seen this kind of tag (where is it used?)
break;
case 8:
returned = new String[] { NBT.getString(tag) };
break;
case 9: //List, will need to make a new type if getCompound() doesn't work here
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) };
break;
case 11: //Integer array, this one is only used on the chunk files I believe
break;
default:
break;
}
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

@ -1,167 +0,0 @@
package me.TheBukor.SkStuff.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_R3.NBTTagCompound;
public class ExprTagOfv1_8_R3 extends SimpleExpression<Object> {
private Expression<String> string;
private Expression<NBTTagCompound> compound;
private Object[] returned;
@Override
public Class<? extends Object> getReturnType() {
return Object.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int arg1, Kleenean arg2, ParseResult arg3) {
string = (Expression<String>) expr[0];
compound = (Expression<NBTTagCompound>) expr[1];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the tag " + string.toString(e, false) + " of compound";
}
@Override
@Nullable
protected Object[] get(Event e) {
NBTTagCompound NBT = compound.getSingle(e);
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 <none>.
Byte id = NBT.get(tag).getTypeId();
switch (id) {
case 1:
returned = new Byte[] { NBT.getByte(tag) };
break;
case 2:
returned = new Short[] { NBT.getShort(tag) };
break;
case 3:
returned = new Integer[] { NBT.getInt(tag) };
break;
case 4:
returned = new Long[] { NBT.getLong(tag) };
break;
case 5:
returned = new Float[] { NBT.getFloat(tag) };
break;
case 6:
returned = new Double[] { NBT.getDouble(tag) };
break;
case 7: //Byte array, never seen this kind of tag (where is it used?)
break;
case 8:
returned = new String[] { NBT.getString(tag) };
break;
case 9: //List, will need to make a new type if getCompound() doesn't work here
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) };
break;
case 11: //Integer array, this one is only used on the chunk files I believe
break;
default:
break;
}
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

@ -1,51 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.Selection;
import javax.annotation.Nullable;
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;
public class ExprVolumeOfSelection extends SimpleExpression<Integer> {
private Expression<Player> player;
@Override
public Class<? extends Integer> getReturnType() {
return Integer.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
player = (Expression<Player>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the width of the WorldEdit selection of " + player.toString(e, false);
}
@Override
@Nullable
protected Integer[] get(Event e) {
WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
Selection sel = we.getSelection(player.getSingle(e));
if (sel == null)
return null;
return new Integer[] { sel.getArea() };
}
}

View File

@ -1,51 +0,0 @@
package me.TheBukor.SkStuff.expressions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.Selection;
import javax.annotation.Nullable;
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;
public class ExprWidthOfSelection extends SimpleExpression<Integer> {
private Expression<Player> player;
@Override
public Class<? extends Integer> getReturnType() {
return Integer.class;
}
@Override
public boolean isSingle() {
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
player = (Expression<Player>) expr[0];
return true;
}
@Override
public String toString(@Nullable Event e, boolean arg1) {
return "the width of the WorldEdit selection of " + player.toString(e, false);
}
@Override
@Nullable
protected Integer[] get(Event e) {
WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
Selection sel = we.getSelection(player.getSingle(e));
if (sel == null)
return null;
return new Integer[] { sel.getWidth() };
}
}

View File

@ -0,0 +1,36 @@
package me.TheBukor.SkStuff.util;
import org.bukkit.Bukkit;
public class ReflectionUtils {
public static Class<?> getNMSClass(String classString) {
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + ".";
String name = "net.minecraft.server." + version + classString;
Class<?> nmsClass = null;
try {
nmsClass = Class.forName(name);
} catch (ClassNotFoundException ex) {
Bukkit.getLogger().warning("Unable to get NMS class! You are probably running an unsupported version");
return null;
}
return nmsClass;
}
public static Class<?> getOBCClass(String classString) {
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + ".";
String name = "org.bukkit.craftbukkit." + version + classString;
Class<?> obcClass = null;
try {
obcClass = Class.forName(name);
} catch (ClassNotFoundException ex) {
Bukkit.getLogger().warning("Unable to get OBC class! You are probably running an unsupported version");
return null;
}
return obcClass;
}
public static String getVersion() {
return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + ".";
}
}