Added NBT support to 1.7 (most likely broken)

This commit is contained in:
Richard 2015-12-05 02:24:33 -02:00
parent dd5d7ea91a
commit 700cfe2c38
17 changed files with 1530 additions and 6 deletions

View File

@ -7,5 +7,9 @@
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.3.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.3.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.8.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/plugins/WorldEdit.jar"/> <classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/Server - Survival - 1.8/plugins/WorldEdit.jar"/>
<classpathentry kind="lib" path="C:/Users/Rubi/AppData/Roaming/.minecraft/workspace/Spigot 1.8, 1.8.3/1.7.10.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.2.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

1
bin/.gitignore vendored
View File

@ -1,2 +1 @@
/me/ /me/
/org/

View File

@ -27,11 +27,19 @@ import me.TheBukor.expressions.ExprFileNBTv1_8_R2;
import me.TheBukor.expressions.ExprFileNBTv1_8_R3; import me.TheBukor.expressions.ExprFileNBTv1_8_R3;
import me.TheBukor.expressions.ExprHeightOfSchematic; import me.TheBukor.expressions.ExprHeightOfSchematic;
import me.TheBukor.expressions.ExprHeightOfSelection; import me.TheBukor.expressions.ExprHeightOfSelection;
import me.TheBukor.expressions.ExprItemNBTv1_7_R1;
import me.TheBukor.expressions.ExprItemNBTv1_7_R2;
import me.TheBukor.expressions.ExprItemNBTv1_7_R3;
import me.TheBukor.expressions.ExprItemNBTv1_7_R4;
import me.TheBukor.expressions.ExprItemNBTv1_8_R1; import me.TheBukor.expressions.ExprItemNBTv1_8_R1;
import me.TheBukor.expressions.ExprItemNBTv1_8_R2; import me.TheBukor.expressions.ExprItemNBTv1_8_R2;
import me.TheBukor.expressions.ExprItemNBTv1_8_R3; import me.TheBukor.expressions.ExprItemNBTv1_8_R3;
import me.TheBukor.expressions.ExprLengthOfSchematic; import me.TheBukor.expressions.ExprLengthOfSchematic;
import me.TheBukor.expressions.ExprLengthOfSelection; import me.TheBukor.expressions.ExprLengthOfSelection;
import me.TheBukor.expressions.ExprNBTv1_7_R1;
import me.TheBukor.expressions.ExprNBTv1_7_R2;
import me.TheBukor.expressions.ExprNBTv1_7_R3;
import me.TheBukor.expressions.ExprNBTv1_7_R4;
import me.TheBukor.expressions.ExprNBTv1_8_R1; import me.TheBukor.expressions.ExprNBTv1_8_R1;
import me.TheBukor.expressions.ExprNBTv1_8_R2; import me.TheBukor.expressions.ExprNBTv1_8_R2;
import me.TheBukor.expressions.ExprNBTv1_8_R3; import me.TheBukor.expressions.ExprNBTv1_8_R3;
@ -39,6 +47,10 @@ import me.TheBukor.expressions.ExprNewEditSession;
import me.TheBukor.expressions.ExprSelectionOfPlayer; import me.TheBukor.expressions.ExprSelectionOfPlayer;
import me.TheBukor.expressions.ExprSelectionPos1; import me.TheBukor.expressions.ExprSelectionPos1;
import me.TheBukor.expressions.ExprSelectionPos2; import me.TheBukor.expressions.ExprSelectionPos2;
import me.TheBukor.expressions.ExprTagOfv1_7_R1;
import me.TheBukor.expressions.ExprTagOfv1_7_R2;
import me.TheBukor.expressions.ExprTagOfv1_7_R3;
import me.TheBukor.expressions.ExprTagOfv1_7_R4;
import me.TheBukor.expressions.ExprTagOfv1_8_R1; import me.TheBukor.expressions.ExprTagOfv1_8_R1;
import me.TheBukor.expressions.ExprTagOfv1_8_R2; import me.TheBukor.expressions.ExprTagOfv1_8_R2;
import me.TheBukor.expressions.ExprTagOfv1_8_R3; import me.TheBukor.expressions.ExprTagOfv1_8_R3;
@ -59,6 +71,159 @@ public class SkStuff extends JavaPlugin {
if (Bukkit.getPluginManager().getPlugin("Skript") != null) { if (Bukkit.getPluginManager().getPlugin("Skript") != null) {
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("Successfully found 1.7.2! Registering version specific expressions...");
exprAmount += 3;
typeAmount += 1;
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(ExprItemNBTv1_7_R1.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%");
Skript.registerExpression(ExprTagOfv1_7_R1.class, Object.class, ExpressionType.SIMPLE, "[nbt[ ]]tag %string% of [nbt [compound]] %compound%");
//WARNING! HIGHLY EXPERIMENTAL, IT CAN CORRUPT WORLDS AT CURRENT VERSION, USE AT YOUR OWN RISK!
//Skript.registerExpression(ExprFileNBTv1_7_R1.class, net.minecraft.server.v1_7_R1.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%");
Classes.registerClass(new ClassInfo<net.minecraft.server.v1_7_R1.NBTTagCompound>(net.minecraft.server.v1_7_R1.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_7_R1.NBTTagCompound>() {
@Override
public String getVariableNamePattern() {
return ".+";
}
@Override
@Nullable
public net.minecraft.server.v1_7_R1.NBTTagCompound parse(String s, ParseContext context) {
net.minecraft.server.v1_7_R1.NBTTagCompound NBT = new net.minecraft.server.v1_7_R1.NBTTagCompound();
net.minecraft.server.v1_7_R1.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R1.NBTTagCompound) net.minecraft.server.v1_7_R1.MojangsonParser.a(s);
NBT.set("", NBT1);
if (NBT.isEmpty() || NBT == null) {
return null;
}
return NBT;
}
@Override
public String toString(net.minecraft.server.v1_7_R1.NBTTagCompound compound, int arg1) {
return compound.toString();
}
@Override
public String toVariableNameString(net.minecraft.server.v1_7_R1.NBTTagCompound compound) {
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]] of [file] %string%");
Classes.registerClass(new ClassInfo<net.minecraft.server.v1_7_R2.NBTTagCompound>(net.minecraft.server.v1_7_R2.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_7_R2.NBTTagCompound>() {
@Override
public String getVariableNamePattern() {
return ".+";
}
@Override
@Nullable
public net.minecraft.server.v1_7_R2.NBTTagCompound parse(String s, ParseContext context) {
net.minecraft.server.v1_7_R2.NBTTagCompound NBT = new net.minecraft.server.v1_7_R2.NBTTagCompound();
net.minecraft.server.v1_7_R2.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R2.NBTTagCompound) net.minecraft.server.v1_7_R2.MojangsonParser.parse(s);
NBT.set("", NBT1);
if (NBT.isEmpty() || NBT == null) {
return null;
}
return NBT;
}
@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 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]] of [file] %string%");
Classes.registerClass(new ClassInfo<net.minecraft.server.v1_7_R3.NBTTagCompound>(net.minecraft.server.v1_7_R3.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_7_R3.NBTTagCompound>() {
@Override
public String getVariableNamePattern() {
return ".+";
}
@Override
@Nullable
public net.minecraft.server.v1_7_R3.NBTTagCompound parse(String s, ParseContext context) {
net.minecraft.server.v1_7_R3.NBTTagCompound NBT = new net.minecraft.server.v1_7_R3.NBTTagCompound();
net.minecraft.server.v1_7_R3.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R3.NBTTagCompound) net.minecraft.server.v1_7_R3.MojangsonParser.parse(s);
NBT.set("", NBT1);
if (NBT.isEmpty() || NBT == null) {
return null;
}
return NBT;
}
@Override
public String toString(net.minecraft.server.v1_7_R3.NBTTagCompound compound, int arg1) {
return compound.toString();
}
@Override
public String toVariableNameString(net.minecraft.server.v1_7_R3.NBTTagCompound compound) {
return 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]] of [file] %string%");
Classes.registerClass(new ClassInfo<net.minecraft.server.v1_7_R4.NBTTagCompound>(net.minecraft.server.v1_7_R4.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser<net.minecraft.server.v1_7_R4.NBTTagCompound>() {
@Override
public String getVariableNamePattern() {
return ".+";
}
@Override
@Nullable
public net.minecraft.server.v1_7_R4.NBTTagCompound parse(String s, ParseContext context) {
net.minecraft.server.v1_7_R4.NBTTagCompound NBT = new net.minecraft.server.v1_7_R4.NBTTagCompound();
net.minecraft.server.v1_7_R4.NBTTagCompound NBT1 = (net.minecraft.server.v1_7_R4.NBTTagCompound) net.minecraft.server.v1_7_R4.MojangsonParser.parse(s);
NBT.set("", NBT1);
if (NBT.isEmpty() || NBT == null) {
return null;
}
return NBT;
}
@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 compound.toString();
}
}));
}
if (Bukkit.getVersion().contains("(MC: 1.8)")) { if (Bukkit.getVersion().contains("(MC: 1.8)")) {
getLogger().info("Successfully found 1.8! Registering version specific expressions..."); getLogger().info("Successfully found 1.8! Registering version specific expressions...");
exprAmount += 4; exprAmount += 4;
@ -80,7 +245,7 @@ public class SkStuff extends JavaPlugin {
public NBTTagCompound parse(String s, ParseContext context) { public NBTTagCompound parse(String s, ParseContext context) {
NBTTagCompound NBT = new NBTTagCompound(); NBTTagCompound NBT = new NBTTagCompound();
NBTTagCompound NBT1 = MojangsonParser.parse(s); NBTTagCompound NBT1 = MojangsonParser.parse(s);
NBT1.a(NBT); NBT.a(NBT1);
if (NBT.isEmpty() || NBT == null) { if (NBT.isEmpty() || NBT == null) {
return null; return null;
} }

View File

@ -34,8 +34,8 @@ public class CondSelectionContains extends Condition {
} }
@Override @Override
public boolean check(Event e) { public boolean check(final Event e) {
WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); final WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
if (we.getSelection(player.getSingle(e)) == null) { if (we.getSelection(player.getSingle(e)) == null) {
return false; return false;
} }

View File

@ -11,6 +11,7 @@ import java.util.zip.ZipException;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import ch.njol.skript.Skript; import ch.njol.skript.Skript;
@ -85,6 +86,7 @@ public class ExprFileNBTv1_8_R3 extends SimpleExpression<NBTTagCompound> {
NBTTagCompound NBT1 = MojangsonParser.parse(tags); NBTTagCompound NBT1 = MojangsonParser.parse(tags);
NBT.a(NBT1); NBT.a(NBT1);
NBTCompressedStreamTools.a(NBT, os); NBTCompressedStreamTools.a(NBT, os);
Bukkit.broadcastMessage("First - " + NBT.toString() + "\n\nSecond: " + NBT1.toString());
fis.close(); fis.close();
os.close(); os.close();
} catch (EOFException ex) { } catch (EOFException ex) {
@ -100,9 +102,11 @@ public class ExprFileNBTv1_8_R3 extends SimpleExpression<NBTTagCompound> {
try { try {
InputStream fis = new FileInputStream(file); InputStream fis = new FileInputStream(file);
NBTTagCompound NBT = NBTCompressedStreamTools.a(fis); NBTTagCompound NBT = NBTCompressedStreamTools.a(fis);
Bukkit.broadcastMessage("First - " + NBT.toString());
OutputStream os = new FileOutputStream(file); OutputStream os = new FileOutputStream(file);
NBT.remove(tags); NBT.remove(tags);
NBTCompressedStreamTools.a(NBT, os); NBTCompressedStreamTools.a(NBT, os);
Bukkit.broadcastMessage("\n\nSecond: " + NBT.toString());
fis.close(); fis.close();
os.close(); os.close();
} catch (EOFException ex) { } catch (EOFException ex) {

View File

@ -0,0 +1,61 @@
package me.TheBukor.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

@ -0,0 +1,61 @@
package me.TheBukor.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

@ -0,0 +1,61 @@
package me.TheBukor.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

@ -0,0 +1,61 @@
package me.TheBukor.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

@ -0,0 +1,194 @@
package me.TheBukor.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

@ -0,0 +1,194 @@
package me.TheBukor.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

@ -0,0 +1,194 @@
package me.TheBukor.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

@ -0,0 +1,194 @@
package me.TheBukor.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

@ -0,0 +1,83 @@
package me.TheBukor.expressions;
import javax.annotation.Nullable;
import org.bukkit.event.Event;
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.NBTTagCompound;
import net.minecraft.server.v1_7_R1.NBTTagList;
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.isEmpty() || NBT == null) 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
returned = new NBTTagList[] { NBT.getList(tag, 5) }; //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;
}
}

View File

@ -0,0 +1,83 @@
package me.TheBukor.expressions;
import javax.annotation.Nullable;
import org.bukkit.event.Event;
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.NBTTagCompound;
import net.minecraft.server.v1_7_R2.NBTTagList;
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.isEmpty() || NBT == null) 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
returned = new NBTTagList[] { NBT.getList(tag, 5) }; //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;
}
}

View File

@ -0,0 +1,83 @@
package me.TheBukor.expressions;
import javax.annotation.Nullable;
import org.bukkit.event.Event;
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.NBTTagCompound;
import net.minecraft.server.v1_7_R3.NBTTagList;
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.isEmpty() || NBT == null) 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
returned = new NBTTagList[] { NBT.getList(tag, 5) }; //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;
}
}

View File

@ -0,0 +1,83 @@
package me.TheBukor.expressions;
import javax.annotation.Nullable;
import org.bukkit.event.Event;
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.NBTTagCompound;
import net.minecraft.server.v1_7_R4.NBTTagList;
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.isEmpty() || NBT == null) 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
returned = new NBTTagList[] { NBT.getList(tag, 5) }; //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;
}
}