-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d84a954
commit 94d93b7
Showing
9 changed files
with
371 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package me.eren.skcheese.elements; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.command.EffectCommandEvent; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.TriggerItem; | ||
import ch.njol.skript.lang.parser.ParserInstance; | ||
import ch.njol.util.Kleenean; | ||
import me.eren.skcheese.SkCheese; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.event.Event; | ||
|
||
public class EffEval extends Effect { | ||
|
||
static { | ||
if (SkCheese.isSyntaxEnabled("eval")) | ||
Skript.registerEffect(EffEval.class, "eval[uate] %strings% [as %-commandsender%]"); | ||
} | ||
|
||
private Expression<String> linesExpression; | ||
private Expression<CommandSender> senderExpression; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
linesExpression = (Expression<String>) exprs[0]; | ||
senderExpression = (Expression<CommandSender>) exprs[1]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(Event event) { | ||
CommandSender sender = this.senderExpression != null ? this.senderExpression.getSingle(event) : Bukkit.getConsoleSender(); | ||
for (String line : linesExpression.getArray(event)) { | ||
ParserInstance parserInstance = ParserInstance.get(); | ||
parserInstance.setCurrentEvent("effect command", EffectCommandEvent.class); | ||
Effect effect = Effect.parse(line, null); | ||
parserInstance.deleteCurrentEvent(); | ||
if (effect != null) { | ||
TriggerItem.walk(effect, new EffectCommandEvent(sender, line)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(Event e, boolean d) { | ||
return "evaluate '" + linesExpression + "' as " + senderExpression; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package me.eren.skcheese.elements; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import me.eren.skcheese.SkCheese; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ExprNumber extends SimpleExpression<Number> { | ||
|
||
private String regex; | ||
private int pattern; | ||
|
||
static { | ||
if (SkCheese.isSyntaxEnabled("binary-and-hex-numbers")) | ||
Skript.registerExpression( | ||
ExprNumber.class, | ||
Number.class, | ||
ExpressionType.SIMPLE, | ||
"0(x|X)<[A-Fa-f0-9]+>", | ||
"0(b|B)<[0-1]+>" | ||
); | ||
} | ||
|
||
@Override | ||
public boolean init(Expression<?> @NotNull [] expressions, int i, @NotNull Kleenean kleenean, SkriptParser.@NotNull ParseResult parseResult) { | ||
pattern = i; | ||
regex = parseResult.regexes.get(0).group(); | ||
return true; | ||
} | ||
|
||
@Override | ||
protected Number @NotNull [] get(@NotNull Event event) { | ||
if (regex == null) return new Number[0]; | ||
Number result = Integer.parseInt(regex, pattern == 0 ? 16 : 2); | ||
return new Number[]{ result }; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public @NotNull Class<? extends Number> getReturnType() { | ||
return Number.class; | ||
} | ||
|
||
@Override | ||
public @NotNull String toString(Event event, boolean b) { | ||
return (pattern == 0 ? "hexadecimal " : "binary ") + regex; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package me.eren.skcheese.elements.bits; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.classes.Changer; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import ch.njol.util.coll.CollectionUtils; | ||
import me.eren.skcheese.SkCheese; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ExprBit extends SimpleExpression<Number> { | ||
|
||
static { | ||
if (SkCheese.isSyntaxEnabled("bit-operations")) | ||
Skript.registerExpression(ExprBit.class, Number.class, ExpressionType.COMBINED, | ||
"[the] %integer%(st|nd|rd|th) bit (in|of) %numbers%", | ||
"bit %integer% (in|of) %numbers%"); | ||
} | ||
|
||
private Expression<Integer> positionExpr; | ||
private Expression<Number> numberExpr; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
positionExpr = (Expression<Integer>) exprs[0]; | ||
numberExpr = (Expression<Number>) exprs[1]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected @Nullable Number[] get(Event e) { | ||
Integer integer = positionExpr.getSingle(e); | ||
if (integer == null) return null; | ||
int pos = integer; | ||
Number[] numbers = numberExpr.getArray(e); | ||
Number[] bits = new Number[numbers.length]; | ||
for (int i = 0; i < numbers.length; i++) { | ||
long num = numbers[i].longValue(); | ||
num >>= (pos - 1); | ||
num &= 1; | ||
bits[i] = num; | ||
} | ||
return bits; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return numberExpr.isSingle(); | ||
} | ||
|
||
@Override | ||
public Class<? extends Number> getReturnType() { | ||
return Number.class; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event e, boolean debug) { | ||
return "bit " + positionExpr.toString(e, debug) + " of " + numberExpr.toString(e, debug); | ||
} | ||
|
||
@Override | ||
public @Nullable Class<?>[] acceptChange(Changer.ChangeMode mode) { | ||
if (mode == Changer.ChangeMode.SET) | ||
return CollectionUtils.array(Boolean.class, Number.class); | ||
return null; | ||
} | ||
|
||
@Override | ||
public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) { | ||
if (delta[0] == null) return; | ||
Integer integer = positionExpr.getSingle(e); | ||
if (integer == null) return; | ||
int pos = integer; | ||
Number[] numbers = numberExpr.getArray(e); | ||
int x; | ||
if (delta[0] instanceof Boolean bool) | ||
x = bool ? 1 : 0; | ||
else x = ((Number) delta[0]).intValue(); | ||
if (x != 1 && x != 0) return; | ||
for (int i = 0; i < numbers.length; i++) { | ||
long num = 1L << (pos - 1); | ||
if (x == 0) { | ||
num = ~num; | ||
num &= numbers[i].longValue(); | ||
} | ||
else { | ||
num |= numbers[i].longValue(); | ||
} | ||
numbers[i] = num; | ||
} | ||
numberExpr.change(e, numbers, Changer.ChangeMode.SET); | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/me/eren/skcheese/elements/bits/ExprBitwise.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package me.eren.skcheese.elements.bits; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.skript.util.LiteralUtils; | ||
import ch.njol.util.Kleenean; | ||
import me.eren.skcheese.SkCheese; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ExprBitwise extends SimpleExpression<Number> { | ||
|
||
private Expression<Number> firstExpression; | ||
private Expression<Number> secondExpression; | ||
|
||
private int pattern; | ||
|
||
static { | ||
if (SkCheese.isSyntaxEnabled("bit-operations")) | ||
Skript.registerExpression( | ||
ExprBitwise.class, Number.class, ExpressionType.COMBINED, | ||
"%number% \\& %number%", | ||
"%number% \\| %number%", | ||
"%number% \\^\\^ %number%", | ||
"\\~%number%" | ||
); | ||
} | ||
|
||
@Override | ||
protected Number @NotNull [] get(@NotNull Event event) { | ||
Number first = this.firstExpression.getSingle(event); | ||
Number second = this.secondExpression != null ? this.secondExpression.getSingle(event) : null; | ||
if (first == null) first = 0; | ||
if (second == null) second = 0; | ||
return switch (pattern) { | ||
case 0 -> new Number[]{ first.intValue() & second.intValue() }; | ||
case 1 -> new Number[]{ first.intValue() | second.intValue() }; | ||
case 2 -> new Number[]{ first.intValue() ^ second.intValue() }; | ||
case 3 -> new Number[]{ ~first.intValue() }; | ||
default -> new Number[0]; | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public @NotNull Class<? extends Number> getReturnType() { | ||
return Number.class; | ||
} | ||
|
||
@Override | ||
public @NotNull String toString(Event event, boolean b) { | ||
return switch (pattern) { | ||
case 0 -> "bitwise AND"; | ||
case 1 -> "bitwise inclusive OR"; | ||
case 2 -> "bitwise exclusive OR"; | ||
case 3 -> "Unary bitwise complement"; | ||
default -> "bitwise operator"; | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean init(Expression<?> @NotNull [] expressions, int i, @NotNull Kleenean kleenean, SkriptParser.@NotNull ParseResult parseResult) { | ||
pattern = i; | ||
firstExpression = LiteralUtils.defendExpression(expressions[0]); | ||
if(pattern != 3) | ||
secondExpression = LiteralUtils.defendExpression(expressions[1]); | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.