From 382e8be72e64e2e5fef164a0851831bf91c9b2d9 Mon Sep 17 00:00:00 2001 From: Richard Date: Sat, 28 Nov 2015 19:49:37 -0200 Subject: [PATCH] First Commit. --- .classpath | 11 + .project | 17 ++ .settings/org.eclipse.jdt.core.prefs | 11 + bin/.gitignore | 1 + plugin.yml | 6 + src/me/TheBukor/SkStuff.java | 211 ++++++++++++++++++ .../conditions/CondSelectionContains.java | 49 ++++ .../expressions/ExprAreaOfSelection.java | 51 +++++ .../expressions/ExprHeightOfSchematic.java | 64 ++++++ .../expressions/ExprHeightOfSelection.java | 51 +++++ .../expressions/ExprItemNBTv1_8_R1.java | 61 +++++ .../expressions/ExprItemNBTv1_8_R2.java | 68 ++++++ .../expressions/ExprItemNBTv1_8_R3.java | 68 ++++++ .../expressions/ExprLengthOfSchematic.java | 64 ++++++ .../expressions/ExprLengthOfSelection.java | 51 +++++ .../TheBukor/expressions/ExprNBTv1_8_R1.java | 197 ++++++++++++++++ .../TheBukor/expressions/ExprNBTv1_8_R2.java | 211 ++++++++++++++++++ .../TheBukor/expressions/ExprNBTv1_8_R3.java | 211 ++++++++++++++++++ .../expressions/ExprSelectionOfPlayer.java | 96 ++++++++ .../expressions/ExprSelectionPos1.java | 65 ++++++ .../expressions/ExprSelectionPos2.java | 65 ++++++ .../expressions/ExprTagOfv1_8_R1.java | 82 +++++++ .../expressions/ExprTagOfv1_8_R2.java | 82 +++++++ .../expressions/ExprTagOfv1_8_R3.java | 82 +++++++ .../expressions/ExprVolumeOfSchematic.java | 76 +++++++ .../expressions/ExprVolumeOfSelection.java | 51 +++++ .../expressions/ExprWidthOfSchematic.java | 64 ++++++ .../expressions/ExprWidthOfSelection.java | 51 +++++ 28 files changed, 2117 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 bin/.gitignore create mode 100644 plugin.yml create mode 100644 src/me/TheBukor/SkStuff.java create mode 100644 src/me/TheBukor/conditions/CondSelectionContains.java create mode 100644 src/me/TheBukor/expressions/ExprAreaOfSelection.java create mode 100644 src/me/TheBukor/expressions/ExprHeightOfSchematic.java create mode 100644 src/me/TheBukor/expressions/ExprHeightOfSelection.java create mode 100644 src/me/TheBukor/expressions/ExprItemNBTv1_8_R1.java create mode 100644 src/me/TheBukor/expressions/ExprItemNBTv1_8_R2.java create mode 100644 src/me/TheBukor/expressions/ExprItemNBTv1_8_R3.java create mode 100644 src/me/TheBukor/expressions/ExprLengthOfSchematic.java create mode 100644 src/me/TheBukor/expressions/ExprLengthOfSelection.java create mode 100644 src/me/TheBukor/expressions/ExprNBTv1_8_R1.java create mode 100644 src/me/TheBukor/expressions/ExprNBTv1_8_R2.java create mode 100644 src/me/TheBukor/expressions/ExprNBTv1_8_R3.java create mode 100644 src/me/TheBukor/expressions/ExprSelectionOfPlayer.java create mode 100644 src/me/TheBukor/expressions/ExprSelectionPos1.java create mode 100644 src/me/TheBukor/expressions/ExprSelectionPos2.java create mode 100644 src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java create mode 100644 src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java create mode 100644 src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java create mode 100644 src/me/TheBukor/expressions/ExprVolumeOfSchematic.java create mode 100644 src/me/TheBukor/expressions/ExprVolumeOfSelection.java create mode 100644 src/me/TheBukor/expressions/ExprWidthOfSchematic.java create mode 100644 src/me/TheBukor/expressions/ExprWidthOfSelection.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e462881 --- /dev/null +++ b/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..119f0a4 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + SkStuff + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bb35fa0 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..4060509 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/me/ diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..fc753db --- /dev/null +++ b/plugin.yml @@ -0,0 +1,6 @@ +name: SkStuff +author: TheBukor +description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support. +version: 1.2.1 +main: me.TheBukor.SkStuff +softdepend: [Skript] \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff.java b/src/me/TheBukor/SkStuff.java new file mode 100644 index 0000000..9a1f9ef --- /dev/null +++ b/src/me/TheBukor/SkStuff.java @@ -0,0 +1,211 @@ +package me.TheBukor; + +import javax.annotation.Nullable; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.ClassInfo; +import ch.njol.skript.classes.Parser; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.ParseContext; +import ch.njol.skript.registrations.Classes; +import me.TheBukor.conditions.CondSelectionContains; +import me.TheBukor.expressions.ExprAreaOfSelection; +import me.TheBukor.expressions.ExprHeightOfSchematic; +import me.TheBukor.expressions.ExprHeightOfSelection; +import me.TheBukor.expressions.ExprItemNBTv1_8_R1; +import me.TheBukor.expressions.ExprItemNBTv1_8_R2; +import me.TheBukor.expressions.ExprItemNBTv1_8_R3; +import me.TheBukor.expressions.ExprLengthOfSchematic; +import me.TheBukor.expressions.ExprLengthOfSelection; +import me.TheBukor.expressions.ExprNBTv1_8_R1; +import me.TheBukor.expressions.ExprNBTv1_8_R2; +import me.TheBukor.expressions.ExprNBTv1_8_R3; +import me.TheBukor.expressions.ExprSelectionOfPlayer; +import me.TheBukor.expressions.ExprSelectionPos1; +import me.TheBukor.expressions.ExprSelectionPos2; +import me.TheBukor.expressions.ExprTagOfv1_8_R1; +import me.TheBukor.expressions.ExprTagOfv1_8_R2; +import me.TheBukor.expressions.ExprTagOfv1_8_R3; +import me.TheBukor.expressions.ExprVolumeOfSchematic; +import me.TheBukor.expressions.ExprVolumeOfSelection; +import me.TheBukor.expressions.ExprWidthOfSchematic; +import me.TheBukor.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 { + private int condAmount = 0; + private int exprAmount = 0; + private int typeAmount = 0; + private int evtAmount = 0; + public void onEnable() { + if (Bukkit.getPluginManager().getPlugin("Skript") != null) { + Skript.registerAddon(this); + getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully enabled!"); + if (Bukkit.getVersion().contains("(MC: 1.8)")){ + getLogger().info("Successfully found 1.8! Registering version specific expressions..."); + exprAmount += 3; + 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%"); + Classes.registerClass(new ClassInfo(NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { + + @Override + public String getVariableNamePattern() { + return ".+"; + } + + @Override + @Nullable + public NBTTagCompound parse(String s, ParseContext arg1) { + NBTTagCompound NBT = new NBTTagCompound(); + NBTTagCompound NBT1 = MojangsonParser.parse(s); + NBT1.a(NBT); + if (NBT.isEmpty() || NBT == null) { + return null; + } + return NBT; + } + + @Override + public String toString(NBTTagCompound compound, int arg1) { + return compound.toString(); + } + + @Override + public String toVariableNameString(NBTTagCompound compound) { + return compound.toString(); + } + })); + } + if (Bukkit.getVersion().contains("(MC: 1.8.3)")){ + getLogger().info("Successfully found 1.8.3! Registering version specific expressions..."); + exprAmount += 3; + 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%"); + Classes.registerClass(new ClassInfo(net.minecraft.server.v1_8_R2.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { + + @Override + public String getVariableNamePattern() { + return ".+"; + } + + @Override + @Nullable + public net.minecraft.server.v1_8_R2.NBTTagCompound parse(String s, ParseContext arg1) { + 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; + } + + @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 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 += 3; + 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%"); + Classes.registerClass(new ClassInfo(net.minecraft.server.v1_8_R3.NBTTagCompound.class, "compound").name("NBT Tag Compound").parser(new Parser() { + + @Override + public String getVariableNamePattern() { + return ".+"; + } + + @Override + @Nullable + public net.minecraft.server.v1_8_R3.NBTTagCompound parse(String s, ParseContext arg1) { + 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; + } + + @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 compound.toString(); + } + })); + } + if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) { + getLogger().info("WorldEdit found! Registering WorldEdit stuff..."); + condAmount += 1; + evtAmount += 1; + exprAmount += 12; + 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.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(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(ExprVolumeOfSelection.class, Integer.class, ExpressionType.SIMPLE, "volume of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection volume"); + 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] %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%]"); + } + String pluralCond = "s"; + String pluralType = "s"; + String pluralEvt = "s"; + if (condAmount == 1) { + pluralCond = ""; + } + if (typeAmount == 1) { + pluralType = ""; + } + if (evtAmount == 1) { + pluralEvt = ""; + } + getLogger().info("Everything ready! Loaded a total of " + condAmount + " condition" + pluralCond + ", " + evtAmount + "event" + pluralEvt + ", " + exprAmount + " expressions and " + typeAmount + " type" + pluralType + "!"); + } else { + getLogger().info("Unable to find Skript, disabling SkStuff..."); + this.onDisable(); + } + } + + public void onDisable() { + getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully disabled"); + } +} diff --git a/src/me/TheBukor/conditions/CondSelectionContains.java b/src/me/TheBukor/conditions/CondSelectionContains.java new file mode 100644 index 0000000..4715d71 --- /dev/null +++ b/src/me/TheBukor/conditions/CondSelectionContains.java @@ -0,0 +1,49 @@ +package me.TheBukor.conditions; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +import javax.annotation.Nullable; + +import ch.njol.skript.lang.Condition; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Checker; +import ch.njol.util.Kleenean; + +public class CondSelectionContains extends Condition { + private Expression player; + private Expression loc; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + player = (Expression) expr[0]; + loc = (Expression) expr[1]; + setNegated(matchedPattern == 2 || matchedPattern == 3); + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "if WorldEdit selection of " + player.toString(e, false) + (isNegated() ? " doesn't contain " : " contains ") + loc.toString(e, false); + } + + @Override + public boolean check(Event e) { + WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + if (we.getSelection(player.getSingle(e)) == null) { + return false; + } + return player.check(e, new Checker() { + @Override + public boolean check(Player p) { + return we.getSelection(p).contains(loc.getSingle(e)); + } + }, isNegated()); + } +} diff --git a/src/me/TheBukor/expressions/ExprAreaOfSelection.java b/src/me/TheBukor/expressions/ExprAreaOfSelection.java new file mode 100644 index 0000000..4bb017b --- /dev/null +++ b/src/me/TheBukor/expressions/ExprAreaOfSelection.java @@ -0,0 +1,51 @@ +package me.TheBukor.expressions; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +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 ExprAreaOfSelection extends SimpleExpression { + private Expression player; + + @Override + public Class 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) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the area of the WorldEdit selection of " + player.toString(e, false); + } + + @Override + @Nullable + protected Integer[] get(Event e) { + WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + if (worldEdit.getSelection(player.getSingle(e)) == null) { + return null; + } + return new Integer[] { (worldEdit.getSelection(player.getSingle(e)).getWidth() * worldEdit.getSelection(player.getSingle(e)).getLength()) }; + } + +} diff --git a/src/me/TheBukor/expressions/ExprHeightOfSchematic.java b/src/me/TheBukor/expressions/ExprHeightOfSchematic.java new file mode 100644 index 0000000..d5d2a10 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprHeightOfSchematic.java @@ -0,0 +1,64 @@ +package me.TheBukor.expressions; + +import java.io.File; +import java.io.IOException; + +import javax.annotation.Nullable; + +import org.bukkit.Bukkit; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.data.DataException; +import com.sk89q.worldedit.schematic.MCEditSchematicFormat; + +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; + +@SuppressWarnings("deprecation") +public class ExprHeightOfSchematic extends SimpleExpression { + private Expression schematic; + private Expression folder; + @SuppressWarnings("unused") + private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + + @Override + public Class getReturnType() { + return Integer.class; + } + + @Override + public boolean isSingle() { + return true; + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + schematic = (Expression) expr[0]; + folder = (Expression) expr[1]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the height of the schematic " + schematic.toString(e, false); + } + + @Override + @Nullable + protected Integer[] get(Event e) { + String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/"; + String schem = schematic.getSingle(e); + File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic")); + Integer h = null; + try { + h = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getHeight(); + } catch (DataException | IOException e1) { + return null; + } + return new Integer[] { h }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprHeightOfSelection.java b/src/me/TheBukor/expressions/ExprHeightOfSelection.java new file mode 100644 index 0000000..541f791 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprHeightOfSelection.java @@ -0,0 +1,51 @@ +package me.TheBukor.expressions; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +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 { + private Expression player; + + @Override + public Class 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) 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 worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + if (worldEdit.getSelection(player.getSingle(e)) == null) { + return null; + } + return new Integer[] { worldEdit.getSelection(player.getSingle(e)).getHeight() }; + } + +} diff --git a/src/me/TheBukor/expressions/ExprItemNBTv1_8_R1.java b/src/me/TheBukor/expressions/ExprItemNBTv1_8_R1.java new file mode 100644 index 0000000..6e271c4 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprItemNBTv1_8_R1.java @@ -0,0 +1,61 @@ +package me.TheBukor.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 { + private Expression itemStack; + private Expression string; + + @Override + public Class 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) expr[0]; + string = (Expression) 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 }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprItemNBTv1_8_R2.java b/src/me/TheBukor/expressions/ExprItemNBTv1_8_R2.java new file mode 100644 index 0000000..f83ac33 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprItemNBTv1_8_R2.java @@ -0,0 +1,68 @@ +package me.TheBukor.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 { + private Expression itemStack; + private Expression string; + + @Override + public Class 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) expr[0]; + string = (Expression) 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 }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprItemNBTv1_8_R3.java b/src/me/TheBukor/expressions/ExprItemNBTv1_8_R3.java new file mode 100644 index 0000000..bac390c --- /dev/null +++ b/src/me/TheBukor/expressions/ExprItemNBTv1_8_R3.java @@ -0,0 +1,68 @@ +package me.TheBukor.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 { + private Expression itemStack; + private Expression string; + + @Override + public Class 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) expr[0]; + string = (Expression) 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 }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprLengthOfSchematic.java b/src/me/TheBukor/expressions/ExprLengthOfSchematic.java new file mode 100644 index 0000000..914f0e7 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprLengthOfSchematic.java @@ -0,0 +1,64 @@ +package me.TheBukor.expressions; + +import java.io.File; +import java.io.IOException; + +import javax.annotation.Nullable; + +import org.bukkit.Bukkit; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.data.DataException; +import com.sk89q.worldedit.schematic.MCEditSchematicFormat; + +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; + +@SuppressWarnings("deprecation") +public class ExprLengthOfSchematic extends SimpleExpression { + private Expression schematic; + private Expression folder; + @SuppressWarnings("unused") + private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + + @Override + public Class getReturnType() { + return Integer.class; + } + + @Override + public boolean isSingle() { + return true; + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + schematic = (Expression) expr[0]; + folder = (Expression) expr[1]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the length of the schematic " + schematic.toString(e, false); + } + + @Override + @Nullable + protected Integer[] get(Event e) { + String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/"; + String schem = schematic.getSingle(e); + File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic")); + Integer l = null; + try { + l = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getLength(); + } catch (DataException | IOException e1) { + return null; + } + return new Integer[] { l }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprLengthOfSelection.java b/src/me/TheBukor/expressions/ExprLengthOfSelection.java new file mode 100644 index 0000000..8110a95 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprLengthOfSelection.java @@ -0,0 +1,51 @@ +package me.TheBukor.expressions; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +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 { + private Expression player; + + @Override + public Class 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) 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 worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + if (worldEdit.getSelection(player.getSingle(e)) == null) { + return null; + } + return new Integer[] { worldEdit.getSelection(player.getSingle(e)).getLength() }; + } + +} diff --git a/src/me/TheBukor/expressions/ExprNBTv1_8_R1.java b/src/me/TheBukor/expressions/ExprNBTv1_8_R1.java new file mode 100644 index 0000000..8814f46 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprNBTv1_8_R1.java @@ -0,0 +1,197 @@ +package me.TheBukor.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 { + private Expression target; + private NBTTagCompound[] returned; + + @Override + public Class 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; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprNBTv1_8_R2.java b/src/me/TheBukor/expressions/ExprNBTv1_8_R2.java new file mode 100644 index 0000000..c5973a0 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprNBTv1_8_R2.java @@ -0,0 +1,211 @@ +package me.TheBukor.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 { + private Expression target; + private NBTTagCompound[] returned; + + @Override + public Class 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; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprNBTv1_8_R3.java b/src/me/TheBukor/expressions/ExprNBTv1_8_R3.java new file mode 100644 index 0000000..195a059 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprNBTv1_8_R3.java @@ -0,0 +1,211 @@ +package me.TheBukor.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 { + private Expression target; + private NBTTagCompound[] returned; + + @Override + public Class 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; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprSelectionOfPlayer.java b/src/me/TheBukor/expressions/ExprSelectionOfPlayer.java new file mode 100644 index 0000000..c4cc177 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprSelectionOfPlayer.java @@ -0,0 +1,96 @@ +package me.TheBukor.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.WorldEditPlugin; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.regions.Region; + +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 ExprSelectionOfPlayer extends SimpleExpression { + private Expression player; + private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");; + + @Override + public Class getReturnType() { + return Location.class; + } + + @Override + public boolean isSingle() { + return false; + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + player = (Expression) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the WorldEdit selection of " + player.toString(e, false); + } + + @SuppressWarnings("deprecation") + @Override + @Nullable + protected Location[] get(Event e) { + Player p = player.getSingle(e); + Region region = null; + try { + region = we.getSession(p).getRegion(); + } catch (IncompleteRegionException ex) { + return null; + } + if (!(region instanceof CuboidRegion)) { + return null; + } + CuboidRegion cuboid = (CuboidRegion) region; + Vector pos1Vec = cuboid.getPos1(); + Vector pos2Vec = cuboid.getPos2(); + Location pos1 = new Location(we.getSelection(p).getWorld(), pos1Vec.getX(), pos1Vec.getY(), pos1Vec.getZ()); + Location pos2 = new Location(we.getSelection(p).getWorld(), pos2Vec.getX(), pos2Vec.getY(), pos2Vec.getZ()); + return new Location[] { pos1, pos2 }; + } +/* + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + Player p = player.getSingle(e); + Object[] objs = getSource().getAll(e); + for (int i = 0; i < objs.length; i++) { + if (i > 0) { + Bukkit.broadcastMessage("WOT M8!! GREATER THAN 1!!"); + Bukkit.broadcastMessage(objs[i].toString()); + } + } + if (mode == ChangeMode.SET) { + we.setSelection(p, new CuboidSelection(((Location) objs[0]).getWorld(), (Location) objs[0], (Location) objs[1])); + } else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { + we.setSelection(p, null); + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { + return CollectionUtils.array(Location.class); + } + return null; + } +*/ +} diff --git a/src/me/TheBukor/expressions/ExprSelectionPos1.java b/src/me/TheBukor/expressions/ExprSelectionPos1.java new file mode 100644 index 0000000..8f1b878 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprSelectionPos1.java @@ -0,0 +1,65 @@ +package me.TheBukor.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.WorldEditPlugin; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.regions.Region; + +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 ExprSelectionPos1 extends SimpleExpression { + private Expression player; + private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + + @Override + public Class 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) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the WorldEdit point 1 selection of " + player.toString(e, false); + } + + @SuppressWarnings("deprecation") + @Override + @Nullable + protected Location[] get(Event e) { + Player p = player.getSingle(e); + Region region = null; + try { + region = we.getSession(p).getRegion(); + } catch (IncompleteRegionException ex) { + return null; + } + if (!(region instanceof CuboidRegion)) { + return null; + } + CuboidRegion cuboid = (CuboidRegion) region; + Vector pos = cuboid.getPos1(); + return new Location[] { new Location(we.getSelection(p).getWorld(), pos.getX(), pos.getY(), pos.getZ()) }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprSelectionPos2.java b/src/me/TheBukor/expressions/ExprSelectionPos2.java new file mode 100644 index 0000000..a04126d --- /dev/null +++ b/src/me/TheBukor/expressions/ExprSelectionPos2.java @@ -0,0 +1,65 @@ +package me.TheBukor.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.WorldEditPlugin; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.regions.Region; + +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 ExprSelectionPos2 extends SimpleExpression { + private Expression player; + private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + + @Override + public Class 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) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the WorldEdit point 2 selection of " + player.toString(e, false); + } + + @SuppressWarnings("deprecation") + @Override + @Nullable + protected Location[] get(Event e) { + Player p = player.getSingle(e); + Region region = null; + try { + region = we.getSession(p).getRegion(); + } catch (IncompleteRegionException ex) { + return null; + } + if (!(region instanceof CuboidRegion)) { + return null; + } + CuboidRegion cuboid = (CuboidRegion) region; + Vector pos = cuboid.getPos2(); + return new Location[] { new Location(we.getSelection(p).getWorld(), pos.getX(), pos.getY(), pos.getZ()) }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java b/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java new file mode 100644 index 0000000..120726a --- /dev/null +++ b/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java @@ -0,0 +1,82 @@ +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_8_R1.NBTTagCompound; + +public class ExprTagOfv1_8_R1 extends SimpleExpression { + private Expression string; + private Expression compound; + private Object[] returned; + @Override + public Class 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) expr[0]; + compound = (Expression) 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); + String tag = string.getSingle(e); + if (NBT.get(tag) == null) { + return null; + } + Byte id = NBT.get(tag).getTypeId(); + switch (id) { + case 1: + returned = new Object[] { NBT.getByte(tag) }; + break; + case 2: + returned = new Object[] { NBT.getShort(tag) }; + break; + case 3: + returned = new Object[] { NBT.getInt(tag) }; + break; + case 4: + returned = new Object[] { NBT.getLong(tag) }; + break; + case 5: + returned = new Object[] { NBT.getFloat(tag) }; + break; + case 6: + returned = new Object[] { NBT.getDouble(tag) }; + break; + case 8: + returned = new Object[] { NBT.getString(tag) }; + break; + case 9: + returned = null; + break; + case 10: + returned = new Object[] { NBT.getCompound(tag) }; + break; + case 11: + returned = null; + break; + default: + break; + } + return returned; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java b/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java new file mode 100644 index 0000000..8e58072 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java @@ -0,0 +1,82 @@ +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_8_R2.NBTTagCompound; + +public class ExprTagOfv1_8_R2 extends SimpleExpression { + private Expression string; + private Expression compound; + private Object[] returned; + @Override + public Class 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) expr[0]; + compound = (Expression) 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); + String tag = string.getSingle(e); + if (NBT.get(tag) == null) { + return null; + } + Byte id = NBT.get(tag).getTypeId(); + switch (id) { + case 1: + returned = new Object[] { NBT.getByte(tag) }; + break; + case 2: + returned = new Object[] { NBT.getShort(tag) }; + break; + case 3: + returned = new Object[] { NBT.getInt(tag) }; + break; + case 4: + returned = new Object[] { NBT.getLong(tag) }; + break; + case 5: + returned = new Object[] { NBT.getFloat(tag) }; + break; + case 6: + returned = new Object[] { NBT.getDouble(tag) }; + break; + case 8: + returned = new Object[] { NBT.getString(tag) }; + break; + case 9: + returned = null; + break; + case 10: + returned = new Object[] { NBT.getCompound(tag) }; + break; + case 11: + returned = null; + break; + default: + break; + } + return returned; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java b/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java new file mode 100644 index 0000000..0a5dd32 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java @@ -0,0 +1,82 @@ +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_8_R3.NBTTagCompound; + +public class ExprTagOfv1_8_R3 extends SimpleExpression { + private Expression string; + private Expression compound; + private Object[] returned; + @Override + public Class 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) expr[0]; + compound = (Expression) 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); + String tag = string.getSingle(e); + if (NBT.get(tag) == null) { + return null; + } + Byte id = NBT.get(tag).getTypeId(); + switch (id) { + case 1: + returned = new Object[] { NBT.getByte(tag) }; + break; + case 2: + returned = new Object[] { NBT.getShort(tag) }; + break; + case 3: + returned = new Object[] { NBT.getInt(tag) }; + break; + case 4: + returned = new Object[] { NBT.getLong(tag) }; + break; + case 5: + returned = new Object[] { NBT.getFloat(tag) }; + break; + case 6: + returned = new Object[] { NBT.getDouble(tag) }; + break; + case 8: + returned = new Object[] { NBT.getString(tag) }; + break; + case 9: + returned = null; + break; + case 10: + returned = new Object[] { NBT.getCompound(tag) }; + break; + case 11: + returned = null; + break; + default: + break; + } + return returned; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprVolumeOfSchematic.java b/src/me/TheBukor/expressions/ExprVolumeOfSchematic.java new file mode 100644 index 0000000..71f0101 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprVolumeOfSchematic.java @@ -0,0 +1,76 @@ +package me.TheBukor.expressions; + +import java.io.File; +import java.io.IOException; + +import javax.annotation.Nullable; + +import org.bukkit.Bukkit; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.data.DataException; +import com.sk89q.worldedit.schematic.MCEditSchematicFormat; + +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; + +@SuppressWarnings("deprecation") +public class ExprVolumeOfSchematic extends SimpleExpression { + private Expression schematic; + private Expression folder; + @SuppressWarnings("unused") + private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + + @Override + public Class getReturnType() { + return Integer.class; + } + + @Override + public boolean isSingle() { + return true; + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + schematic = (Expression) expr[0]; + folder = (Expression) expr[1]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the volume of the schematic " + schematic.toString(e, false); + } + + @Override + @Nullable + protected Integer[] get(Event e) { + String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/"; + String schem = schematic.getSingle(e); + File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic")); + Integer w = 0; + Integer h = 0; + Integer l = 0; + try { + w = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getWidth(); + } catch (DataException | IOException e1) { + return null; + } + try { + h = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getHeight(); + } catch (DataException | IOException e2) { + return null; + } + try { + l = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getLength(); + } catch (DataException | IOException e1) { + return null; + } + return new Integer[] { w * h * l }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprVolumeOfSelection.java b/src/me/TheBukor/expressions/ExprVolumeOfSelection.java new file mode 100644 index 0000000..92fbd91 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprVolumeOfSelection.java @@ -0,0 +1,51 @@ +package me.TheBukor.expressions; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +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 { + private Expression player; + + @Override + public Class 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) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the volume of the WorldEdit selection of " + player.toString(e, false); + } + + @Override + @Nullable + protected Integer[] get(Event e) { + WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + if (worldEdit.getSelection(player.getSingle(e)) == null) { + return null; + } + return new Integer[] { worldEdit.getSelection(player.getSingle(e)).getArea() }; + } + +} diff --git a/src/me/TheBukor/expressions/ExprWidthOfSchematic.java b/src/me/TheBukor/expressions/ExprWidthOfSchematic.java new file mode 100644 index 0000000..38c52ea --- /dev/null +++ b/src/me/TheBukor/expressions/ExprWidthOfSchematic.java @@ -0,0 +1,64 @@ +package me.TheBukor.expressions; + +import java.io.File; +import java.io.IOException; + +import javax.annotation.Nullable; + +import org.bukkit.Bukkit; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.data.DataException; +import com.sk89q.worldedit.schematic.MCEditSchematicFormat; + +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; + +@SuppressWarnings("deprecation") +public class ExprWidthOfSchematic extends SimpleExpression { + private Expression schematic; + private Expression folder; + @SuppressWarnings("unused") + private WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + + @Override + public Class getReturnType() { + return Integer.class; + } + + @Override + public boolean isSingle() { + return true; + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + schematic = (Expression) expr[0]; + folder = (Expression) expr[1]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the width of the schematic " + schematic.toString(e, false); + } + + @Override + @Nullable + protected Integer[] get(Event e) { + String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/"; + String schem = schematic.getSingle(e); + File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic")); + Integer w = null; + try { + w = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getWidth(); + } catch (DataException | IOException e1) { + return null; + } + return new Integer[] { w }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprWidthOfSelection.java b/src/me/TheBukor/expressions/ExprWidthOfSelection.java new file mode 100644 index 0000000..ca2a1f7 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprWidthOfSelection.java @@ -0,0 +1,51 @@ +package me.TheBukor.expressions; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +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 { + private Expression player; + + @Override + public Class 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) 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 worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + if (worldEdit.getSelection(player.getSingle(e)) == null) { + return null; + } + return new Integer[] { worldEdit.getSelection(player.getSingle(e)).getWidth() }; + } + +}