-
-
Notifications
You must be signed in to change notification settings - Fork 455
SimplifiedCondition #8150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Absolutionism
merged 12 commits into
SkriptLang:dev/feature
from
Absolutionism:dev/SimplifiedCondition
Sep 17, 2025
Merged
SimplifiedCondition #8150
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f6b84c3
Initial Commit
Absolutionism f7cbd86
Suppress for TestMode
Absolutionism 5693eac
Update Condition.java
Absolutionism ef5e1e9
Update Condition.java
Absolutionism 37cf479
Efy's Changes
Absolutionism 71a2060
simplifyWith
Absolutionism 675ebe2
Update src/main/java/ch/njol/skript/lang/SimplifiedCondition.java
Absolutionism b85a5db
remove simplifyWith
Absolutionism dd6269e
Positive Conditions
Absolutionism 808849c
Merge branch 'dev/feature' into dev/SimplifiedCondition
Efnilite f0f2da0
Merge branch 'dev/feature' into dev/SimplifiedCondition
Absolutionism 89839f9
Merge branch 'dev/feature' into dev/SimplifiedCondition
Absolutionism File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
98 changes: 98 additions & 0 deletions
98
src/main/java/ch/njol/skript/lang/SimplifiedCondition.java
This file contains hidden or 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 ch.njol.skript.lang; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.skript.lang.parser.ParserInstance; | ||
| import ch.njol.skript.lang.util.ContextlessEvent; | ||
| import ch.njol.util.Kleenean; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.skriptlang.skript.lang.script.Script; | ||
| import org.skriptlang.skript.lang.script.ScriptWarning; | ||
|
|
||
| /** | ||
| * Represents a condition that can be simplified during initialization. | ||
| */ | ||
| public class SimplifiedCondition extends Condition { | ||
|
|
||
| /** | ||
| * Creates a new {@link SimplifiedCondition} from a {@link Condition} by evaluating it with a {@link ContextlessEvent}. | ||
| * Any expression used by {@code original} that requires specific event data cannot be safely simplified. | ||
| * | ||
| * @param original The original {@link Condition} to simplify. | ||
| * @return A new {@link SimplifiedCondition}. | ||
| */ | ||
| public static Condition fromCondition(Condition original) { | ||
| return fromCondition(original, true); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new {@link SimplifiedCondition} from a {@link Condition} by evaluating it with a {@link ContextlessEvent}. | ||
| * Any expression used by {@code original} that requires specific event data cannot be safely simplified. | ||
| * | ||
| * @param original The original {@link Condition} to simplify. | ||
| * @param warn Whether a warning should be outputted. | ||
|
Absolutionism marked this conversation as resolved.
Outdated
|
||
| * @return A new {@link SimplifiedCondition}. | ||
| */ | ||
| public static Condition fromCondition(Condition original, boolean warn) { | ||
| if (original instanceof SimplifiedCondition simplifiedCondition) | ||
| return simplifiedCondition; | ||
|
|
||
| Event event = ContextlessEvent.get(); | ||
| boolean result = original.check(event); | ||
|
|
||
| if (warn) { | ||
| ParserInstance parser = ParserInstance.get(); | ||
| Script script = parser.isActive() ? parser.getCurrentScript() : null; | ||
| if (script != null && !script.suppressesWarning(ScriptWarning.CONSTANT_CONDITION)) { | ||
| Skript.warning("The condition '" + original + "' will always be " + (result ? "true" : "false") + "."); | ||
|
Absolutionism marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| return new SimplifiedCondition(original, result); | ||
| } | ||
|
|
||
| private final Condition source; | ||
| private final boolean result; | ||
|
|
||
| /** | ||
| * Constructs a new {@link SimplifiedCondition}. | ||
| * | ||
| * @param source The source {@link Condition} this was created from. | ||
| * @param result The evaluated result from {@code source} via {@link Condition#check(Event)}. | ||
| */ | ||
| private SimplifiedCondition(Condition source, boolean result) { | ||
| this.source = source; | ||
| this.result = result; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the source {@link Condition} used to create this {@link SimplifiedCondition}. | ||
| */ | ||
| public Condition getSource() { | ||
| return source; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the result that was evaluated from {@link #source} during initialization. | ||
| */ | ||
| public boolean getResult() { | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean check(Event event) { | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return source.toString(event, debug); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.