From ced2a2648dc626a2967cae6b842478d6e408e04a Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 29 Nov 2015 16:49:36 -0200 Subject: [PATCH] Added experimental WE effects/expressions, fixed NPE when using the... ..."tag %string% of %compound%" expression with ItemStacks without NBT, tried to fix schematic expressions. --- src/me/TheBukor/SkStuff.java | 94 ++++++++++++------- src/me/TheBukor/effects/EffDrawLineWE.java | 63 +++++++++++++ .../TheBukor/effects/EffExecuteWorldEdit.java | 13 +-- .../TheBukor/effects/EffUndoRedoSession.java | 42 +++++++++ .../expressions/ExprChangedBlocksSession.java | 45 +++++++++ .../TheBukor/expressions/ExprEditSession.java | 54 +++++++++++ .../expressions/ExprEditSessionLimit.java | 73 ++++++++++++++ .../expressions/ExprHeightOfSchematic.java | 6 +- .../expressions/ExprLengthOfSchematic.java | 6 +- .../expressions/ExprTagOfv1_8_R1.java | 31 +++--- .../expressions/ExprTagOfv1_8_R2.java | 31 +++--- .../expressions/ExprTagOfv1_8_R3.java | 32 ++++--- .../expressions/ExprVolumeOfSchematic.java | 6 +- .../expressions/ExprWidthOfSchematic.java | 6 +- 14 files changed, 405 insertions(+), 97 deletions(-) create mode 100644 src/me/TheBukor/effects/EffDrawLineWE.java create mode 100644 src/me/TheBukor/effects/EffUndoRedoSession.java create mode 100644 src/me/TheBukor/expressions/ExprChangedBlocksSession.java create mode 100644 src/me/TheBukor/expressions/ExprEditSession.java create mode 100644 src/me/TheBukor/expressions/ExprEditSessionLimit.java diff --git a/src/me/TheBukor/SkStuff.java b/src/me/TheBukor/SkStuff.java index fbd75a9..d22dba0 100644 --- a/src/me/TheBukor/SkStuff.java +++ b/src/me/TheBukor/SkStuff.java @@ -7,6 +7,8 @@ import org.bukkit.Location; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import com.sk89q.worldedit.EditSession; + import ch.njol.skript.Skript; import ch.njol.skript.classes.ClassInfo; import ch.njol.skript.classes.Parser; @@ -14,8 +16,12 @@ 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.effects.EffExecuteWorldEdit; +import me.TheBukor.effects.EffDrawLineWE; +import me.TheBukor.effects.EffUndoRedoSession; import me.TheBukor.expressions.ExprAreaOfSelection; +import me.TheBukor.expressions.ExprChangedBlocksSession; +import me.TheBukor.expressions.ExprEditSession; +import me.TheBukor.expressions.ExprEditSessionLimit; import me.TheBukor.expressions.ExprHeightOfSchematic; import me.TheBukor.expressions.ExprHeightOfSelection; import me.TheBukor.expressions.ExprItemNBTv1_8_R1; @@ -44,7 +50,7 @@ public class SkStuff extends JavaPlugin { private int condAmount = 0; private int exprAmount = 0; private int typeAmount = 0; - private int evtAmount = 0; + private int effAmount = 0; public void onEnable() { if (Bukkit.getPluginManager().getPlugin("Skript") != null) { Skript.registerAddon(this); @@ -65,7 +71,7 @@ public class SkStuff extends JavaPlugin { @Override @Nullable - public NBTTagCompound parse(String s, ParseContext arg1) { + public NBTTagCompound parse(String s, ParseContext context) { NBTTagCompound NBT = new NBTTagCompound(); NBTTagCompound NBT1 = MojangsonParser.parse(s); NBT1.a(NBT); @@ -84,7 +90,7 @@ public class SkStuff extends JavaPlugin { 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..."); @@ -102,7 +108,7 @@ public class SkStuff extends JavaPlugin { @Override @Nullable - public net.minecraft.server.v1_8_R2.NBTTagCompound parse(String s, ParseContext arg1) { + public net.minecraft.server.v1_8_R2.NBTTagCompound parse(String s, ParseContext context) { net.minecraft.server.v1_8_R2.NBTTagCompound NBT = new net.minecraft.server.v1_8_R2.NBTTagCompound(); try { net.minecraft.server.v1_8_R2.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R2.MojangsonParser.parse(s); @@ -125,7 +131,7 @@ public class SkStuff extends JavaPlugin { 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..."); @@ -143,7 +149,7 @@ public class SkStuff extends JavaPlugin { @Override @Nullable - public net.minecraft.server.v1_8_R3.NBTTagCompound parse(String s, ParseContext arg1) { + public net.minecraft.server.v1_8_R3.NBTTagCompound parse(String s, ParseContext context) { net.minecraft.server.v1_8_R3.NBTTagCompound NBT = new net.minecraft.server.v1_8_R3.NBTTagCompound(); try { net.minecraft.server.v1_8_R3.NBTTagCompound NBT1 = net.minecraft.server.v1_8_R3.MojangsonParser.parse(s); @@ -166,15 +172,22 @@ public class SkStuff extends JavaPlugin { 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; + effAmount += 2; + exprAmount += 15; + typeAmount += 1; Skript.registerCondition(CondSelectionContains.class, "[(world[ ]edit|we)] selection of %player% (contains|has) %location%", "%player%'s [(world[ ]edit|we)] selection (contains|has) %location%", "[(world[ ]edit|we)] selection of %player% does(n't| not) (contain|have) %location%", "%player%'s [(world[ ]edit|we)] selection does(n't| not) (contain|have) %location%"); - Skript.registerEffect(EffExecuteWorldEdit.class, "make %player% execute (world[ ]edit|we) [operation] set (using|with) %itemstack% [[with] limit [of] %integer% [blocks]]", "execute %player% (world[ ]edit|we) [operation] set (using|with) %itemstack% [[with] limit [of] %integer% [blocks]"); + // EXPERIMENTAL EFFECTS/EXPRESSIONS + Skript.registerEffect(EffDrawLineWE.class, "(create|draw|make) [a] (no(n|t)(-| )hollow|filled) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block] %itemstack% [[(and|with)] thick[ness] %-double%]", "(create|draw|make) [a] hollow line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block] %itemstack% [[(and|with)] thick[ness] %-double%]"); + Skript.registerEffect(EffUndoRedoSession.class, "undo [last] (change|edit)[s] (of|from) [edit[ ]session] %editsession%", "redo [last] (change|edit)[s] (of|from) [edit[ ]session] %editsession%"); + Skript.registerExpression(ExprEditSessionLimit.class, Integer.class, ExpressionType.PROPERTY, "[block] limit [change] of [edit[ ]session] %editsession%"); + Skript.registerExpression(ExprChangedBlocksSession.class, Integer.class, ExpressionType.PROPERTY, "number of [all] changed blocks (in|of) [edit[ ]session] %editsession%"); + Skript.registerExpression(ExprEditSession.class, EditSession.class, ExpressionType.PROPERTY, "[new] edit[ ]session (for|from|of) %player%", "[new] %player% edit[ ]session"); + // END OF EXPERIMENTAL EFFS/EXPRS Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection"); Skript.registerExpression(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"); @@ -183,29 +196,46 @@ 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%]"); - } - 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(); + 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%]"); + Classes.registerClass(new ClassInfo(EditSession.class, "editsession").name("Edit Session").parser(new Parser() { + + @Override + public String getVariableNamePattern() { + return ".+"; + } + + @Override + @Nullable + public EditSession parse(String s, ParseContext context) { + return null; + } + + @Override + public boolean canParse(ParseContext context) { + return false; + } + + @Override + public String toString(EditSession editSession, int arg1) { + return null; + } + + @Override + public String toVariableNameString(EditSession editSession) { + return null; + } + + })); } + getLogger().info("Everything ready! Loaded a total of " + condAmount + (condAmount == 1 ? " condition, " : " conditions, ") + effAmount + (effAmount == 1 ? " effect, " : " effects, ") + exprAmount + (exprAmount == 1 ? " expression" : " expressions and ") + typeAmount + (typeAmount == 1 ? " type!" : " types!")); + } 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/effects/EffDrawLineWE.java b/src/me/TheBukor/effects/EffDrawLineWE.java new file mode 100644 index 0000000..619e523 --- /dev/null +++ b/src/me/TheBukor/effects/EffDrawLineWE.java @@ -0,0 +1,63 @@ +package me.TheBukor.effects; + +import javax.annotation.Nullable; + +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.inventory.ItemStack; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.bukkit.BukkitUtil; +import com.sk89q.worldedit.patterns.SingleBlockPattern; + +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; + +@SuppressWarnings("deprecation") +public class EffDrawLineWE extends Effect { + private Expression location1; + private Expression location2; + private Expression editSession; + private Expression block; + private Expression thickness; + private boolean filled = true; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + location1 = (Expression) expr[0]; + location2 = (Expression) expr[1]; + editSession = (Expression) expr[2]; + block = (Expression) expr[3]; + thickness = (Expression) expr[4]; + if (matchedPattern == 1) filled = false; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "draw a line using an edit session with " + block.toString(e, false); + } + + @Override + protected void execute(Event e) { + Location pos1 = location1.getSingle(e); + Location pos2 = location2.getSingle(e); + EditSession session = editSession.getSingle(e); + ItemStack b = block.getSingle(e); + Double thick = thickness.getSingle(e); + if (thick == null) thick = (double) 1; + if (b.getType().isBlock()) { + try { + session.drawLine(new SingleBlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), BukkitUtil.toVector(pos1), BukkitUtil.toVector(pos2), thick, filled); + session.flushQueue(); + } catch (MaxChangedBlocksException ex) { + return; + } + } + } +} diff --git a/src/me/TheBukor/effects/EffExecuteWorldEdit.java b/src/me/TheBukor/effects/EffExecuteWorldEdit.java index 9d9e549..92e1e35 100644 --- a/src/me/TheBukor/effects/EffExecuteWorldEdit.java +++ b/src/me/TheBukor/effects/EffExecuteWorldEdit.java @@ -19,7 +19,6 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; -@SuppressWarnings("deprecation") public class EffExecuteWorldEdit extends Effect { private Expression player; private Expression block; @@ -40,21 +39,19 @@ public class EffExecuteWorldEdit extends Effect { return "make " + player.toString(e, false) + " execute WorldEdit set using " + block.toString(e, false) + new String(blockLimit.getSingle(e) != null ? " with limit of " + blockLimit.toString(e, false) + " blocks" : ""); } + @SuppressWarnings("deprecation") @Override protected void execute(Event e) { Player p = player.getSingle(e); ItemStack b = block.getSingle(e); Integer limit = blockLimit.getSingle(e); - if (limit == null) limit = we.getWorldEdit().getConfiguration().defaultChangeLimit; + if (limit == null) limit = we.getLocalConfiguration().defaultChangeLimit; if (we.getSelection(p) != null) { if (b.getType().isBlock()) { try { - EditSession session = we.createEditSession(p); - p.sendMessage(Boolean.toString(session.isQueueEnabled())); - session.enableQueue(); - session.setBlockChangeLimit(limit); - session.setBlocks(we.getSession(p).getSelection((World) we.wrapPlayer(p).getWorld()), new BaseBlock(b.getTypeId(), b.getDurability())); - we.getSession(p).remember(session); + EditSession editSession = we.getWorldEdit().getEditSessionFactory().getEditSession((World) we.wrapPlayer(p).getWorld(), limit, (com.sk89q.worldedit.entity.Player) we.wrapPlayer(p)); + editSession.setBlocks(we.getSession(p).getSelection((World) we.wrapPlayer(p).getWorld()), new BaseBlock(b.getTypeId(), b.getDurability())); + we.getSession(p).remember(editSession); //So the player can do //undo if he wants to } catch (MaxChangedBlocksException | IncompleteRegionException ex) { return; } diff --git a/src/me/TheBukor/effects/EffUndoRedoSession.java b/src/me/TheBukor/effects/EffUndoRedoSession.java new file mode 100644 index 0000000..d4b4fda --- /dev/null +++ b/src/me/TheBukor/effects/EffUndoRedoSession.java @@ -0,0 +1,42 @@ +package me.TheBukor.effects; + +import javax.annotation.Nullable; + +import org.bukkit.event.Event; + +import com.sk89q.worldedit.EditSession; + +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; + +public class EffUndoRedoSession extends Effect { + private Expression editSession; + private boolean redo = false; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + editSession = (Expression) expr[0]; + if (matchedPattern == 1) redo = true; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "undo last change of edit session"; + } + + @Override + protected void execute(Event e) { + EditSession session = editSession.getSingle(e); + if (session == null) return; + if (redo == false) { + session.undo(session); + } else { + session.redo(session); + } + session.flushQueue(); + } +} \ No newline at end of file diff --git a/src/me/TheBukor/expressions/ExprChangedBlocksSession.java b/src/me/TheBukor/expressions/ExprChangedBlocksSession.java new file mode 100644 index 0000000..22ddf51 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprChangedBlocksSession.java @@ -0,0 +1,45 @@ +package me.TheBukor.expressions; + +import javax.annotation.Nullable; + +import org.bukkit.event.Event; + +import com.sk89q.worldedit.EditSession; + +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 ExprChangedBlocksSession extends SimpleExpression { + private Expression editSession; + @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) { + editSession = (Expression) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the number of changed blocks in an edit session"; + } + + @Override + @Nullable + protected Integer[] get(Event e) { + EditSession session = editSession.getSingle(e); + if (session == null) return null; + return new Integer[] { session.getBlockChangeCount() }; + } +} diff --git a/src/me/TheBukor/expressions/ExprEditSession.java b/src/me/TheBukor/expressions/ExprEditSession.java new file mode 100644 index 0000000..36ed27f --- /dev/null +++ b/src/me/TheBukor/expressions/ExprEditSession.java @@ -0,0 +1,54 @@ +package me.TheBukor.expressions; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.world.World; + +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 ExprEditSession extends SimpleExpression { + private Expression player; + + @Override + public Class getReturnType() { + return EditSession.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 edit session of " + player.toString(e, false); + } + + @Override + @Nullable + protected EditSession[] get(Event e) { + Player p = player.getSingle(e); + WorldEditPlugin we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + if (we.getWorldEdit().getEditSessionFactory().getEditSession((World) we.wrapPlayer(p).getWorld(), we.getSession(p).getBlockChangeLimit(), we.wrapPlayer(p)) == null) { + return new EditSession[] { we.createEditSession(p) }; + } + return new EditSession[] { we.getWorldEdit().getEditSessionFactory().getEditSession((World) we.wrapPlayer(p).getWorld(), we.getSession(p).getBlockChangeLimit(), we.wrapPlayer(p)) }; + } + +} diff --git a/src/me/TheBukor/expressions/ExprEditSessionLimit.java b/src/me/TheBukor/expressions/ExprEditSessionLimit.java new file mode 100644 index 0000000..c8a9e65 --- /dev/null +++ b/src/me/TheBukor/expressions/ExprEditSessionLimit.java @@ -0,0 +1,73 @@ +package me.TheBukor.expressions; + +import javax.annotation.Nullable; + +import org.bukkit.Bukkit; +import org.bukkit.event.Event; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +import ch.njol.skript.classes.Changer.ChangeMode; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; + +public class ExprEditSessionLimit extends SimpleExpression { + private Expression editSession; + 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) { + editSession = (Expression) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "the block change limit of an edit session"; + } + + @Override + @Nullable + protected Integer[] get(Event e) { + EditSession session = editSession.getSingle(e); + if (session == null) return null; + return new Integer[] { session.getBlockChangeLimit() }; + } + + @Override + public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { + EditSession session = editSession.getSingle(e); + if (mode == ChangeMode.SET) { + Integer newLimit = (Integer) delta[0]; + session.setBlockChangeLimit(newLimit); + } else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) { + session.setBlockChangeLimit(we.getLocalConfiguration().defaultChangeLimit); + } + } + + @SuppressWarnings("unchecked") + @Override + @Nullable + public Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET || mode == ChangeMode.RESET || mode == ChangeMode.DELETE) { + return CollectionUtils.array(Integer.class); + } + return null; + } +} diff --git a/src/me/TheBukor/expressions/ExprHeightOfSchematic.java b/src/me/TheBukor/expressions/ExprHeightOfSchematic.java index b1bd987..c9f06d0 100644 --- a/src/me/TheBukor/expressions/ExprHeightOfSchematic.java +++ b/src/me/TheBukor/expressions/ExprHeightOfSchematic.java @@ -44,15 +44,15 @@ public class ExprHeightOfSchematic extends SimpleExpression { @Override public String toString(@Nullable Event e, boolean arg1) { - return "the height of the schematic " + schematic.toString(e, false) + " in the folder " + new String(folder.getSingle(e) != null ? folder.toString(e, false) : "plugins/WorldEdit/schematics"); + return "the height of the schematic " + schematic.toString(e, false) + " in the folder " + (folder.getSingle(e) == null ? "plugins/WorldEdit/schematics" : folder.toString(e, false)); } @Override @Nullable protected Integer[] get(Event e) { - String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/schematics/"; + String f = (folder.getSingle(e) == null) ? "plugins/WorldEdit/schematics/" : folder.getSingle(e); String schem = schematic.getSingle(e); - File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic")); + File schemFile = new File((f.endsWith("/")) ? f : (f + "/") + (schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); Integer h = null; try { h = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getHeight(); diff --git a/src/me/TheBukor/expressions/ExprLengthOfSchematic.java b/src/me/TheBukor/expressions/ExprLengthOfSchematic.java index 87295da..f5485f7 100644 --- a/src/me/TheBukor/expressions/ExprLengthOfSchematic.java +++ b/src/me/TheBukor/expressions/ExprLengthOfSchematic.java @@ -44,15 +44,15 @@ public class ExprLengthOfSchematic extends SimpleExpression { @Override public String toString(@Nullable Event e, boolean arg1) { - return "the length of the schematic " + schematic.toString(e, false) + " in the folder " + new String(folder.getSingle(e) != null ? folder.toString(e, false) : "plugins/WorldEdit/schematics"); + return "the length of the schematic " + schematic.toString(e, false) + " in the folder " + (folder.getSingle(e) == null ? "plugins/WorldEdit/schematics" : folder.toString(e, false)); } @Override @Nullable protected Integer[] get(Event e) { - String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/schematics/"; + String f = (folder.getSingle(e) == null) ? "plugins/WorldEdit/schematics/" : folder.getSingle(e); String schem = schematic.getSingle(e); - File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic")); + File schemFile = new File((f.endsWith("/")) ? f : (f + "/") + (schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); Integer l = null; try { l = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getLength(); diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java b/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java index 120726a..283b9fd 100644 --- a/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java +++ b/src/me/TheBukor/expressions/ExprTagOfv1_8_R1.java @@ -9,6 +9,7 @@ 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; +import net.minecraft.server.v1_8_R1.NBTTagList; public class ExprTagOfv1_8_R1 extends SimpleExpression { private Expression string; @@ -38,41 +39,41 @@ public class ExprTagOfv1_8_R1 extends SimpleExpression { @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; - } + if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return . Byte id = NBT.get(tag).getTypeId(); switch (id) { case 1: - returned = new Object[] { NBT.getByte(tag) }; + returned = new Byte[] { NBT.getByte(tag) }; break; case 2: - returned = new Object[] { NBT.getShort(tag) }; + returned = new Short[] { NBT.getShort(tag) }; break; case 3: - returned = new Object[] { NBT.getInt(tag) }; + returned = new Integer[] { NBT.getInt(tag) }; break; case 4: - returned = new Object[] { NBT.getLong(tag) }; + returned = new Long[] { NBT.getLong(tag) }; break; case 5: - returned = new Object[] { NBT.getFloat(tag) }; + returned = new Float[] { NBT.getFloat(tag) }; break; case 6: - returned = new Object[] { NBT.getDouble(tag) }; + 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 Object[] { NBT.getString(tag) }; + returned = new String[] { NBT.getString(tag) }; break; - case 9: - returned = null; + 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 Object[] { NBT.getCompound(tag) }; + returned = new NBTTagCompound[] { NBT.getCompound(tag) }; break; - case 11: - returned = null; + case 11: //Integer array, this one is only used on the chunk files I believe break; default: break; diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java b/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java index 8e58072..fb41e5e 100644 --- a/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java +++ b/src/me/TheBukor/expressions/ExprTagOfv1_8_R2.java @@ -9,6 +9,7 @@ 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; +import net.minecraft.server.v1_8_R2.NBTTagList; public class ExprTagOfv1_8_R2 extends SimpleExpression { private Expression string; @@ -38,41 +39,41 @@ public class ExprTagOfv1_8_R2 extends SimpleExpression { @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; - } + if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return . Byte id = NBT.get(tag).getTypeId(); switch (id) { case 1: - returned = new Object[] { NBT.getByte(tag) }; + returned = new Byte[] { NBT.getByte(tag) }; break; case 2: - returned = new Object[] { NBT.getShort(tag) }; + returned = new Short[] { NBT.getShort(tag) }; break; case 3: - returned = new Object[] { NBT.getInt(tag) }; + returned = new Integer[] { NBT.getInt(tag) }; break; case 4: - returned = new Object[] { NBT.getLong(tag) }; + returned = new Long[] { NBT.getLong(tag) }; break; case 5: - returned = new Object[] { NBT.getFloat(tag) }; + returned = new Float[] { NBT.getFloat(tag) }; break; case 6: - returned = new Object[] { NBT.getDouble(tag) }; + 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 Object[] { NBT.getString(tag) }; + returned = new String[] { NBT.getString(tag) }; break; - case 9: - returned = null; + 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 Object[] { NBT.getCompound(tag) }; + returned = new NBTTagCompound[] { NBT.getCompound(tag) }; break; - case 11: - returned = null; + case 11: //Integer array, this one is only used on the chunk files I believe break; default: break; diff --git a/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java b/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java index 0a5dd32..0b9f265 100644 --- a/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java +++ b/src/me/TheBukor/expressions/ExprTagOfv1_8_R3.java @@ -2,6 +2,7 @@ package me.TheBukor.expressions; import javax.annotation.Nullable; +import org.bukkit.Bukkit; import org.bukkit.event.Event; import ch.njol.skript.lang.Expression; @@ -38,41 +39,42 @@ public class ExprTagOfv1_8_R3 extends SimpleExpression { @Nullable protected Object[] get(Event e) { NBTTagCompound NBT = compound.getSingle(e); + if (NBT == null || NBT.isEmpty()) return null; //The NBT can be empty/inexistant for items String tag = string.getSingle(e); - if (NBT.get(tag) == null) { - return null; - } + if (NBT.get(tag) == null) return null; //The tag doesn't exist? Return . Byte id = NBT.get(tag).getTypeId(); switch (id) { case 1: - returned = new Object[] { NBT.getByte(tag) }; + returned = new Byte[] { NBT.getByte(tag) }; break; case 2: - returned = new Object[] { NBT.getShort(tag) }; + returned = new Short[] { NBT.getShort(tag) }; break; case 3: - returned = new Object[] { NBT.getInt(tag) }; + returned = new Integer[] { NBT.getInt(tag) }; break; case 4: - returned = new Object[] { NBT.getLong(tag) }; + returned = new Long[] { NBT.getLong(tag) }; break; case 5: - returned = new Object[] { NBT.getFloat(tag) }; + returned = new Float[] { NBT.getFloat(tag) }; break; case 6: - returned = new Object[] { NBT.getDouble(tag) }; + 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 Object[] { NBT.getString(tag) }; + returned = new String[] { NBT.getString(tag) }; break; - case 9: - returned = null; + case 9: //List, will need to make a new type if getCompound() doesn't work here + Bukkit.broadcastMessage("LIST!"); + returned = new Object[] { NBT.getList(tag, 0).toString() }; //Is the int argument the type ID? break; case 10: - returned = new Object[] { NBT.getCompound(tag) }; + returned = new NBTTagCompound[] { NBT.getCompound(tag) }; break; - case 11: - returned = null; + case 11: //Integer array, this one is only used on the chunk files I believe break; default: break; diff --git a/src/me/TheBukor/expressions/ExprVolumeOfSchematic.java b/src/me/TheBukor/expressions/ExprVolumeOfSchematic.java index 532eac1..dc1548e 100644 --- a/src/me/TheBukor/expressions/ExprVolumeOfSchematic.java +++ b/src/me/TheBukor/expressions/ExprVolumeOfSchematic.java @@ -44,15 +44,15 @@ public class ExprVolumeOfSchematic extends SimpleExpression { @Override public String toString(@Nullable Event e, boolean arg1) { - return "the volume of the schematic " + schematic.toString(e, false) + " in the folder " + new String(folder.getSingle(e) != null ? folder.toString(e, false) : "plugins/WorldEdit/schematics"); + return "the volume of the schematic " + schematic.toString(e, false) + " in the folder " + (folder.getSingle(e) == null ? "plugins/WorldEdit/schematics" : folder.toString(e, false)); } @Override @Nullable protected Integer[] get(Event e) { - String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/schematics/"; + String f = (folder.getSingle(e) == null) ? "plugins/WorldEdit/schematics/" : folder.getSingle(e); String schem = schematic.getSingle(e); - File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic")); + File schemFile = new File((f.endsWith("/")) ? f : (f + "/") + (schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); Integer w = 0; Integer h = 0; Integer l = 0; diff --git a/src/me/TheBukor/expressions/ExprWidthOfSchematic.java b/src/me/TheBukor/expressions/ExprWidthOfSchematic.java index a1ec7c0..4f405f8 100644 --- a/src/me/TheBukor/expressions/ExprWidthOfSchematic.java +++ b/src/me/TheBukor/expressions/ExprWidthOfSchematic.java @@ -44,15 +44,15 @@ public class ExprWidthOfSchematic extends SimpleExpression { @Override public String toString(@Nullable Event e, boolean arg1) { - return "the width of the schematic " + schematic.toString(e, false) + " in the folder " + new String(folder.getSingle(e) != null ? folder.toString(e, false) : "plugins/WorldEdit/schematics"); + return "the width of the schematic " + schematic.toString(e, false) + " in the folder " + (folder.getSingle(e) == null ? "plugins/WorldEdit/schematics" : folder.toString(e, false)); } @Override @Nullable protected Integer[] get(Event e) { - String f = (folder.getSingle(e) != null) ? folder.getSingle(e) : "plugins/WorldEdit/schematics/"; + String f = (folder.getSingle(e) == null) ? "plugins/WorldEdit/schematics/" : folder.getSingle(e); String schem = schematic.getSingle(e); - File schemFile = new File((f.endsWith("/")) ? f : f + "/" + new String(schem.endsWith(".schematic") ? schem : schem + ".schematic")); + File schemFile = new File((f.endsWith("/")) ? f : (f + "/") + (schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); Integer w = null; try { w = MCEditSchematicFormat.getFormat(schemFile).load(schemFile).getWidth();