From fde72b034441ec1e42a83c6966d13b920c979e9a Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 21 Jan 2016 22:34:26 -0200 Subject: [PATCH] New string expressions, fixes to schem/selection size expressions, ... removed some unused classes, stacktraces no longer appear when there's a NBT parse error, only a message should appear instead --- plugin.yml | 2 +- src/me/TheBukor/SkStuff/SkStuff.java | 42 +++--- .../expressions/ExprAreaOfSchematic.java | 58 -------- .../SkStuff/expressions/ExprFileNBT.java | 7 +- .../expressions/ExprFileNBTv1_8_R3.java | 131 ------------------ .../expressions/ExprHeightOfSchematic.java | 57 -------- .../SkStuff/expressions/ExprItemNBT.java | 11 +- .../expressions/ExprLengthOfSchematic.java | 57 -------- .../SkStuff/expressions/ExprNBTOf.java | 7 +- .../SkStuff/expressions/ExprTagOf.java | 14 +- .../SkStuff/expressions/ExprToLowerCase.java | 43 ++++++ .../SkStuff/expressions/ExprToUpperCase.java | 43 ++++++ .../expressions/ExprWidthOfSchematic.java | 57 -------- .../expressions/ExprWordsToUpperCase.java | 56 ++++++++ 14 files changed, 185 insertions(+), 400 deletions(-) delete mode 100644 src/me/TheBukor/SkStuff/expressions/ExprAreaOfSchematic.java delete mode 100644 src/me/TheBukor/SkStuff/expressions/ExprFileNBTv1_8_R3.java delete mode 100644 src/me/TheBukor/SkStuff/expressions/ExprHeightOfSchematic.java delete mode 100644 src/me/TheBukor/SkStuff/expressions/ExprLengthOfSchematic.java create mode 100644 src/me/TheBukor/SkStuff/expressions/ExprToLowerCase.java create mode 100644 src/me/TheBukor/SkStuff/expressions/ExprToUpperCase.java delete mode 100644 src/me/TheBukor/SkStuff/expressions/ExprWidthOfSchematic.java create mode 100644 src/me/TheBukor/SkStuff/expressions/ExprWordsToUpperCase.java diff --git a/plugin.yml b/plugin.yml index 0089fec..9b0c5f9 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: SkStuff author: TheBukor description: A Skript addon which adds extra functionalities such as NBT and extended WorldEdit support. -version: 1.4.1.1 +version: 1.4.1.2 main: me.TheBukor.SkStuff.SkStuff softdepend: [Skript, WorldEdit] \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/SkStuff.java b/src/me/TheBukor/SkStuff/SkStuff.java index c159204..ea74e4f 100644 --- a/src/me/TheBukor/SkStuff/SkStuff.java +++ b/src/me/TheBukor/SkStuff/SkStuff.java @@ -53,28 +53,35 @@ import me.TheBukor.SkStuff.expressions.ExprSelectionArea; import me.TheBukor.SkStuff.expressions.ExprSelectionOfPlayer; import me.TheBukor.SkStuff.expressions.ExprSelectionPos; import me.TheBukor.SkStuff.expressions.ExprTagOf; +import me.TheBukor.SkStuff.expressions.ExprToLowerCase; +import me.TheBukor.SkStuff.expressions.ExprToUpperCase; import me.TheBukor.SkStuff.expressions.ExprVanishState; +import me.TheBukor.SkStuff.expressions.ExprWordsToUpperCase; import me.TheBukor.SkStuff.util.ReflectionUtils; public class SkStuff extends JavaPlugin { private int condAmount = 0; - private int exprAmount = 0; - private int typeAmount = 0; private int effAmount = 0; private boolean evtWE = false; + private int exprAmount = 0; + private int typeAmount = 0; private Class nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound"); private Class nbtParserClass = ReflectionUtils.getNMSClass("MojangsonParser"); - private Class nbtParseExClass = ReflectionUtils.getNMSClass("MojangsonParseException"); - @SuppressWarnings({ "unchecked" }) + @SuppressWarnings("unchecked") public void onEnable() { if (Bukkit.getPluginManager().getPlugin("Skript") != null && Skript.isAcceptRegistrations()) { Skript.registerAddon(this); getLogger().info("SkStuff " + this.getDescription().getVersion() + " has been successfully enabled!"); + + getLogger().info("Registering general non version specific stuff..."); + Skript.registerExpression(ExprToUpperCase.class, String.class, ExpressionType.SIMPLE, "%string% [converted] to [all] (cap[ital]s|upper[ ]case)", "convert %string% to [all] (cap[ital]s|upper[ ]case)", "capitalize [all] [char[acter]s (of|in)] %string%"); + Skript.registerExpression(ExprToLowerCase.class, String.class, ExpressionType.SIMPLE, "%string% [converted] to [all] lower[ ]case", "convert %string% to [all] lower[ ]case", "un[( |-)]capitalize [all] [char[acter]s (of|in)] %string%"); + Skript.registerExpression(ExprWordsToUpperCase.class, String.class, ExpressionType.SIMPLE, "(first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% [converted] to (cap[ital]s|upper[ ]case) (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])", "convert (first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% to (cap[ital]s|upper[ ]case) (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])", "capitalize (first|1st) (letter|char[acter]) (of|in) (each word|[all] words) (of|in) %string% (0¦|1¦ignoring [other] upper[ ]case [(char[acter]s|letters)])"); + exprAmount += 3; + getLogger().info("Trying to register version specific stuff..."); - typeAmount += 1; - exprAmount += 6; Skript.registerExpression(ExprNBTOf.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]"); Skript.registerExpression(ExprItemNBT.class, ItemStack.class, ExpressionType.SIMPLE, "%itemstack% with [custom] nbt[[ ]tag[s]] %string%"); Skript.registerExpression(ExprTagOf.class, Object.class, ExpressionType.PROPERTY, "[nbt[ ]]tag %string% of [[nbt] compound] %compound%"); @@ -114,8 +121,9 @@ public class SkStuff extends JavaPlugin { } } catch (Exception ex) { if (ex instanceof InvocationTargetException) { - if (ex.getCause().getClass().equals(nbtParseExClass) ) { + if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) { Skript.error("Error when parsing NBT - " + ex.getCause().getMessage()); + return; } ex.printStackTrace(); } @@ -154,7 +162,7 @@ public class SkStuff extends JavaPlugin { nbtClass.getMethod("a", nbtClass).invoke(NBT, NBT1); } catch (Exception ex) { if (ex instanceof InvocationTargetException) { - if (ex.getCause().getClass().equals(nbtParseExClass) ) { + if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) { return null; } ex.printStackTrace(); @@ -179,12 +187,10 @@ public class SkStuff extends JavaPlugin { return "nbt:" + compound.toString(); } })); + typeAmount += 1; + exprAmount += 6; if (Bukkit.getPluginManager().getPlugin("WorldEdit") != null) { getLogger().info("WorldEdit found! Registering WorldEdit stuff..."); - condAmount += 1; - effAmount += 12; - exprAmount += 7; - 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(EffDrawLineWE.class, "(create|draw|make) [a[n]] (0¦(no(n|t)(-| )hollow|filled|)|1¦hollow) line from %location% to %location% (using|with) [edit[ ]session] %editsession% (using|with) [block[s]] %itemstacks% [with] thick[ness] %double%"); Skript.registerEffect(EffUndoRedoSession.class, "(0¦undo|1¦redo) (change|edit)s (of|from) [edit[ ]session] %editsession%"); @@ -203,8 +209,8 @@ public class SkStuff extends JavaPlugin { Skript.registerExpression(ExprNewEditSession.class, EditSession.class, ExpressionType.PROPERTY, "[new] edit[ ]session in [world] %world% [with] [max[imum]] [block] limit [change] [of] %integer%"); Skript.registerExpression(ExprSelectionOfPlayer.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection"); Skript.registerExpression(ExprSelectionPos.class, Location.class, ExpressionType.PROPERTY, "[(world[ ]edit|we)] po(s|int)[ ](0¦1|1¦2) of %player%", "%player%'s [(world[ ]edit|we)] po(s|int)[ ](0¦1|1¦2)"); - Skript.registerExpression(ExprSelectionArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)3¦(z( |-)size|length)4¦area) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection (0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)3¦(z( |-)size|length)4¦area)"); - Skript.registerExpression(ExprSchematicArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)3¦(z( |-)size|length)4¦area) of schem[atic] [from] %string%"); + Skript.registerExpression(ExprSelectionArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area) of [(world[ ]edit|we)] selection of %player%", "%player%'s [(world[ ]edit|we)] selection (0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area)"); + Skript.registerExpression(ExprSchematicArea.class, Integer.class, ExpressionType.SIMPLE, "(0¦volume|1¦(x( |-)size|width)|2¦(y( |-)size|height)|3¦(z( |-)size|length)|4¦area) of schem[atic] [from] %string%"); Classes.registerClass(new ClassInfo(EditSession.class, "editsession").name("Edit Session").user("edit ?sessions?")); try { Class.forName("com.sk89q.worldedit.extent.logging.AbstractLoggingExtent"); @@ -228,13 +234,17 @@ public class SkStuff extends JavaPlugin { } catch (ClassNotFoundException ex) { Skript.error("Unable to register \"On WorldEdit block change\" event! You will need to upgrade to WorldEdit 6.0"); } + condAmount += 1; + effAmount += 12; + exprAmount += 7; + typeAmount += 1; } if (Bukkit.getPluginManager().getPlugin("VanishNoPacket") != null) { getLogger().info("VanishNoPacket was found! Registering vanishing features..."); - effAmount += 1; - exprAmount += 1; Skript.registerEffect(EffToggleVanish.class, "toggle vanish (state|mode) of %player% (0¦|1¦(silently|quietly))", "toggle %player%'s vanish (state|mode) (0¦|1¦(silently|quietly))"); Skript.registerExpression(ExprVanishState.class, Boolean.class, ExpressionType.PROPERTY, "vanish (state|mode) of %player%", "%player%'s vanish (state|mode)"); + effAmount += 1; + exprAmount += 1; } getLogger().info("Everything ready! Loaded a total of " + condAmount + (condAmount == 1 ? " condition, " : " conditions, ") + effAmount + (effAmount == 1 ? " effect, " : " effects, ") + (evtWE ? "1 event, " : "") + exprAmount + (exprAmount == 1 ? " expression" : " expressions and ") + typeAmount + (typeAmount == 1 ? " type!" : " types!")); } else { diff --git a/src/me/TheBukor/SkStuff/expressions/ExprAreaOfSchematic.java b/src/me/TheBukor/SkStuff/expressions/ExprAreaOfSchematic.java deleted file mode 100644 index 1464068..0000000 --- a/src/me/TheBukor/SkStuff/expressions/ExprAreaOfSchematic.java +++ /dev/null @@ -1,58 +0,0 @@ -package me.TheBukor.SkStuff.expressions; - -import java.io.File; -import java.io.IOException; - -import javax.annotation.Nullable; - -import org.bukkit.event.Event; - -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.schematic.MCEditSchematicFormat; -import com.sk89q.worldedit.world.DataException; - -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 ExprAreaOfSchematic extends SimpleExpression { - private Expression schematic; - - @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]; - return true; - } - - @Override - public String toString(@Nullable Event e, boolean arg1) { - return "the area of the schematic from " + schematic.toString(e, false); - } - - @Override - @Nullable - protected Integer[] get(Event e) { - String schem = schematic.getSingle(e); - File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); - Region region = null; - try { - region = ((Clipboard) MCEditSchematicFormat.getFormat(schemFile).load(schemFile)).getRegion(); - } catch (DataException | IOException ex) { - return null; - } - return new Integer[] { region.getWidth() * region.getLength() }; - } -} \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/expressions/ExprFileNBT.java b/src/me/TheBukor/SkStuff/expressions/ExprFileNBT.java index 948b10c..0f435a1 100644 --- a/src/me/TheBukor/SkStuff/expressions/ExprFileNBT.java +++ b/src/me/TheBukor/SkStuff/expressions/ExprFileNBT.java @@ -31,7 +31,6 @@ public class ExprFileNBT extends SimpleExpression { private Class nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase"); private Class nbtToolsClass = ReflectionUtils.getNMSClass("NBTCompressedStreamTools"); private Class nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound"); - private Class nbtParseExClass = ReflectionUtils.getNMSClass("MojangsonParseException"); private Class nbtParserClass = ReflectionUtils.getNMSClass("MojangsonParser"); @Override @@ -76,7 +75,7 @@ public class ExprFileNBT extends SimpleExpression { fis.close(); } catch (Exception ex) { if (ex instanceof InvocationTargetException) { - if (ex.getCause().getClass().equals(nbtParseExClass)) { + if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) { Skript.error("Error when parsing NBT - " + ex.getCause().getMessage()); } ex.printStackTrace(); @@ -120,7 +119,7 @@ public class ExprFileNBT extends SimpleExpression { os.close(); } catch (Exception ex) { if (ex instanceof InvocationTargetException) { - if (ex.getCause().getClass().equals(nbtParseExClass) ) { + if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) { Skript.error("Error when parsing NBT - " + ex.getCause().getMessage()); } ex.printStackTrace(); @@ -147,7 +146,7 @@ public class ExprFileNBT extends SimpleExpression { os.close(); } catch (Exception ex) { if (ex instanceof InvocationTargetException) { - if (ex.getCause().getClass().equals(nbtParseExClass)) { + if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) { Skript.error("Error when parsing NBT - " + ex.getCause().getMessage()); } ex.printStackTrace(); diff --git a/src/me/TheBukor/SkStuff/expressions/ExprFileNBTv1_8_R3.java b/src/me/TheBukor/SkStuff/expressions/ExprFileNBTv1_8_R3.java deleted file mode 100644 index eca1e9b..0000000 --- a/src/me/TheBukor/SkStuff/expressions/ExprFileNBTv1_8_R3.java +++ /dev/null @@ -1,131 +0,0 @@ -package me.TheBukor.SkStuff.expressions; - -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.zip.ZipException; - -import javax.annotation.Nullable; - -import org.bukkit.Bukkit; -import org.bukkit.event.Event; - -import ch.njol.skript.Skript; -import ch.njol.skript.classes.Changer.ChangeMode; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser.ParseResult; -import ch.njol.skript.lang.util.SimpleExpression; -import ch.njol.util.Kleenean; -import ch.njol.util.coll.CollectionUtils; -import net.minecraft.server.v1_8_R3.MojangsonParseException; -import net.minecraft.server.v1_8_R3.MojangsonParser; -import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools; -import net.minecraft.server.v1_8_R3.NBTTagCompound; - -public class ExprFileNBTv1_8_R3 extends SimpleExpression { - private Expression input; - - @Override - public Class getReturnType() { - return NBTTagCompound.class; - } - - @Override - public boolean isSingle() { - return true; - } - - @SuppressWarnings("unchecked") - @Override - public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { - input = (Expression) expr[0]; - return true; - } - - @Override - public String toString(@Nullable Event e, boolean arg1) { - return "the NBT of file from file " + input.toString(e, false); - } - - @Override - @Nullable - protected NBTTagCompound[] get(Event e) { - NBTTagCompound NBT = null; - File file = new File(input.getSingle(e)); - if (file.exists()) { - try { - InputStream fis = new FileInputStream(file); - NBT = NBTCompressedStreamTools.a(fis); - fis.close(); - } catch (EOFException ex) { - //End of file, no error. - } catch (ZipException ex) { - return null; //Not a valid file (not compressed in GZIP format) - } catch (IOException ex) { - ex.printStackTrace(); - } - } else { - return null; // Specified file doesn't exist - } - return new NBTTagCompound[] { NBT }; - } - - @Override - public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { - File file = new File(input.getSingle(e)); - String tags = (String) delta[0]; - if (mode == ChangeMode.ADD) { - try { - InputStream fis = new FileInputStream(file); - NBTTagCompound NBT = NBTCompressedStreamTools.a(fis); - OutputStream os = new FileOutputStream(file); - NBTTagCompound NBT1 = MojangsonParser.parse(tags); - NBT.a(NBT1); - NBTCompressedStreamTools.a(NBT, os); - Bukkit.broadcastMessage("First - " + NBT.toString() + "\n\nSecond: " + NBT1.toString()); - fis.close(); - os.close(); - } catch (EOFException ex) { - //End of file, no error. - } catch (ZipException ex) { - return; //Not a valid file (not compressed in GZIP format) - } catch (IOException ex) { - ex.printStackTrace(); - } catch (MojangsonParseException ex) { - Skript.warning("Error when parsing NBT - " + ex.getMessage()); - } - } else if (mode == ChangeMode.REMOVE) { - try { - InputStream fis = new FileInputStream(file); - NBTTagCompound NBT = NBTCompressedStreamTools.a(fis); - Bukkit.broadcastMessage("First - " + NBT.toString()); - OutputStream os = new FileOutputStream(file); - NBT.remove(tags); - NBTCompressedStreamTools.a(NBT, os); - Bukkit.broadcastMessage("\n\nSecond: " + NBT.toString()); - fis.close(); - os.close(); - } catch (EOFException ex) { - //End of file, no error. - } catch (ZipException ex) { - return; //Not a valid file (not compressed in GZIP format) - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - - @SuppressWarnings("unchecked") - @Override - @Nullable - public Class[] acceptChange(ChangeMode mode) { - if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) { - return CollectionUtils.array(String.class); - } - return null; - } -} \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/expressions/ExprHeightOfSchematic.java b/src/me/TheBukor/SkStuff/expressions/ExprHeightOfSchematic.java deleted file mode 100644 index 70ab12b..0000000 --- a/src/me/TheBukor/SkStuff/expressions/ExprHeightOfSchematic.java +++ /dev/null @@ -1,57 +0,0 @@ -package me.TheBukor.SkStuff.expressions; - -import java.io.File; -import java.io.IOException; - -import javax.annotation.Nullable; - -import org.bukkit.event.Event; - -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.schematic.MCEditSchematicFormat; -import com.sk89q.worldedit.world.DataException; - -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 ExprHeightOfSchematic extends SimpleExpression { - private Expression schematic; - - @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]; - return true; - } - - @Override - public String toString(@Nullable Event e, boolean arg1) { - return "the height of the schematic from " + schematic.toString(e, false); - } - - @Override - @Nullable - protected Integer[] get(Event e) { - String schem = schematic.getSingle(e); - File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); - Integer h = null; - try { - h = ((Clipboard) MCEditSchematicFormat.getFormat(schemFile).load(schemFile)).getRegion().getHeight(); - } catch (DataException | IOException ex) { - return null; - } - return new Integer[] { h }; - } -} \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/expressions/ExprItemNBT.java b/src/me/TheBukor/SkStuff/expressions/ExprItemNBT.java index c6c164d..bae0859 100644 --- a/src/me/TheBukor/SkStuff/expressions/ExprItemNBT.java +++ b/src/me/TheBukor/SkStuff/expressions/ExprItemNBT.java @@ -15,13 +15,11 @@ import ch.njol.util.Kleenean; import me.TheBukor.SkStuff.util.ReflectionUtils; public class ExprItemNBT extends SimpleExpression { - private Boolean useParseException = true; private Expression itemStack; private Expression string; private Class nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound"); private Class nbtParseClass = ReflectionUtils.getNMSClass("MojangsonParser"); - private Class nbtParseExClass = ReflectionUtils.getNMSClass("MojangsonParseException"); private Class nmsItemClass = ReflectionUtils.getNMSClass("ItemStack"); private Class craftItemClass = ReflectionUtils.getOBCClass("inventory.CraftItemStack"); @@ -41,10 +39,6 @@ public class ExprItemNBT extends SimpleExpression { public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { itemStack = (Expression) expr[0]; string = (Expression) expr[1]; - String bukkitVersion = ReflectionUtils.getVersion(); - if (bukkitVersion.contains("v1_7_R") || bukkitVersion.equals("v1_8_R1")) { - useParseException = false; - } return true; } @@ -75,8 +69,9 @@ public class ExprItemNBT extends SimpleExpression { } nmsItem.getClass().getMethod("setTag", nbtClass).invoke(nmsItem, NBT); } catch (Exception ex) { - if (useParseException && ex.getClass().equals(nbtParseExClass)) - Skript.warning(ChatColor.RED + "Error when parsing NBT - " + ex.getMessage()); + if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) { + Skript.warning(ChatColor.RED + "Error when parsing NBT - " + ex.getMessage()); + } } Object newItem = null; try { diff --git a/src/me/TheBukor/SkStuff/expressions/ExprLengthOfSchematic.java b/src/me/TheBukor/SkStuff/expressions/ExprLengthOfSchematic.java deleted file mode 100644 index 786ed1b..0000000 --- a/src/me/TheBukor/SkStuff/expressions/ExprLengthOfSchematic.java +++ /dev/null @@ -1,57 +0,0 @@ -package me.TheBukor.SkStuff.expressions; - -import java.io.File; -import java.io.IOException; - -import javax.annotation.Nullable; - -import org.bukkit.event.Event; - -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.schematic.MCEditSchematicFormat; -import com.sk89q.worldedit.world.DataException; - -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 ExprLengthOfSchematic extends SimpleExpression { - private Expression schematic; - - @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]; - return true; - } - - @Override - public String toString(@Nullable Event e, boolean arg1) { - return "the length of the schematic from " + schematic.toString(e, false); - } - - @Override - @Nullable - protected Integer[] get(Event e) { - String schem = schematic.getSingle(e); - File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); - Integer l = null; - try { - l = ((Clipboard) MCEditSchematicFormat.getFormat(schemFile).load(schemFile)).getRegion().getLength(); - } catch (DataException | IOException ex) { - return null; - } - return new Integer[] { l }; - } -} \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java b/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java index ca62ae0..3659516 100644 --- a/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java +++ b/src/me/TheBukor/SkStuff/expressions/ExprNBTOf.java @@ -26,7 +26,6 @@ public class ExprNBTOf extends SimpleExpression { private Class nbtBaseClass = ReflectionUtils.getNMSClass("NBTBase"); private Class nbtClass = ReflectionUtils.getNMSClass("NBTTagCompound"); - private Class nbtParseExClass = ReflectionUtils.getNMSClass("MojangsonParseException"); private Class nbtParserClass = ReflectionUtils.getNMSClass("MojangsonParser"); private Class nmsPosClass = ReflectionUtils.getNMSClass("BlockPosition"); private Class nmsItemClass = ReflectionUtils.getNMSClass("ItemStack"); @@ -148,7 +147,7 @@ public class ExprNBTOf extends SimpleExpression { nmsEnt.getClass().getMethod("f", nbtClass).invoke(nmsEnt, NBT); } catch (Exception ex) { if (ex instanceof InvocationTargetException) { - if (ex.getCause().getClass().equals(nbtParseExClass) ) { + if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) { Skript.error("Error when parsing NBT - " + ex.getCause().getMessage()); } ex.printStackTrace(); @@ -206,7 +205,7 @@ public class ExprNBTOf extends SimpleExpression { nmsWorld.getClass().getMethod("notify", nmsPosClass).invoke(nmsWorld, tileEntity.getClass().getMethod("getPosition").invoke(tileEntity)); } catch (Exception ex) { if (ex instanceof InvocationTargetException) { - if (ex.getCause().getClass().equals(nbtParseExClass) ) { + if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) { Skript.error("Error when parsing NBT - " + ex.getCause().getMessage()); } ex.printStackTrace(); @@ -272,7 +271,7 @@ public class ExprNBTOf extends SimpleExpression { ((Slot) slot[0]).setItem((ItemStack) newItem); } catch (Exception ex) { if (ex instanceof InvocationTargetException) { - if (ex.getCause().getClass().equals(nbtParseExClass) ) { + if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) { Skript.error("Error when parsing NBT - " + ex.getCause().getMessage()); } ex.printStackTrace(); diff --git a/src/me/TheBukor/SkStuff/expressions/ExprTagOf.java b/src/me/TheBukor/SkStuff/expressions/ExprTagOf.java index d2637cd..7719ed0 100644 --- a/src/me/TheBukor/SkStuff/expressions/ExprTagOf.java +++ b/src/me/TheBukor/SkStuff/expressions/ExprTagOf.java @@ -83,7 +83,7 @@ public class ExprTagOf extends SimpleExpression { Object list = null; for (i = 1; i <= 11; i++) { //To get a list I need to know the type of the tags it contains inside, //since I can't predict what type the list will have, I just loop all of the IDs until I find a non-empty list. - list = NBT.getClass().getMethod("getList", String.class, int.class).invoke(NBT, stringTag, i); + list = NBT.getClass().getMethod("getList", String.class, int.class).invoke(NBT, stringTag, i); //Try to get the list with the ID "loop-number". if (!list.toString().equals("[]")) { //If list is not empty. break; //Stop loop. } @@ -91,19 +91,19 @@ public class ExprTagOf extends SimpleExpression { String methodName = null; switch (((int) list.getClass().getMethod("f").invoke(list))) { //list.f() gets the type of the tags in the list. case 5: //Float - methodName = "e"; + methodName = "e"; //list.e(int) = get float from the specified index. break; case 6: //Double - methodName = "d"; + methodName = "d"; //list.d(int) = get double from the specified index. break; case 8: //String - methodName = "getString"; + methodName = "getString"; //Self-explanatory, I guess. break; case 10: //Compound - methodName = "get"; + methodName = "get"; //list.get(int) = get compound at the specified index. break; case 11: //Integer array - methodName = "c"; + methodName = "c"; //Not sure if ever used, but meh. break; default: break; @@ -117,7 +117,7 @@ public class ExprTagOf extends SimpleExpression { return tags; case 10: return new Object[] { NBT.getClass().getMethod("getCompound", String.class).invoke(NBT, stringTag) }; - case 11: //Integer array, this one is only used on the chunk files. + case 11: //Integer array, this one is only used on the chunk files (and maybe schematic files?). return new Object[] { NBT.getClass().getMethod("getIntArray", String.class).invoke(NBT, stringTag).toString() }; default: //This shouldn't happen, but it's better to have this just in case it spills errors everywhere. break; diff --git a/src/me/TheBukor/SkStuff/expressions/ExprToLowerCase.java b/src/me/TheBukor/SkStuff/expressions/ExprToLowerCase.java new file mode 100644 index 0000000..69cb21b --- /dev/null +++ b/src/me/TheBukor/SkStuff/expressions/ExprToLowerCase.java @@ -0,0 +1,43 @@ +package me.TheBukor.SkStuff.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; + +public class ExprToLowerCase extends SimpleExpression { + private Expression text; + + @Override + public Class getReturnType() { + return String.class; + } + + @Override + public boolean isSingle() { + return true; + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + text = (Expression) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "convert all characters in " + text.toString(e, false) + " to lowercase"; + } + + @Override + @Nullable + protected String[] get(Event e) { + String s = text.getSingle(e); + return new String[] { s.toLowerCase() }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/expressions/ExprToUpperCase.java b/src/me/TheBukor/SkStuff/expressions/ExprToUpperCase.java new file mode 100644 index 0000000..9c07e31 --- /dev/null +++ b/src/me/TheBukor/SkStuff/expressions/ExprToUpperCase.java @@ -0,0 +1,43 @@ +package me.TheBukor.SkStuff.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; + +public class ExprToUpperCase extends SimpleExpression { + private Expression text; + + @Override + public Class getReturnType() { + return String.class; + } + + @Override + public boolean isSingle() { + return true; + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) { + text = (Expression) expr[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "convert all characters in " + text.toString(e, false) + " to uppercase"; + } + + @Override + @Nullable + protected String[] get(Event e) { + String s = text.getSingle(e); + return new String[] { s.toUpperCase() }; + } +} \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/expressions/ExprWidthOfSchematic.java b/src/me/TheBukor/SkStuff/expressions/ExprWidthOfSchematic.java deleted file mode 100644 index 3feb00c..0000000 --- a/src/me/TheBukor/SkStuff/expressions/ExprWidthOfSchematic.java +++ /dev/null @@ -1,57 +0,0 @@ -package me.TheBukor.SkStuff.expressions; - -import java.io.File; -import java.io.IOException; - -import javax.annotation.Nullable; - -import org.bukkit.event.Event; - -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.schematic.MCEditSchematicFormat; -import com.sk89q.worldedit.world.DataException; - -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 ExprWidthOfSchematic extends SimpleExpression { - private Expression schematic; - - @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]; - return true; - } - - @Override - public String toString(@Nullable Event e, boolean arg1) { - return "the height of the schematic from " + schematic.toString(e, false); - } - - @Override - @Nullable - protected Integer[] get(Event e) { - String schem = schematic.getSingle(e); - File schemFile = new File((schem.endsWith(".schematic") ? schem : (schem + ".schematic"))); - Integer w = null; - try { - w = ((Clipboard) MCEditSchematicFormat.getFormat(schemFile).load(schemFile)).getRegion().getWidth(); - } catch (DataException | IOException ex) { - return null; - } - return new Integer[] { w }; - } -} \ No newline at end of file diff --git a/src/me/TheBukor/SkStuff/expressions/ExprWordsToUpperCase.java b/src/me/TheBukor/SkStuff/expressions/ExprWordsToUpperCase.java new file mode 100644 index 0000000..d93e228 --- /dev/null +++ b/src/me/TheBukor/SkStuff/expressions/ExprWordsToUpperCase.java @@ -0,0 +1,56 @@ +package me.TheBukor.SkStuff.expressions; + +import javax.annotation.Nullable; + +import org.apache.commons.lang.WordUtils; +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; + +public class ExprWordsToUpperCase extends SimpleExpression { + private Expression text; + private Boolean fullyCapitalize = false; + private String toStringEnd; + + @Override + public Class getReturnType() { + return String.class; + } + + @Override + public boolean isSingle() { + return true; + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expr, int matchedPattern, Kleenean arg2, ParseResult result) { + text = (Expression) expr[0]; + if (result.mark == 0) { + toStringEnd = " to uppercase"; + } else { + fullyCapitalize = true; + toStringEnd = " to uppercase ignoring other uppercase characters"; + } + return true; + } + + @Override + public String toString(@Nullable Event e, boolean arg1) { + return "convert first character of each word in " + text.toString(e, false) + toStringEnd; + } + + @Override + @Nullable + protected String[] get(Event e) { + String s = text.getSingle(e); + if (fullyCapitalize) { + return new String[] { WordUtils.capitalizeFully(s) }; + } else { + return new String[] { WordUtils.capitalize(s) }; + } + } +} \ No newline at end of file