forked from SkriptLang/Skript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev/feature' into feature/registry-classes
- Loading branch information
Showing
13 changed files
with
1,179 additions
and
179 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
src/main/java/ch/njol/skript/conditions/CondIsUsingFeature.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,81 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package ch.njol.skript.conditions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Condition; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.skriptlang.skript.lang.experiment.Experimented; | ||
|
||
@SuppressWarnings("NotNullFieldNotInitialized") | ||
@Name("Is Using Experimental Feature") | ||
@Description("Checks whether a script is using an experimental feature by name.") | ||
@Examples({"the script is using \"example feature\"", | ||
"on load:", | ||
"\tif the script is using \"example feature\":", | ||
"\t\tbroadcast \"You're using an experimental feature!\""}) | ||
@Since("INSERT VERSION") | ||
public class CondIsUsingFeature extends Condition { | ||
|
||
static { | ||
Skript.registerCondition(CondIsUsingFeature.class, | ||
"[the] [current] script is using %strings%", | ||
"[the] [current] script is(n't| not) using %strings%"); | ||
} | ||
|
||
private Expression<String> names; | ||
private Experimented snapshot; | ||
|
||
@SuppressWarnings("null") | ||
@Override | ||
public boolean init(Expression<?>[] expressions, int pattern, Kleenean delayed, ParseResult result) { | ||
//noinspection unchecked | ||
this.names = (Expression<String>) expressions[0]; | ||
this.setNegated(pattern == 1); | ||
this.snapshot = this.getParser().experimentSnapshot(); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event event) { | ||
String[] array = names.getArray(event); | ||
if (array.length == 0) | ||
return true; | ||
boolean isUsing = true; | ||
for (@NotNull String object : array) { | ||
isUsing &= snapshot.hasExperiment(object); | ||
} | ||
return isUsing ^ this.isNegated(); | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "the current script " + (isNegated() ? "isn't" : "is") + " using " + names.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package ch.njol.skript.registrations; | ||
|
||
import ch.njol.skript.SkriptAddon; | ||
import ch.njol.skript.patterns.PatternCompiler; | ||
import ch.njol.skript.patterns.SkriptPattern; | ||
import org.skriptlang.skript.lang.experiment.Experiment; | ||
import org.skriptlang.skript.lang.experiment.ExperimentRegistry; | ||
import org.skriptlang.skript.lang.experiment.LifeCycle; | ||
|
||
/** | ||
* Experimental feature toggles as provided by Skript itself. | ||
*/ | ||
public enum Feature implements Experiment { | ||
; | ||
|
||
private final String codeName; | ||
private final LifeCycle phase; | ||
private final SkriptPattern compiledPattern; | ||
|
||
Feature(String codeName, LifeCycle phase, String... patterns) { | ||
this.codeName = codeName; | ||
this.phase = phase; | ||
switch (patterns.length) { | ||
case 0: | ||
this.compiledPattern = PatternCompiler.compile(codeName); | ||
break; | ||
case 1: | ||
this.compiledPattern = PatternCompiler.compile(patterns[0]); | ||
break; | ||
default: | ||
this.compiledPattern = PatternCompiler.compile('(' + String.join("|", patterns) + ')'); | ||
break; | ||
} | ||
} | ||
|
||
Feature(String codeName, LifeCycle phase) { | ||
this(codeName, phase, codeName); | ||
} | ||
|
||
public static void registerAll(SkriptAddon addon, ExperimentRegistry manager) { | ||
for (Feature value : values()) { | ||
manager.register(addon, value); | ||
} | ||
} | ||
|
||
@Override | ||
public String codeName() { | ||
return codeName; | ||
} | ||
|
||
@Override | ||
public LifeCycle phase() { | ||
return phase; | ||
} | ||
|
||
@Override | ||
public SkriptPattern pattern() { | ||
return compiledPattern; | ||
} | ||
|
||
} |
Oops, something went wrong.