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
This commit is contained in:
Richard 2016-01-21 22:34:26 -02:00
parent e598f81061
commit fde72b0344
14 changed files with 185 additions and 400 deletions

View File

@ -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]

View File

@ -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>(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 {

View File

@ -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<Integer> {
private Expression<String> schematic;
@Override
public Class<? extends Integer> 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<String>) 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() };
}
}

View File

@ -31,7 +31,6 @@ public class ExprFileNBT extends SimpleExpression<Object> {
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<Object> {
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<Object> {
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<Object> {
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();

View File

@ -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<NBTTagCompound> {
private Expression<String> input;
@Override
public Class<? extends NBTTagCompound> 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<String>) 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;
}
}

View File

@ -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<Integer> {
private Expression<String> schematic;
@Override
public Class<? extends Integer> 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<String>) 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 };
}
}

View File

@ -15,13 +15,11 @@ import ch.njol.util.Kleenean;
import me.TheBukor.SkStuff.util.ReflectionUtils;
public class ExprItemNBT extends SimpleExpression<ItemStack> {
private Boolean useParseException = true;
private Expression<ItemStack> itemStack;
private Expression<String> 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<ItemStack> {
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult arg3) {
itemStack = (Expression<ItemStack>) expr[0];
string = (Expression<String>) 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<ItemStack> {
}
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 {

View File

@ -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<Integer> {
private Expression<String> schematic;
@Override
public Class<? extends Integer> 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<String>) 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 };
}
}

View File

@ -26,7 +26,6 @@ public class ExprNBTOf extends SimpleExpression<Object> {
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<Object> {
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<Object> {
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<Object> {
((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();

View File

@ -83,7 +83,7 @@ public class ExprTagOf extends SimpleExpression<Object> {
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<Object> {
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<Object> {
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;

View File

@ -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<String> {
private Expression<String> text;
@Override
public Class<? extends String> 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<String>) 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() };
}
}

View File

@ -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<String> {
private Expression<String> text;
@Override
public Class<? extends String> 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<String>) 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() };
}
}

View File

@ -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<Integer> {
private Expression<String> schematic;
@Override
public Class<? extends Integer> 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<String>) 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 };
}
}

View File

@ -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<String> {
private Expression<String> text;
private Boolean fullyCapitalize = false;
private String toStringEnd;
@Override
public Class<? extends String> 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<String>) 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) };
}
}
}