-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Added some control to the outer event in a listen once section
- Loading branch information
Showing
4 changed files
with
198 additions
and
3 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/info/itsthesky/disky/elements/sections/once/EffOuterExecution.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,50 @@ | ||
package info.itsthesky.disky.elements.sections.once; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.Variable; | ||
import ch.njol.skript.variables.Variables; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class EffOuterExecution extends Effect { | ||
|
||
static { | ||
Skript.registerEffect( | ||
EffOuterExecution.class, | ||
"outer <.+>" | ||
); | ||
} | ||
|
||
private SecListenOnce secListenOnce; | ||
private Effect effect; | ||
|
||
@Override | ||
public boolean init(Expression<?> @NotNull [] expressions, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { | ||
secListenOnce = getParser().getCurrentSection(SecListenOnce.class); | ||
if (secListenOnce == null) { | ||
Skript.error("The 'outer' effect can only be used in a 'listen once' section."); | ||
return false; | ||
} | ||
|
||
final String rawEffect = parseResult.regexes.get(0).group(); | ||
return secListenOnce.executeInOuter(() -> { | ||
effect = Effect.parse(rawEffect, "Can't understand this effect: " + rawEffect); | ||
return true; | ||
}); | ||
} | ||
|
||
@Override | ||
protected void execute(@NotNull Event event) { | ||
effect.run(secListenOnce.getOuterEvent()); | ||
} | ||
|
||
@Override | ||
public @NotNull String toString(@Nullable Event event, boolean debug) { | ||
return "outer " + effect.toString(event, debug); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/info/itsthesky/disky/elements/sections/once/ExprOuterExpression.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,65 @@ | ||
package info.itsthesky.disky.elements.sections.once; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.ParseContext; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ExprOuterExpression extends SimpleExpression<Object> { | ||
|
||
// static { | ||
// Skript.registerExpression( | ||
// ExprOuterExpression.class, | ||
// Object.class, | ||
// ExpressionType.COMBINED, | ||
// "[the] outer <.+>" | ||
// ); | ||
// } | ||
|
||
private Expression<?> expr; | ||
private SecListenOnce secListenOnce; | ||
|
||
@Override | ||
public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { | ||
secListenOnce = getParser().getCurrentSection(SecListenOnce.class); | ||
if (secListenOnce == null) { | ||
Skript.error("The 'outer' expression can only be used in a 'listen once' section."); | ||
return false; | ||
} | ||
|
||
var rawExpression = parseResult.regexes.get(0).group(); | ||
expr = new SkriptParser(rawExpression, SkriptParser.PARSE_LITERALS, ParseContext.DEFAULT).parseExpression(Object.class); | ||
if (expr == null) { | ||
Skript.error("Cannot parse the given expression: " + rawExpression); | ||
return false; | ||
} | ||
|
||
return secListenOnce.executeInOuter(() -> expr.init(exprs, matchedPattern, isDelayed, parseResult)); | ||
} | ||
|
||
@Override | ||
protected Object @NotNull [] get(@NotNull Event event) { | ||
return expr.getArray(secListenOnce.getOuterEvent()); | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return expr.isSingle(); | ||
} | ||
|
||
@Override | ||
public @NotNull Class<?> getReturnType() { | ||
return expr.getReturnType(); | ||
} | ||
|
||
@Override | ||
public @NotNull String toString(@Nullable Event event, boolean debug) { | ||
return "the outer " + expr.toString(event, debug); | ||
} | ||
} |
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