diff --git a/bin/.gitignore b/bin/.gitignore index 4060509..24cb195 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1 +1,2 @@ /me/ +/org/ diff --git a/src/me/TheBukor/SkStuff.java b/src/me/TheBukor/SkStuff.java index a4d837a..7c8b4f9 100644 --- a/src/me/TheBukor/SkStuff.java +++ b/src/me/TheBukor/SkStuff.java @@ -21,6 +21,9 @@ import me.TheBukor.effects.EffUndoRedoSession; import me.TheBukor.expressions.ExprAreaOfSelection; import me.TheBukor.expressions.ExprChangedBlocksSession; import me.TheBukor.expressions.ExprEditSessionLimit; +import me.TheBukor.expressions.ExprFileNBTv1_8_R1; +import me.TheBukor.expressions.ExprFileNBTv1_8_R2; +import me.TheBukor.expressions.ExprFileNBTv1_8_R3; import me.TheBukor.expressions.ExprHeightOfSchematic; import me.TheBukor.expressions.ExprHeightOfSelection; import me.TheBukor.expressions.ExprItemNBTv1_8_R1; @@ -62,6 +65,7 @@ public class SkStuff extends JavaPlugin { 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%"); + Skript.registerExpression(ExprFileNBTv1_8_R1.class, NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%"); Classes.registerClass(new ClassInfo(NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { @Override @@ -99,6 +103,7 @@ public class SkStuff extends JavaPlugin { 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%"); + Skript.registerExpression(ExprFileNBTv1_8_R2.class, net.minecraft.server.v1_8_R2.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%"); Classes.registerClass(new ClassInfo(net.minecraft.server.v1_8_R2.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { @Override @@ -140,6 +145,7 @@ public class SkStuff extends JavaPlugin { 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%"); + Skript.registerExpression(ExprFileNBTv1_8_R3.class, net.minecraft.server.v1_8_R3.NBTTagCompound.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of [file] %string%"); Classes.registerClass(new ClassInfo(net.minecraft.server.v1_8_R3.NBTTagCompound.class, "compound").name("NBT Compound").parser(new Parser() { @Override @@ -196,10 +202,10 @@ public class SkStuff extends JavaPlugin { 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] %string% [from [folder] %-string%]"); - Skript.registerExpression(ExprWidthOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(x( |-)size|width) of schem[atic] %string% [from [folder] %-string%]"); - Skript.registerExpression(ExprHeightOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(y( |-)size|height) of schem[atic] %string% [from [folder] %-string%]"); - Skript.registerExpression(ExprLengthOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(z( |-)size|length) of schem[atic] %string% [from [folder] %-string%]"); + Skript.registerExpression(ExprVolumeOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "volume of schem[atic] %string%"); + Skript.registerExpression(ExprWidthOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(x( |-)size|width) of schem[atic] %string%"); + Skript.registerExpression(ExprHeightOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(y( |-)size|height) of schem[atic] %string%"); + Skript.registerExpression(ExprLengthOfSchematic.class, Integer.class, ExpressionType.SIMPLE, "(z( |-)size|length) of schem[atic] %string%"); Classes.registerClass(new ClassInfo(EditSession.class, "editsession").name("Edit Session").parser(new Parser() { @Override diff --git a/src/me/TheBukor/expressions/ExprFileNBTv1_8_R1.java b/src/me/TheBukor/expressions/ExprFileNBTv1_8_R1.java new file mode 100644 index 0000000..967613e --- /dev/null +++ b/src/me/TheBukor/expressions/ExprFileNBTv1_8_R1.java @@ -0,0 +1,123 @@ +package me.TheBukor.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 { + private Expression input; + + @Override + public Class 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) 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; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprFileNBTv1_8_R2.java b/src/me/TheBukor/expressions/ExprFileNBTv1_8_R2.java new file mode 100644 index 0000000..6e36685 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprFileNBTv1_8_R2.java @@ -0,0 +1,127 @@ +package me.TheBukor.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 { + private Expression input; + + @Override + public Class 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) 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; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprFileNBTv1_8_R3.java b/src/me/TheBukor/expressions/ExprFileNBTv1_8_R3.java new file mode 100644 index 0000000..4318e03 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprFileNBTv1_8_R3.java @@ -0,0 +1,127 @@ +package me.TheBukor.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_R3.MojangsonParseException; +import net.minecraft.server.v1_8_R3.MojangsonParser; +import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools; +import net.minecraft.server.v1_8_R3.NBTTagCompound; + +public class ExprFileNBTv1_8_R3 extends SimpleExpression { + private Expression input; + + @Override + public Class 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) 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; + } +} \ No newline at end of file