New timespan conversion expression, goddamn targetInvocationExceptions.
Might have to debug a little bit to figure out how to let just the warning appear when there's a parse error.
This commit is contained in:
parent
fde72b0344
commit
8e785c04cb
@ -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.2
|
||||
version: 1.4.1.3
|
||||
main: me.TheBukor.SkStuff.SkStuff
|
||||
softdepend: [Skript, WorldEdit]
|
@ -53,6 +53,7 @@ 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.ExprTimespanToNumber;
|
||||
import me.TheBukor.SkStuff.expressions.ExprToLowerCase;
|
||||
import me.TheBukor.SkStuff.expressions.ExprToUpperCase;
|
||||
import me.TheBukor.SkStuff.expressions.ExprVanishState;
|
||||
@ -79,7 +80,8 @@ public class SkStuff extends JavaPlugin {
|
||||
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;
|
||||
Skript.registerExpression(ExprTimespanToNumber.class, Number.class, ExpressionType.SIMPLE, "%timespan% [converted] [in]to (0宇icks|1存ec[ond]s|2妃in[ute]s|3多ours|4圬ays)");
|
||||
exprAmount += 4;
|
||||
|
||||
getLogger().info("Trying to register version specific stuff...");
|
||||
Skript.registerExpression(ExprNBTOf.class, Object.class, ExpressionType.PROPERTY, "nbt[[ ]tag[s]] of %entity/block/itemstack%", "%entity/block/itemstack%'s nbt[[ ]tag[s]]");
|
||||
|
@ -77,6 +77,7 @@ public class ExprFileNBT extends SimpleExpression<Object> {
|
||||
if (ex instanceof InvocationTargetException) {
|
||||
if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) {
|
||||
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
|
||||
return null;
|
||||
}
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -121,6 +122,7 @@ public class ExprFileNBT extends SimpleExpression<Object> {
|
||||
if (ex instanceof InvocationTargetException) {
|
||||
if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) {
|
||||
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
|
||||
return;
|
||||
}
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -148,6 +150,7 @@ public class ExprFileNBT extends SimpleExpression<Object> {
|
||||
if (ex instanceof InvocationTargetException) {
|
||||
if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) {
|
||||
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
|
||||
return;
|
||||
}
|
||||
ex.printStackTrace();
|
||||
} else if (ex instanceof EOFException) {
|
||||
|
@ -71,6 +71,7 @@ public class ExprItemNBT extends SimpleExpression<ItemStack> {
|
||||
} catch (Exception ex) {
|
||||
if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) {
|
||||
Skript.warning(ChatColor.RED + "Error when parsing NBT - " + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Object newItem = null;
|
||||
|
@ -149,6 +149,7 @@ public class ExprNBTOf extends SimpleExpression<Object> {
|
||||
if (ex instanceof InvocationTargetException) {
|
||||
if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) {
|
||||
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
|
||||
return;
|
||||
}
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -207,6 +208,7 @@ public class ExprNBTOf extends SimpleExpression<Object> {
|
||||
if (ex instanceof InvocationTargetException) {
|
||||
if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) {
|
||||
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
|
||||
return;
|
||||
}
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -273,6 +275,7 @@ public class ExprNBTOf extends SimpleExpression<Object> {
|
||||
if (ex instanceof InvocationTargetException) {
|
||||
if (ex.getCause().getClass().getName().equals("MojangsonParseException") ) {
|
||||
Skript.error("Error when parsing NBT - " + ex.getCause().getMessage());
|
||||
return;
|
||||
}
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
@ -0,0 +1,77 @@
|
||||
package me.TheBukor.SkStuff.expressions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import ch.njol.skript.Skript;
|
||||
import ch.njol.skript.lang.Expression;
|
||||
import ch.njol.skript.lang.SkriptParser.ParseResult;
|
||||
import ch.njol.skript.lang.util.SimpleExpression;
|
||||
import ch.njol.skript.util.Timespan;
|
||||
import ch.njol.util.Kleenean;
|
||||
|
||||
public class ExprTimespanToNumber extends SimpleExpression<Number> {
|
||||
private Expression<Timespan> time;
|
||||
private String toStringMark;
|
||||
private int mark;
|
||||
|
||||
@Override
|
||||
public Class<? extends Number> getReturnType() {
|
||||
return Number.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean init(Expression<?>[] expr, int matchedPattern, Kleenean arg2, ParseResult result) {
|
||||
time = (Expression<Timespan>) expr[0];
|
||||
mark = result.mark;
|
||||
if (result.mark == 0) {
|
||||
toStringMark = "ticks";
|
||||
} else if (result.mark == 1) {
|
||||
toStringMark = "seconds";
|
||||
} else if (result.mark == 2) {
|
||||
toStringMark = "minutes";
|
||||
} else if (result.mark == 3) {
|
||||
toStringMark = "hours";
|
||||
} else if (result.mark == 4) {
|
||||
toStringMark = "days";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable Event e, boolean arg1) {
|
||||
return time.toString(e, false) + "converted to " + toStringMark;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Nullable
|
||||
protected Number[] get(Event e) {
|
||||
Timespan t = time.getSingle(e);
|
||||
Number ticks = null;
|
||||
if (Skript.methodExists(Timespan.class, "getTicks_i")) { //Compatibility with Mirreducki's Skript patch 24+ days timespans.
|
||||
ticks = t.getTicks_i();
|
||||
} else { //Standard Skript timespans, limited to roughly 24 days.
|
||||
ticks = t.getTicks();
|
||||
}
|
||||
if (mark == 0) {
|
||||
return new Number[] { ticks };
|
||||
} else if (mark == 1) {
|
||||
return new Number[] { ticks.longValue() / 20 };
|
||||
} else if (mark == 2) {
|
||||
return new Number[] { ticks.longValue() / 20 / 60 };
|
||||
} else if (mark == 3) {
|
||||
return new Number[] { ticks.longValue() / 20 / 60 / 60 };
|
||||
} else if (mark == 4) {
|
||||
return new Number[] { ticks.longValue() / 20 / 60 / 60 / 24 };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user