diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml
index 08a6df7b665..677d0ce8a8b 100644
--- a/.github/ISSUE_TEMPLATE/bug-report.yml
+++ b/.github/ISSUE_TEMPLATE/bug-report.yml
@@ -7,6 +7,8 @@ body:
## Guidelines
Please make sure you are running the latest version of Skript on a supported server platform and version.
Try to make sure there are no issues of this same problem currently open either.
+ As of the release of Skript 2.10, the oldest supported version has been raised to 1.19.4.
+ Any issues created for versions older than 1.19.4 will not be looked into or fixed unless the issue persists on supported versions.
- type: textarea
attributes:
label: Skript/Server Version
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 5b930003730..16900d59a6f 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -1,5 +1,12 @@
version: 2
updates:
+ - package-ecosystem: "gitsubmodule"
+ target-branch: "dev/patch"
+ directory: "/"
+ schedule:
+ interval: "weekly"
+ labels:
+ - "dependencies"
- package-ecosystem: "github-actions"
target-branch: "dev/patch"
directory: "/"
diff --git a/src/main/java/ch/njol/skript/PatcherTool.java b/src/main/java/ch/njol/skript/PatcherTool.java
index 6b2355fdaf9..66062ae1769 100644
--- a/src/main/java/ch/njol/skript/PatcherTool.java
+++ b/src/main/java/ch/njol/skript/PatcherTool.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript;
import java.io.IOException;
diff --git a/src/main/java/ch/njol/skript/ServerPlatform.java b/src/main/java/ch/njol/skript/ServerPlatform.java
index 8313476883e..97fbc66e055 100644
--- a/src/main/java/ch/njol/skript/ServerPlatform.java
+++ b/src/main/java/ch/njol/skript/ServerPlatform.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript;
/**
diff --git a/src/main/java/ch/njol/skript/Skript.java b/src/main/java/ch/njol/skript/Skript.java
index 8bd3a557a35..e425cb19c4e 100644
--- a/src/main/java/ch/njol/skript/Skript.java
+++ b/src/main/java/ch/njol/skript/Skript.java
@@ -62,7 +62,6 @@
import ch.njol.skript.variables.Variables;
import ch.njol.util.Closeable;
import ch.njol.util.Kleenean;
-import ch.njol.util.NullableChecker;
import ch.njol.util.StringUtils;
import ch.njol.util.coll.iterator.CheckedIterator;
import ch.njol.util.coll.iterator.EnumerationIterable;
@@ -70,6 +69,7 @@
import com.google.common.collect.Lists;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.*;
@@ -87,17 +87,23 @@
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Unmodifiable;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability;
import org.junit.After;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
+import org.skriptlang.skript.bukkit.registration.BukkitRegistryKeys;
+import org.skriptlang.skript.bukkit.registration.BukkitSyntaxInfos;
import org.junit.runner.notification.Failure;
import org.skriptlang.skript.bukkit.SkriptMetrics;
import org.skriptlang.skript.bukkit.breeding.BreedingModule;
import org.skriptlang.skript.bukkit.displays.DisplayModule;
+import org.skriptlang.skript.bukkit.furnace.FurnaceModule;
import org.skriptlang.skript.bukkit.fishing.FishingModule;
import org.skriptlang.skript.bukkit.input.InputModule;
+import org.skriptlang.skript.bukkit.loottables.LootTableModule;
import org.skriptlang.skript.lang.comparator.Comparator;
import org.skriptlang.skript.lang.comparator.Comparators;
import org.skriptlang.skript.lang.converter.Converter;
@@ -107,6 +113,9 @@
import org.skriptlang.skript.lang.script.Script;
import org.skriptlang.skript.lang.structure.Structure;
import org.skriptlang.skript.lang.structure.StructureInfo;
+import org.skriptlang.skript.registration.SyntaxOrigin;
+import org.skriptlang.skript.registration.SyntaxRegistry;
+import org.skriptlang.skript.registration.SyntaxInfo;
import java.io.File;
import java.io.IOException;
@@ -141,6 +150,8 @@
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
@@ -179,14 +190,24 @@ public final class Skript extends JavaPlugin implements Listener {
@Nullable
private static Skript instance = null;
+ static org.skriptlang.skript.@UnknownNullability Skript skript = null;
+ private static org.skriptlang.skript.@UnknownNullability Skript unmodifiableSkript = null;
+
private static boolean disabled = false;
private static boolean partDisabled = false;
public static Skript getInstance() {
- final Skript i = instance;
- if (i == null)
+ if (instance == null)
throw new IllegalStateException();
- return i;
+ return instance;
+ }
+
+ @ApiStatus.Experimental
+ public static org.skriptlang.skript.Skript instance() {
+ if (unmodifiableSkript == null) {
+ throw new SkriptAPIException("Skript is still initializing");
+ }
+ return unmodifiableSkript;
}
/**
@@ -207,7 +228,6 @@ public Skript() throws IllegalStateException {
/**
* Check minecraft version and assign it to minecraftVersion field
* This method is created to update MC version before onEnable method
- * To fix {@link Utils#HEX_SUPPORTED} being assigned before minecraftVersion is properly assigned
*/
public static void updateMinecraftVersion() {
String bukkitV = Bukkit.getBukkitVersion();
@@ -392,8 +412,6 @@ public void onEnable() {
} catch (Exception e) {
Skript.exception(e, "Update checker could not be initialized.");
}
- experimentRegistry = new ExperimentRegistry(this);
- Feature.registerAll(getAddonInstance(), experimentRegistry);
if (!getDataFolder().isDirectory())
getDataFolder().mkdirs();
@@ -468,9 +486,17 @@ public void onEnable() {
}
}
- // initialize the Skript addon instance
+ // initialize the modern Skript instance
+ skript = org.skriptlang.skript.Skript.of(getClass(), getName());
+ unmodifiableSkript = skript.unmodifiableView();
+ skript.localizer().setSourceDirectories("lang",
+ getDataFolder().getAbsolutePath() + "lang");
+ // initialize the old Skript SkriptAddon instance
getAddonInstance();
+ experimentRegistry = new ExperimentRegistry(this);
+ Feature.registerAll(getAddonInstance(), experimentRegistry);
+
// Load classes which are always safe to use
new JavaClasses(); // These may be needed in configuration
@@ -549,6 +575,8 @@ public void onEnable() {
BreedingModule.load();
DisplayModule.load();
InputModule.load();
+ FurnaceModule.load();
+ LootTableModule.load();
} catch (final Exception e) {
exception(e, "Could not load required .class files: " + e.getLocalizedMessage());
setEnabled(false);
@@ -616,7 +644,6 @@ public void run() {
stopAcceptingRegistrations();
-
Documentation.generate(); // TODO move to test classes?
// Variable loading
@@ -769,7 +796,10 @@ protected void afterErrors() {
EffObjectives.fail();
info("Collecting results to " + TestMode.RESULTS_FILE);
- String results = new Gson().toJson(TestTracker.collectResults());
+ String results = new GsonBuilder()
+ .setPrettyPrinting() // Easier to read lines
+ .disableHtmlEscaping() // Fixes issue with "'" character in test strings going unicode
+ .create().toJson(TestTracker.collectResults());
try {
Files.write(TestMode.RESULTS_FILE, results.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
@@ -1223,7 +1253,6 @@ private boolean isServerRunning() {
private void beforeDisable() {
partDisabled = true;
EvtSkript.onSkriptStop(); // TODO [code style] warn user about delays in Skript stop events
-
ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts());
}
@@ -1335,194 +1364,231 @@ public static void checkAcceptRegistrations() {
private static void stopAcceptingRegistrations() {
Converters.createChainedConverters();
-
acceptRegistrations = false;
-
Classes.onRegistrationsStop();
}
// ================ ADDONS ================
- private final static HashMap addons = new HashMap<>();
+ @Deprecated
+ private static final Set addons = new HashSet<>();
/**
* Registers an addon to Skript. This is currently not required for addons to work, but the returned {@link SkriptAddon} provides useful methods for registering syntax elements
* and adding new strings to Skript's localization system (e.g. the required "types.[type]" strings for registered classes).
- *
- * @param p The plugin
+ *
+ * @param plugin The plugin
*/
- public static SkriptAddon registerAddon(final JavaPlugin p) {
+ public static SkriptAddon registerAddon(JavaPlugin plugin) {
checkAcceptRegistrations();
- if (addons.containsKey(p.getName()))
- throw new IllegalArgumentException("The plugin " + p.getName() + " is already registered");
- final SkriptAddon addon = new SkriptAddon(p);
- addons.put(p.getName(), addon);
+ SkriptAddon addon = new SkriptAddon(plugin);
+ addons.add(addon);
return addon;
}
- @Nullable
- public static SkriptAddon getAddon(final JavaPlugin p) {
- return addons.get(p.getName());
+ public static @Nullable SkriptAddon getAddon(JavaPlugin plugin) {
+ if (plugin == Skript.getInstance()) {
+ return Skript.getAddonInstance();
+ }
+ for (SkriptAddon addon : getAddons()) {
+ if (addon.plugin == plugin) {
+ return addon;
+ }
+ }
+ return null;
}
- @Nullable
- public static SkriptAddon getAddon(final String name) {
- return addons.get(name);
+ public static @Nullable SkriptAddon getAddon(String name) {
+ if (name.equals(Skript.getInstance().getName())) {
+ return Skript.getAddonInstance();
+ }
+ for (SkriptAddon addon : getAddons()) {
+ if (addon.getName().equals(name)) {
+ return addon;
+ }
+ }
+ return null;
}
- @SuppressWarnings("null")
- public static Collection getAddons() {
- return Collections.unmodifiableCollection(addons.values());
+ public static @Unmodifiable Collection getAddons() {
+ Set addons = new HashSet<>(Skript.addons);
+ addons.addAll(instance().addons().stream()
+ .filter(addon -> addons.stream().noneMatch(oldAddon -> oldAddon.name().equals(addon.name())))
+ .map(SkriptAddon::fromModern)
+ .collect(Collectors.toSet())
+ );
+ return Collections.unmodifiableCollection(addons);
}
- @Nullable
- private static SkriptAddon addon;
+ @Deprecated
+ private static @Nullable SkriptAddon addon;
/**
* @return A {@link SkriptAddon} representing Skript.
*/
public static SkriptAddon getAddonInstance() {
if (addon == null) {
- addon = new SkriptAddon(Skript.getInstance());
- addon.setLanguageFileDirectory("lang");
+ addon = SkriptAddon.fromModern(instance());
}
return addon;
}
// ================ CONDITIONS & EFFECTS & SECTIONS ================
- private static final List> conditions = new ArrayList<>(50);
- private static final List> effects = new ArrayList<>(50);
- private static final List> statements = new ArrayList<>(100);
- private static final List> sections = new ArrayList<>(50);
+ private static final class BukkitOrigin implements SyntaxOrigin {
- public static Collection> getStatements() {
- return statements;
- }
+ private final String name;
- public static Collection> getEffects() {
- return effects;
- }
+ private BukkitOrigin(Plugin plugin) {
+ this.name = plugin.getName();
+ }
- public static Collection> getSections() {
- return sections;
- }
+ @Override
+ public String name() {
+ return name;
+ }
- // ================ CONDITIONS ================
- public static Collection> getConditions() {
- return conditions;
}
- private final static int[] conditionTypesStartIndices = new int[ConditionType.values().length];
+ private static SyntaxOrigin getSyntaxOrigin(JavaPlugin plugin) {
+ SkriptAddon addon = getAddon(plugin);
+ if (addon != null) {
+ return SyntaxOrigin.of(addon);
+ }
+ return new BukkitOrigin(plugin);
+ }
/**
- * registers a {@link Condition}.
- *
- * @param condition The condition's class
+ * Registers a {@link Condition}.
+ *
+ * @param conditionClass The condition's class
* @param patterns Skript patterns to match this condition
*/
- public static void registerCondition(Class condition, String... patterns) throws IllegalArgumentException {
- registerCondition(condition, ConditionType.COMBINED, patterns);
+ public static void registerCondition(Class conditionClass, String... patterns) throws IllegalArgumentException {
+ registerCondition(conditionClass, ConditionType.COMBINED, patterns);
}
/**
- * registers a {@link Condition}.
- *
- * @param condition The condition's class
- * @param type The conditions {@link ConditionType type}. This is used to determine in which order to try to parse conditions.
+ * Registers a {@link Condition}.
+ *
+ * @param conditionClass The condition's class
+ * @param type The type of condition which affects its priority in the parsing search
* @param patterns Skript patterns to match this condition
*/
- public static void registerCondition(Class condition, ConditionType type, String... patterns) throws IllegalArgumentException {
+ public static void registerCondition(Class conditionClass, ConditionType type, String... patterns) throws IllegalArgumentException {
checkAcceptRegistrations();
- String originClassPath = Thread.currentThread().getStackTrace()[2].getClassName();
- final SyntaxElementInfo info = new SyntaxElementInfo<>(patterns, condition, originClassPath);
- conditions.add(conditionTypesStartIndices[type.ordinal()], info);
- statements.add(conditionTypesStartIndices[type.ordinal()], info);
- for (int i = type.ordinal(); i < ConditionType.values().length; i++)
- conditionTypesStartIndices[i]++;
+ skript.syntaxRegistry().register(SyntaxRegistry.CONDITION, SyntaxInfo.builder(conditionClass)
+ .priority(type.priority())
+ .origin(getSyntaxOrigin(JavaPlugin.getProvidingPlugin(conditionClass)))
+ .addPatterns(patterns)
+ .build()
+ );
}
/**
* Registers an {@link Effect}.
- *
- * @param effect The effect's class
+ *
+ * @param effectClass The effect's class
* @param patterns Skript patterns to match this effect
*/
- public static void registerEffect(final Class effect, final String... patterns) throws IllegalArgumentException {
+ public static void registerEffect(Class effectClass, String... patterns) throws IllegalArgumentException {
checkAcceptRegistrations();
- String originClassPath = Thread.currentThread().getStackTrace()[2].getClassName();
- final SyntaxElementInfo info = new SyntaxElementInfo<>(patterns, effect, originClassPath);
- effects.add(info);
- statements.add(info);
+ skript.syntaxRegistry().register(SyntaxRegistry.EFFECT, SyntaxInfo.builder(effectClass)
+ .origin(getSyntaxOrigin(JavaPlugin.getProvidingPlugin(effectClass)))
+ .addPatterns(patterns)
+ .build()
+ );
}
/**
* Registers a {@link Section}.
*
- * @param section The section's class
+ * @param sectionClass The section's class
* @param patterns Skript patterns to match this section
* @see Section
*/
- public static void registerSection(Class section, String... patterns) throws IllegalArgumentException {
+ public static void registerSection(Class sectionClass, String... patterns) throws IllegalArgumentException {
checkAcceptRegistrations();
- String originClassPath = Thread.currentThread().getStackTrace()[2].getClassName();
- SyntaxElementInfo info = new SyntaxElementInfo<>(patterns, section, originClassPath);
- sections.add(info);
+ skript.syntaxRegistry().register(SyntaxRegistry.SECTION, SyntaxInfo.builder(sectionClass)
+ .origin(getSyntaxOrigin(JavaPlugin.getProvidingPlugin(sectionClass)))
+ .addPatterns(patterns)
+ .build()
+ );
}
- // ================ EXPRESSIONS ================
+ public static @Unmodifiable Collection> getStatements() {
+ return instance().syntaxRegistry()
+ .syntaxes(SyntaxRegistry.STATEMENT).stream()
+ .map(SyntaxElementInfo::, Statement>fromModern)
+ .collect(Collectors.toUnmodifiableList());
+ }
- private final static List> expressions = new ArrayList<>(100);
+ public static @Unmodifiable Collection> getConditions() {
+ return instance().syntaxRegistry()
+ .syntaxes(SyntaxRegistry.CONDITION).stream()
+ .map(SyntaxElementInfo::, Condition>fromModern)
+ .collect(Collectors.toUnmodifiableList());
+ }
+
+ public static @Unmodifiable Collection> getEffects() {
+ return instance().syntaxRegistry()
+ .syntaxes(SyntaxRegistry.EFFECT).stream()
+ .map(SyntaxElementInfo::, Effect>fromModern)
+ .collect(Collectors.toUnmodifiableList());
+ }
+
+ public static @Unmodifiable Collection> getSections() {
+ return instance().syntaxRegistry()
+ .syntaxes(SyntaxRegistry.SECTION).stream()
+ .map(SyntaxElementInfo::, Section>fromModern)
+ .collect(Collectors.toUnmodifiableList());
+ }
- private final static int[] expressionTypesStartIndices = new int[ExpressionType.values().length];
+ // ================ EXPRESSIONS ================
/**
* Registers an expression.
- *
- * @param c The expression's class
+ *
+ * @param expressionType The expression's class
* @param returnType The superclass of all values returned by the expression
* @param type The expression's {@link ExpressionType type}. This is used to determine in which order to try to parse expressions.
* @param patterns Skript patterns that match this expression
* @throws IllegalArgumentException if returnType is not a normal class
*/
- public static , T> void registerExpression(final Class c, final Class returnType, final ExpressionType type, final String... patterns) throws IllegalArgumentException {
+ public static , T> void registerExpression(
+ Class expressionType, Class returnType, ExpressionType type, String... patterns
+ ) throws IllegalArgumentException {
checkAcceptRegistrations();
- if (returnType.isAnnotation() || returnType.isArray() || returnType.isPrimitive())
- throw new IllegalArgumentException("returnType must be a normal type");
- String originClassPath = Thread.currentThread().getStackTrace()[2].getClassName();
- final ExpressionInfo info = new ExpressionInfo<>(patterns, returnType, c, originClassPath, type);
- expressions.add(expressionTypesStartIndices[type.ordinal()], info);
- for (int i = type.ordinal(); i < ExpressionType.values().length; i++) {
- expressionTypesStartIndices[i]++;
- }
+ skript.syntaxRegistry().register(SyntaxRegistry.EXPRESSION, SyntaxInfo.Expression.builder(expressionType, returnType)
+ .priority(type.priority())
+ .origin(getSyntaxOrigin(JavaPlugin.getProvidingPlugin(expressionType)))
+ .addPatterns(patterns)
+ .build()
+ );
}
- @SuppressWarnings("null")
public static Iterator> getExpressions() {
- return expressions.iterator();
- }
-
- public static Iterator> getExpressions(final Class>... returnTypes) {
- return new CheckedIterator<>(getExpressions(), new NullableChecker>() {
- @Override
- public boolean check(final @Nullable ExpressionInfo, ?> i) {
- if (i == null || i.returnType == Object.class)
+ List> list = new ArrayList<>();
+ for (SyntaxInfo.Expression, ?> info : instance().syntaxRegistry().syntaxes(SyntaxRegistry.EXPRESSION))
+ list.add((ExpressionInfo, ?>) SyntaxElementInfo.fromModern(info));
+ return list.iterator();
+ }
+
+ public static Iterator> getExpressions(Class>... returnTypes) {
+ return new CheckedIterator<>(getExpressions(), info -> {
+ if (info == null || info.returnType == Object.class)
+ return true;
+ for (Class> returnType : returnTypes) {
+ assert returnType != null;
+ if (Converters.converterExists(info.returnType, returnType))
return true;
- for (final Class> returnType : returnTypes) {
- assert returnType != null;
- if (Converters.converterExists(i.returnType, returnType))
- return true;
- }
- return false;
}
+ return false;
});
}
// ================ EVENTS ================
- private static final List> events = new ArrayList<>(50);
- private static final List> structures = new ArrayList<>(10);
-
/**
* Registers an event.
*
@@ -1542,51 +1608,66 @@ public static SkriptEventInfo registerEvent(String na
* Registers an event.
*
* @param name The name of the event, used for error messages
- * @param c The event's class
+ * @param eventClass The event's class
* @param events The Bukkit events this event applies to
* @param patterns Skript patterns to match this event
* @return A SkriptEventInfo representing the registered event. Used to generate Skript's documentation.
*/
- public static SkriptEventInfo registerEvent(String name, Class c, Class extends Event>[] events, String... patterns) {
+ @SuppressWarnings("ConstantConditions") // caused by bad array annotations
+ public static SkriptEventInfo registerEvent(
+ String name, Class eventClass, Class extends Event>[] events, String... patterns
+ ) {
checkAcceptRegistrations();
- String originClassPath = Thread.currentThread().getStackTrace()[2].getClassName();
-
- String[] transformedPatterns = new String[patterns.length];
for (int i = 0; i < patterns.length; i++)
- transformedPatterns[i] = SkriptEvent.fixPattern(patterns[i]);
-
- SkriptEventInfo r = new SkriptEventInfo<>(name, transformedPatterns, c, originClassPath, events);
- Skript.events.add(r);
- return r;
+ patterns[i] = BukkitSyntaxInfos.fixPattern(patterns[i]);
+ var legacy = new SkriptEventInfo.ModernSkriptEventInfo<>(name, patterns, eventClass, "", events);
+ skript.syntaxRegistry().register(BukkitRegistryKeys.EVENT, legacy);
+ return legacy;
}
- public static void registerStructure(Class c, String... patterns) {
+ public static void registerStructure(Class structureClass, String... patterns) {
checkAcceptRegistrations();
- String originClassPath = Thread.currentThread().getStackTrace()[2].getClassName();
- StructureInfo structureInfo = new StructureInfo<>(patterns, c, originClassPath);
- structures.add(structureInfo);
+ skript.syntaxRegistry().register(SyntaxRegistry.STRUCTURE, SyntaxInfo.Structure.builder(structureClass)
+ .origin(getSyntaxOrigin(JavaPlugin.getProvidingPlugin(structureClass)))
+ .addPatterns(patterns)
+ .build()
+ );
}
- public static void registerSimpleStructure(Class c, String... patterns) {
+ public static void registerSimpleStructure(Class structureClass, String... patterns) {
checkAcceptRegistrations();
- String originClassPath = Thread.currentThread().getStackTrace()[2].getClassName();
- StructureInfo structureInfo = new StructureInfo<>(patterns, c, originClassPath, true);
- structures.add(structureInfo);
+ skript.syntaxRegistry().register(SyntaxRegistry.STRUCTURE, SyntaxInfo.Structure.builder(structureClass)
+ .origin(getSyntaxOrigin(JavaPlugin.getProvidingPlugin(structureClass)))
+ .addPatterns(patterns)
+ .nodeType(SyntaxInfo.Structure.NodeType.SIMPLE)
+ .build()
+ );
}
- public static void registerStructure(Class c, EntryValidator entryValidator, String... patterns) {
+ public static void registerStructure(
+ Class structureClass, EntryValidator entryValidator, String... patterns
+ ) {
checkAcceptRegistrations();
- String originClassPath = Thread.currentThread().getStackTrace()[2].getClassName();
- StructureInfo structureInfo = new StructureInfo<>(patterns, c, originClassPath, entryValidator);
- structures.add(structureInfo);
+ skript.syntaxRegistry().register(SyntaxRegistry.STRUCTURE, SyntaxInfo.Structure.builder(structureClass)
+ .origin(getSyntaxOrigin(JavaPlugin.getProvidingPlugin(structureClass)))
+ .addPatterns(patterns)
+ .entryValidator(entryValidator)
+ .build()
+ );
}
- public static Collection> getEvents() {
- return events;
+ public static @Unmodifiable Collection> getEvents() {
+ return instance().syntaxRegistry()
+ .syntaxes(BukkitRegistryKeys.EVENT).stream()
+ .map(SyntaxElementInfo::, SkriptEvent>fromModern)
+ .collect(Collectors.toUnmodifiableList());
}
- public static List> getStructures() {
- return structures;
+ public static @Unmodifiable List> getStructures() {
+ return instance().syntaxRegistry()
+ .syntaxes(SyntaxRegistry.STRUCTURE).stream()
+ .map(SyntaxElementInfo::, Structure>fromModern)
+ .collect(Collectors.toUnmodifiableList());
}
// ================ COMMANDS ================
@@ -1651,6 +1732,17 @@ public static void debug(final String info) {
SkriptLogger.log(SkriptLogger.DEBUG, info);
}
+ /**
+ * Sends a debug message with formatted objects if {@link #debug()} returns true.
+ *
+ * @param message The message to send
+ * @param objects The objects to format the message with
+ * @see String#formatted(Object...)
+ */
+ public static void debug(String message, Object... objects) {
+ debug(message.formatted(objects));
+ }
+
/**
* @see SkriptLogger#log(Level, String)
*/
diff --git a/src/main/java/ch/njol/skript/SkriptAPIException.java b/src/main/java/ch/njol/skript/SkriptAPIException.java
index a9cf43afc1c..25230f55fb6 100644
--- a/src/main/java/ch/njol/skript/SkriptAPIException.java
+++ b/src/main/java/ch/njol/skript/SkriptAPIException.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript;
/**
diff --git a/src/main/java/ch/njol/skript/SkriptAddon.java b/src/main/java/ch/njol/skript/SkriptAddon.java
index 3a1cf894d35..f09bdcf4e5d 100644
--- a/src/main/java/ch/njol/skript/SkriptAddon.java
+++ b/src/main/java/ch/njol/skript/SkriptAddon.java
@@ -1,68 +1,61 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript;
import java.io.File;
import java.io.IOException;
+import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.Nullable;
-import ch.njol.skript.localization.Language;
import ch.njol.skript.util.Utils;
import ch.njol.skript.util.Version;
+import org.jetbrains.annotations.ApiStatus;
+import org.skriptlang.skript.localization.Localizer;
+import org.skriptlang.skript.registration.SyntaxRegistry;
+import org.skriptlang.skript.util.Registry;
/**
* Utility class for Skript addons. Use {@link Skript#registerAddon(JavaPlugin)} to create a SkriptAddon instance for your plugin.
*/
-public final class SkriptAddon {
+public final class SkriptAddon implements org.skriptlang.skript.addon.SkriptAddon {
public final JavaPlugin plugin;
public final Version version;
private final String name;
+ private final org.skriptlang.skript.addon.SkriptAddon addon;
+
/**
* Package-private constructor. Use {@link Skript#registerAddon(JavaPlugin)} to get a SkriptAddon for your plugin.
- *
- * @param p
*/
- SkriptAddon(final JavaPlugin p) {
- plugin = p;
- name = "" + p.getName();
- Version v;
+ SkriptAddon(JavaPlugin plugin) {
+ this(plugin, Skript.skript.registerAddon(plugin.getClass(), plugin.getName()));
+ }
+
+ SkriptAddon(JavaPlugin plugin, org.skriptlang.skript.addon.SkriptAddon addon) {
+ this.addon = addon;
+ this.plugin = plugin;
+ this.name = plugin.getName();
+ Version version;
try {
- v = new Version("" + p.getDescription().getVersion());
- } catch (final IllegalArgumentException e) {
- final Matcher m = Pattern.compile("(\\d+)(?:\\.(\\d+)(?:\\.(\\d+))?)?").matcher(p.getDescription().getVersion());
+ version = new Version(plugin.getDescription().getVersion());
+ } catch (IllegalArgumentException e) {
+ final Matcher m = Pattern.compile("(\\d+)(?:\\.(\\d+)(?:\\.(\\d+))?)?").matcher(plugin.getDescription().getVersion());
if (!m.find())
- throw new IllegalArgumentException("The version of the plugin " + p.getName() + " does not contain any numbers: " + p.getDescription().getVersion());
- v = new Version(Utils.parseInt("" + m.group(1)), m.group(2) == null ? 0 : Utils.parseInt("" + m.group(2)), m.group(3) == null ? 0 : Utils.parseInt("" + m.group(3)));
- Skript.warning("The plugin " + p.getName() + " uses a non-standard version syntax: '" + p.getDescription().getVersion() + "'. Skript will use " + v + " instead.");
+ throw new IllegalArgumentException("The version of the plugin " + name + " does not contain any numbers: " + plugin.getDescription().getVersion());
+ version = new Version(Utils.parseInt(m.group(1)), m.group(2) == null ? 0 : Utils.parseInt(m.group(2)), m.group(3) == null ? 0 : Utils.parseInt(m.group(3)));
+ Skript.warning("The plugin " + name + " uses a non-standard version syntax: '" + plugin.getDescription().getVersion() + "'. Skript will use " + version + " instead.");
}
- version = v;
+ this.version = version;
}
@Override
public final String toString() {
- return name;
+ return getName();
}
public String getName() {
@@ -83,9 +76,6 @@ public SkriptAddon loadClasses(String basePackage, String... subPackages) throws
return this;
}
- @Nullable
- private String languageFileDirectory = null;
-
/**
* Makes Skript load language files from the specified directory, e.g. "lang" or "skript lang" if you have a lang folder yourself. Localised files will be read from the
* plugin's jar and the plugin's data folder, but the default English file is only taken from the jar and must exist!
@@ -94,19 +84,13 @@ public SkriptAddon loadClasses(String basePackage, String... subPackages) throws
* @return This SkriptAddon
*/
public SkriptAddon setLanguageFileDirectory(String directory) {
- if (languageFileDirectory != null)
- throw new IllegalStateException();
- directory = "" + directory.replace('\\', '/');
- if (directory.endsWith("/"))
- directory = "" + directory.substring(0, directory.length() - 1);
- languageFileDirectory = directory;
- Language.loadDefault(this);
+ localizer().setSourceDirectories(directory, plugin.getDataFolder().getAbsolutePath() + directory);
return this;
}
@Nullable
public String getLanguageFileDirectory() {
- return languageFileDirectory;
+ return localizer().languageFileDirectory();
}
@Nullable
@@ -126,4 +110,67 @@ public File getFile() {
return file;
}
+ //
+ // Modern SkriptAddon Compatibility
+ //
+
+ @ApiStatus.Experimental
+ static SkriptAddon fromModern(org.skriptlang.skript.addon.SkriptAddon addon) {
+ return new SkriptAddon(JavaPlugin.getProvidingPlugin(addon.source()), addon);
+ }
+
+ @Override
+ @ApiStatus.Experimental
+ public Class> source() {
+ return addon.source();
+ }
+
+ @Override
+ @ApiStatus.Experimental
+ public String name() {
+ return addon.name();
+ }
+
+ @Override
+ @ApiStatus.Experimental
+ public > void storeRegistry(Class registryClass, R registry) {
+ addon.storeRegistry(registryClass, registry);
+ }
+
+ @Override
+ @ApiStatus.Experimental
+ public void removeRegistry(Class extends Registry>> registryClass) {
+ addon.removeRegistry(registryClass);
+ }
+
+ @Override
+ @ApiStatus.Experimental
+ public boolean hasRegistry(Class extends Registry>> registryClass) {
+ return addon.hasRegistry(registryClass);
+ }
+
+ @Override
+ @ApiStatus.Experimental
+ public > R registry(Class registryClass) {
+ return addon.registry(registryClass);
+ }
+
+ @Override
+ @ApiStatus.Experimental
+ public > R registry(Class registryClass, Supplier putIfAbsent) {
+ return addon.registry(registryClass, putIfAbsent);
+ }
+
+ @Override
+ @ApiStatus.Experimental
+ public SyntaxRegistry syntaxRegistry() {
+ return addon.syntaxRegistry();
+ }
+
+ @Override
+ @ApiStatus.Experimental
+ public Localizer localizer() {
+ return addon.localizer();
+ }
+
}
diff --git a/src/main/java/ch/njol/skript/SkriptCommand.java b/src/main/java/ch/njol/skript/SkriptCommand.java
index 248a79fd884..99d43150869 100644
--- a/src/main/java/ch/njol/skript/SkriptCommand.java
+++ b/src/main/java/ch/njol/skript/SkriptCommand.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript;
import ch.njol.skript.aliases.Aliases;
@@ -32,12 +14,14 @@
import ch.njol.skript.test.runner.SkriptTestEvent;
import ch.njol.skript.test.runner.TestMode;
import ch.njol.skript.test.runner.TestTracker;
+import ch.njol.skript.test.utils.TestResults;
import ch.njol.skript.util.ExceptionUtils;
import ch.njol.skript.util.FileUtils;
import ch.njol.skript.util.SkriptColor;
import ch.njol.skript.util.Utils;
import ch.njol.util.OpenCloseable;
import ch.njol.util.StringUtils;
+import com.google.gson.GsonBuilder;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -50,7 +34,8 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
-import java.nio.file.Path;
+import java.nio.file.Files;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -424,13 +409,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}
} else {
- scriptFile = TestMode.TEST_DIR.resolve(
- Arrays.stream(args).skip(1).collect(Collectors.joining(" ")) + ".sk"
- ).toFile();
- TestMode.lastTestFile = scriptFile;
+ if (args[1].equalsIgnoreCase("all")) {
+ scriptFile = TestMode.TEST_DIR.toFile();
+ } else {
+ scriptFile = getScriptFromArgs(sender, args, TestMode.TEST_DIR.toFile());
+ TestMode.lastTestFile = scriptFile;
+ }
}
- if (!scriptFile.exists()) {
+ if (scriptFile == null || !scriptFile.exists()) {
Skript.error(sender, "Test script doesn't exist!");
return true;
}
@@ -443,10 +430,23 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts());
// Get results and show them
- String[] lines = TestTracker.collectResults().createReport().split("\n");
+ TestResults testResults = TestTracker.collectResults();
+ String[] lines = testResults.createReport().split("\n");
for (String line : lines) {
Skript.info(sender, line);
}
+
+ // Log results to file
+ Skript.info(sender, "Collecting results to " + TestMode.RESULTS_FILE);
+ String results = new GsonBuilder()
+ .setPrettyPrinting() // Easier to read lines
+ .disableHtmlEscaping() // Fixes issue with "'" character in test strings going unicode
+ .create().toJson(testResults);
+ try {
+ Files.writeString(TestMode.RESULTS_FILE, results);
+ } catch (IOException e) {
+ Skript.exception(e, "Failed to write test results.");
+ }
})
);
} else if (args[0].equalsIgnoreCase("list") || args[0].equalsIgnoreCase("show")) {
@@ -458,7 +458,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
ScriptLoader.getDisabledScripts().stream()
.flatMap(file -> {
if (file.isDirectory()) {
- return Arrays.stream(file.listFiles());
+ return getSubFiles(file).stream();
}
return Arrays.stream(new File[]{file});
})
@@ -480,10 +480,27 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
private static final ArgsMessage m_invalid_script = new ArgsMessage(CONFIG_NODE + ".invalid script");
private static final ArgsMessage m_invalid_folder = new ArgsMessage(CONFIG_NODE + ".invalid folder");
- @Nullable
- private static File getScriptFromArgs(CommandSender sender, String[] args) {
+ private static List getSubFiles(File file) {
+ List files = new ArrayList<>();
+ if (file.isDirectory()) {
+ for (File listFile : file.listFiles(f -> !f.isHidden())) {
+ if (listFile.isDirectory()) {
+ files.addAll(getSubFiles(listFile));
+ } else if (listFile.getName().endsWith(".sk")) {
+ files.add(listFile);
+ }
+ }
+ }
+ return files;
+ }
+
+ private static @Nullable File getScriptFromArgs(CommandSender sender, String[] args) {
+ return getScriptFromArgs(sender, args, Skript.getInstance().getScriptsFolder());
+ }
+
+ private static @Nullable File getScriptFromArgs(CommandSender sender, String[] args, File directoryFile) {
String script = StringUtils.join(args, " ", 1, args.length);
- File f = getScriptFromName(script);
+ File f = getScriptFromName(script, directoryFile);
if (f == null) {
// Always allow '/' and '\' regardless of OS
boolean directory = script.endsWith("/") || script.endsWith("\\") || script.endsWith(File.separator);
@@ -493,8 +510,11 @@ private static File getScriptFromArgs(CommandSender sender, String[] args) {
return f;
}
- @Nullable
- public static File getScriptFromName(String script) {
+ public static @Nullable File getScriptFromName(String script) {
+ return getScriptFromName(script, Skript.getInstance().getScriptsFolder());
+ }
+
+ public static @Nullable File getScriptFromName(String script, File directoryFile) {
if (script.endsWith("/") || script.endsWith("\\")) { // Always allow '/' and '\' regardless of OS
script = script.replace('/', File.separatorChar).replace('\\', File.separatorChar);
} else if (!StringUtils.endsWithIgnoreCase(script, ".sk")) {
@@ -507,7 +527,7 @@ public static File getScriptFromName(String script) {
if (script.startsWith(ScriptLoader.DISABLED_SCRIPT_PREFIX))
script = script.substring(ScriptLoader.DISABLED_SCRIPT_PREFIX_LENGTH);
- File scriptFile = new File(Skript.getInstance().getScriptsFolder(), script);
+ File scriptFile = new File(directoryFile, script);
if (!scriptFile.exists()) {
scriptFile = new File(scriptFile.getParentFile(), ScriptLoader.DISABLED_SCRIPT_PREFIX + scriptFile.getName());
if (!scriptFile.exists()) {
diff --git a/src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java b/src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java
index 3d0fdf49267..009a0c76f10 100644
--- a/src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java
+++ b/src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript;
import ch.njol.skript.doc.Documentation;
@@ -46,8 +28,8 @@ public List onTabComplete(CommandSender sender, Command command, String
if (args[0].equalsIgnoreCase("update") && args.length == 2) {
options.add("check");
options.add("changes");
- } else if (args[0].matches("(?i)(reload|disable|enable)") && args.length >= 2) {
- File scripts = Skript.getInstance().getScriptsFolder();
+ } else if (args[0].matches("(?i)(reload|disable|enable|test)") && args.length >= 2) {
+ File scripts = TestMode.DEV_MODE ? TestMode.TEST_DIR.toFile() : Skript.getInstance().getScriptsFolder();
String scriptsPathString = scripts.toPath().toString();
int scriptsPathLength = scriptsPathString.length();
diff --git a/src/main/java/ch/njol/skript/SkriptConfig.java b/src/main/java/ch/njol/skript/SkriptConfig.java
index 6cb2ab99ede..f846172b82c 100644
--- a/src/main/java/ch/njol/skript/SkriptConfig.java
+++ b/src/main/java/ch/njol/skript/SkriptConfig.java
@@ -4,7 +4,6 @@
import ch.njol.skript.config.EnumParser;
import ch.njol.skript.config.Option;
import ch.njol.skript.config.OptionSection;
-import ch.njol.skript.config.SectionNode;
import ch.njol.skript.hooks.Hook;
import ch.njol.skript.hooks.VaultHook;
import ch.njol.skript.hooks.regions.GriefPreventionHook;
@@ -364,115 +363,75 @@ private static void userDisableHooks(Class extends Hook>> hookClass, boolean
/**
* This should only be used in special cases
*/
- @Nullable
- public static Config getConfig() {
+ public static @Nullable Config getConfig() {
return mainConfig;
}
-
- // also used for reloading
- static boolean load() {
+
+ /**
+ * Reloads the main config file.
+ */
+ static void load() {
try {
- final File oldConfigFile = new File(Skript.getInstance().getDataFolder(), "config.cfg");
- final File configFile = new File(Skript.getInstance().getDataFolder(), "config.sk");
- if (oldConfigFile.exists()) {
- if (!configFile.exists()) {
- oldConfigFile.renameTo(configFile);
- Skript.info("[1.3] Renamed your 'config.cfg' to 'config.sk' to match the new format");
- } else {
- Skript.error("Found both a new and an old config, ignoring the old one");
- }
- }
+ File configFile = new File(Skript.getInstance().getDataFolder(), "config.sk");
+
if (!configFile.exists()) {
Skript.error("Config file 'config.sk' does not exist!");
- return false;
+ return;
}
if (!configFile.canRead()) {
Skript.error("Config file 'config.sk' cannot be read!");
- return false;
+ return;
}
-
- Config mc;
+
+ Config mainConfig;
try {
- mc = new Config(configFile, false, false, ":");
- } catch (final IOException e) {
- Skript.error("Could not load the main config: " + e.getLocalizedMessage());
- return false;
+ mainConfig = new Config(configFile, false, false, ":");
+ } catch (IOException ex) {
+ Skript.exception(ex, "Could not load the main config");
+ return;
}
- mainConfig = mc;
+ SkriptConfig.mainConfig = mainConfig;
- String configVersion = mc.get(version.key);
+ String configVersion = mainConfig.get(version.key);
if (configVersion == null || Skript.getVersion().compareTo(new Version(configVersion)) != 0) {
- try {
- final InputStream in = Skript.getInstance().getResource("config.sk");
- if (in == null) {
+ if (!mainConfig.getMainNode().isValid()) {
+ Skript.error("Your config is outdated, but cannot be updated because it contains errors.");
+ return;
+ }
+
+ try (InputStream stream = Skript.getInstance().getResource("config.sk")) {
+ if (stream == null) {
Skript.error("Your config is outdated, but Skript couldn't find the newest config in its jar.");
- return false;
- }
- final Config newConfig = new Config(in, "Skript.jar/config.sk", false, false, ":");
- in.close();
-
- boolean forceUpdate = false;
-
- if (mc.getMainNode().get("database") != null) { // old database layout
- forceUpdate = true;
- try {
- final SectionNode oldDB = (SectionNode) mc.getMainNode().get("database");
- assert oldDB != null;
- final SectionNode newDBs = (SectionNode) newConfig.getMainNode().get(databases.key);
- assert newDBs != null;
- final SectionNode newDB = (SectionNode) newDBs.get("database 1");
- assert newDB != null;
-
- newDB.setValues(oldDB);
-
- // '.db' was dynamically added before
- final String file = newDB.getValue("file");
- assert file != null;
- if (!file.endsWith(".db"))
- newDB.set("file", file + ".db");
-
- final SectionNode def = (SectionNode) newDBs.get("default");
- assert def != null;
- def.set("backup interval", "" + mc.get("variables backup interval"));
- } catch (final Exception e) {
- Skript.error("An error occurred while trying to update the config's database section.");
- Skript.error("You'll have to update the config yourself:");
- Skript.error("Open the new config.sk as well as the created backup, and move the 'database' section from the backup to the start of the 'databases' section");
- Skript.error("of the new config (i.e. the line 'databases:' should be directly above 'database:'), and add a tab in front of every line that you just copied.");
- return false;
- }
+ return;
}
-
- if (newConfig.setValues(mc, version.key, databases.key) || forceUpdate) { // new config is different
- final File bu = FileUtils.backup(configFile);
- newConfig.getMainNode().set(version.key, Skript.getVersion().toString());
- if (mc.getMainNode().get(databases.key) != null)
- newConfig.getMainNode().set(databases.key, mc.getMainNode().get(databases.key));
- mc = mainConfig = newConfig;
- mc.save(configFile);
- Skript.info("Your configuration has been updated to the latest version. A backup of your old config file has been created as " + bu.getName());
- } else { // only the version changed
- mc.getMainNode().set(version.key, Skript.getVersion().toString());
- mc.save(configFile);
+ Config newConfig = new Config(stream, "Skript.jar/config.sk", false, false, ":");
+
+ File backup = FileUtils.backup(configFile);
+ boolean updated = mainConfig.updateNodes(newConfig);
+ mainConfig.getMainNode().set(version.key, Skript.getVersion().toString());
+ mainConfig.save(configFile);
+ SkriptConfig.mainConfig = mainConfig;
+
+ if (updated) {
+ Skript.info("Your configuration has been updated to the latest version. " +
+ "A backup of your old config file has been created as " + backup.getName());
+ } else {
+ Skript.info("Your configuration is outdated, but no changes were performed. " +
+ "A backup of your config file has been created as " + backup.getName());
}
- } catch (final IOException e) {
- Skript.error("Could not load the new config from the jar file: " + e.getLocalizedMessage());
+ } catch (IOException ex) {
+ Skript.exception(ex, "Could not update the main config");
+ return;
}
}
-
- mc.load(SkriptConfig.class);
-
-// if (!keepConfigsLoaded.value())
-// mainConfig = null;
- } catch (final RuntimeException e) {
- Skript.exception(e, "An error occurred while loading the config");
- return false;
+
+ mainConfig.load(SkriptConfig.class);
+ } catch (RuntimeException ex) {
+ Skript.exception(ex, "An error occurred while loading the config");
}
// trigger reload event handlers
eventRegistry().events(ReloadEvent.class).forEach(ReloadEvent::onReload);
-
- return true;
}
}
diff --git a/src/main/java/ch/njol/skript/SkriptEventHandler.java b/src/main/java/ch/njol/skript/SkriptEventHandler.java
index 7b9947e8486..00901afa9c2 100644
--- a/src/main/java/ch/njol/skript/SkriptEventHandler.java
+++ b/src/main/java/ch/njol/skript/SkriptEventHandler.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript;
import ch.njol.skript.lang.SkriptEvent;
diff --git a/src/main/java/ch/njol/skript/SkriptUpdater.java b/src/main/java/ch/njol/skript/SkriptUpdater.java
index 51500f52c93..97c87ba2fd3 100644
--- a/src/main/java/ch/njol/skript/SkriptUpdater.java
+++ b/src/main/java/ch/njol/skript/SkriptUpdater.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript;
import java.io.IOException;
diff --git a/src/main/java/ch/njol/skript/aliases/Aliases.java b/src/main/java/ch/njol/skript/aliases/Aliases.java
index ad41fdb8508..de3562c787c 100644
--- a/src/main/java/ch/njol/skript/aliases/Aliases.java
+++ b/src/main/java/ch/njol/skript/aliases/Aliases.java
@@ -447,12 +447,7 @@ private static void loadMissingAliases() {
Skript.warning("An item that has the id 'mod:item' can be used as 'mod's item' or 'item from mod'.");
Skript.warning("WARNING: Skript does not officially support any modded servers.");
Skript.warning("Any issues you encounter related to modded items will be your responsibility to fix.");
- Skript.warning("The server will keep loading after 5 seconds.");
Skript.warning("==============================================================");
- try {
- Thread.sleep(5000L);
- } catch (InterruptedException ignored) {
- }
}
}
diff --git a/src/main/java/ch/njol/skript/aliases/AliasesMap.java b/src/main/java/ch/njol/skript/aliases/AliasesMap.java
index 143f5264060..b42424b5178 100644
--- a/src/main/java/ch/njol/skript/aliases/AliasesMap.java
+++ b/src/main/java/ch/njol/skript/aliases/AliasesMap.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.aliases;
import java.util.ArrayList;
diff --git a/src/main/java/ch/njol/skript/aliases/AliasesParser.java b/src/main/java/ch/njol/skript/aliases/AliasesParser.java
index e4a0891b689..623a86d64ca 100644
--- a/src/main/java/ch/njol/skript/aliases/AliasesParser.java
+++ b/src/main/java/ch/njol/skript/aliases/AliasesParser.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.aliases;
import java.util.ArrayList;
diff --git a/src/main/java/ch/njol/skript/aliases/InvalidMinecraftIdException.java b/src/main/java/ch/njol/skript/aliases/InvalidMinecraftIdException.java
index a4074477e75..12235757b35 100644
--- a/src/main/java/ch/njol/skript/aliases/InvalidMinecraftIdException.java
+++ b/src/main/java/ch/njol/skript/aliases/InvalidMinecraftIdException.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.aliases;
public class InvalidMinecraftIdException extends IllegalArgumentException {
diff --git a/src/main/java/ch/njol/skript/aliases/ItemData.java b/src/main/java/ch/njol/skript/aliases/ItemData.java
index f18812aabb8..a7a16ab8dc3 100644
--- a/src/main/java/ch/njol/skript/aliases/ItemData.java
+++ b/src/main/java/ch/njol/skript/aliases/ItemData.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.aliases;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/aliases/ItemFlags.java b/src/main/java/ch/njol/skript/aliases/ItemFlags.java
index b39b0b93c87..d14fed568bb 100644
--- a/src/main/java/ch/njol/skript/aliases/ItemFlags.java
+++ b/src/main/java/ch/njol/skript/aliases/ItemFlags.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.aliases;
diff --git a/src/main/java/ch/njol/skript/aliases/ItemType.java b/src/main/java/ch/njol/skript/aliases/ItemType.java
index 39ce6d21962..4cbea58df59 100644
--- a/src/main/java/ch/njol/skript/aliases/ItemType.java
+++ b/src/main/java/ch/njol/skript/aliases/ItemType.java
@@ -4,6 +4,8 @@
import ch.njol.skript.bukkitutil.BukkitUnsafe;
import ch.njol.skript.bukkitutil.ItemUtils;
import ch.njol.skript.lang.Unit;
+import ch.njol.skript.lang.util.common.AnyAmount;
+import ch.njol.skript.lang.util.common.AnyNamed;
import ch.njol.skript.localization.Adjective;
import ch.njol.skript.localization.GeneralWords;
import ch.njol.skript.localization.Language;
@@ -35,6 +37,7 @@
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.NotSerializableException;
@@ -55,7 +58,8 @@
import java.util.stream.Collectors;
@ContainerType(ItemStack.class)
-public class ItemType implements Unit, Iterable, Container, YggdrasilExtendedSerializable {
+public class ItemType implements Unit, Iterable, Container, YggdrasilExtendedSerializable,
+ AnyNamed, AnyAmount {
static {
// This handles updating ItemType and ItemData variable records
@@ -1444,4 +1448,37 @@ public ItemType getBaseType() {
return copy;
}
+ @Override
+ public @Nullable String name() {
+ ItemMeta meta = this.getItemMeta();
+ return meta.hasDisplayName() ? meta.getDisplayName() : null;
+ }
+
+ @Override
+ public boolean supportsNameChange() {
+ return true;
+ }
+
+ @Override
+ public void setName(String name) {
+ ItemMeta meta = this.getItemMeta();
+ meta.setDisplayName(name);
+ this.setItemMeta(meta);
+ }
+
+ @Override
+ public @NotNull Number amount() {
+ return this.getAmount();
+ }
+
+ @Override
+ public boolean supportsAmountChange() {
+ return true;
+ }
+
+ @Override
+ public void setAmount(@Nullable Number amount) throws UnsupportedOperationException {
+ this.setAmount(amount != null ? amount.intValue() : 0);
+ }
+
}
diff --git a/src/main/java/ch/njol/skript/aliases/MatchQuality.java b/src/main/java/ch/njol/skript/aliases/MatchQuality.java
index 58bac3dd2d5..8f863c7e0ca 100644
--- a/src/main/java/ch/njol/skript/aliases/MatchQuality.java
+++ b/src/main/java/ch/njol/skript/aliases/MatchQuality.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.aliases;
/**
diff --git a/src/main/java/ch/njol/skript/aliases/MaterialName.java b/src/main/java/ch/njol/skript/aliases/MaterialName.java
index d79912b9103..67fe60be0cb 100644
--- a/src/main/java/ch/njol/skript/aliases/MaterialName.java
+++ b/src/main/java/ch/njol/skript/aliases/MaterialName.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.aliases;
import org.bukkit.Material;
diff --git a/src/main/java/ch/njol/skript/aliases/ScriptAliases.java b/src/main/java/ch/njol/skript/aliases/ScriptAliases.java
index 6a5386f3b94..de6575e20a8 100644
--- a/src/main/java/ch/njol/skript/aliases/ScriptAliases.java
+++ b/src/main/java/ch/njol/skript/aliases/ScriptAliases.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.aliases;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/ClickEventTracker.java b/src/main/java/ch/njol/skript/bukkitutil/ClickEventTracker.java
index a0ad94999be..0a2188ae0f3 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/ClickEventTracker.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/ClickEventTracker.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil;
import java.util.HashMap;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/CommandReloader.java b/src/main/java/ch/njol/skript/bukkitutil/CommandReloader.java
index e7ae58015f0..aa730e1ad0c 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/CommandReloader.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/CommandReloader.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil;
import java.lang.reflect.Method;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/DamageUtils.java b/src/main/java/ch/njol/skript/bukkitutil/DamageUtils.java
new file mode 100644
index 00000000000..02f74bef6bb
--- /dev/null
+++ b/src/main/java/ch/njol/skript/bukkitutil/DamageUtils.java
@@ -0,0 +1,41 @@
+package ch.njol.skript.bukkitutil;
+
+import org.bukkit.damage.DamageSource;
+import org.bukkit.damage.DamageType;
+import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
+import org.jetbrains.annotations.NotNull;
+
+public class DamageUtils {
+
+ @SuppressWarnings("UnstableApiUsage")
+ public static @NotNull DamageSource getDamageSourceFromCause(DamageCause cause) {
+ return DamageSource.builder(switch (cause) {
+ case KILL, SUICIDE -> DamageType.GENERIC_KILL;
+ case WORLD_BORDER, VOID -> DamageType.OUT_OF_WORLD;
+ case CONTACT -> DamageType.CACTUS;
+ case SUFFOCATION -> DamageType.IN_WALL;
+ case FALL -> DamageType.FALL;
+ case FIRE -> DamageType.ON_FIRE;
+ case FIRE_TICK -> DamageType.IN_FIRE;
+ case LAVA -> DamageType.LAVA;
+ case DROWNING -> DamageType.DROWN;
+ case BLOCK_EXPLOSION, ENTITY_EXPLOSION -> DamageType.EXPLOSION;
+ case LIGHTNING -> DamageType.LIGHTNING_BOLT;
+ case STARVATION -> DamageType.STARVE;
+ case MAGIC, POISON -> DamageType.MAGIC;
+ case WITHER -> DamageType.WITHER;
+ case FALLING_BLOCK -> DamageType.FALLING_BLOCK;
+ case THORNS -> DamageType.THORNS;
+ case DRAGON_BREATH -> DamageType.DRAGON_BREATH;
+ case FLY_INTO_WALL -> DamageType.FLY_INTO_WALL;
+ case HOT_FLOOR -> DamageType.HOT_FLOOR;
+ case CAMPFIRE -> DamageType.CAMPFIRE;
+ case CRAMMING -> DamageType.CRAMMING;
+ case DRYOUT -> DamageType.DRY_OUT;
+ case FREEZE -> DamageType.FREEZE;
+ case SONIC_BOOM -> DamageType.SONIC_BOOM;
+ default -> DamageType.GENERIC;
+ }).build();
+ }
+
+}
diff --git a/src/main/java/ch/njol/skript/bukkitutil/EnchantmentUtils.java b/src/main/java/ch/njol/skript/bukkitutil/EnchantmentUtils.java
index 7247bba5d37..e43574d9f5e 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/EnchantmentUtils.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/EnchantmentUtils.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil;
import ch.njol.skript.classes.ClassInfo;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/EntityUtils.java b/src/main/java/ch/njol/skript/bukkitutil/EntityUtils.java
index 0da7aee9a66..2808d6637ae 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/EntityUtils.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/EntityUtils.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil;
import org.bukkit.Location;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/HealthUtils.java b/src/main/java/ch/njol/skript/bukkitutil/HealthUtils.java
index aae3224b409..a6955604cc1 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/HealthUtils.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/HealthUtils.java
@@ -2,6 +2,8 @@
import ch.njol.skript.Skript;
import ch.njol.util.Math2;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import org.bukkit.attribute.Attributable;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
@@ -13,10 +15,16 @@
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.jetbrains.annotations.Nullable;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
public class HealthUtils {
+ private static final @Nullable Constructor OLD_DAMAGE_EVENT_CONSTRUCTOR;
+
+ static {
+ Constructor constructor = null;
+ try {
+ constructor = EntityDamageEvent.class.getConstructor(Damageable.class, DamageCause.class, double.class);
+ } catch (NoSuchMethodException ignored) {}
+ OLD_DAMAGE_EVENT_CONSTRUCTOR = constructor;
+ }
private static final Attribute MAX_HEALTH;
static {
@@ -29,80 +37,95 @@ public class HealthUtils {
/**
* Get the health of an entity
- * @param e Entity to get health from
+ *
+ * @param damageable Entity to get health from
* @return The amount of hearts the entity has left
*/
- public static double getHealth(Damageable e) {
- if (e.isDead())
+ public static double getHealth(Damageable damageable) {
+ if (damageable.isDead())
return 0;
- return e.getHealth() / 2;
+ return damageable.getHealth() / 2;
}
-
+
/**
* Set the health of an entity
- * @param e Entity to set health for
+ *
+ * @param damageable Entity to set health for
* @param health The amount of hearts to set
*/
- public static void setHealth(Damageable e, double health) {
- e.setHealth(Math2.fit(0, health, getMaxHealth(e)) * 2);
+ public static void setHealth(Damageable damageable, double health) {
+ damageable.setHealth(Math2.fit(0, health, getMaxHealth(damageable)) * 2);
}
-
+
/**
* Get the max health an entity has
- * @param e Entity to get max health from
+ *
+ * @param damageable Entity to get max health from
* @return How many hearts the entity can have at most
*/
- public static double getMaxHealth(Damageable e) {
- AttributeInstance attributeInstance = ((Attributable) e).getAttribute(MAX_HEALTH);
+ public static double getMaxHealth(Damageable damageable) {
+ AttributeInstance attributeInstance = ((Attributable) damageable).getAttribute(MAX_HEALTH);
assert attributeInstance != null;
return attributeInstance.getValue() / 2;
}
-
+
/**
* Set the max health an entity can have
- * @param e Entity to set max health for
+ *
+ * @param damageable Entity to set max health for
* @param health How many hearts the entity can have at most
*/
- public static void setMaxHealth(Damageable e, double health) {
- AttributeInstance attributeInstance = ((Attributable) e).getAttribute(MAX_HEALTH);
+ public static void setMaxHealth(Damageable damageable, double health) {
+ AttributeInstance attributeInstance = ((Attributable) damageable).getAttribute(MAX_HEALTH);
assert attributeInstance != null;
attributeInstance.setBaseValue(health * 2);
}
-
+
/**
* Apply damage to an entity
- * @param e Entity to apply damage to
- * @param d Amount of hearts to damage
+ *
+ * @param damageable Entity to apply damage to
+ * @param damage Amount of hearts to damage
*/
- public static void damage(Damageable e, double d) {
- if (d < 0) {
- heal(e, -d);
+ public static void damage(Damageable damageable, double damage) {
+ if (damage < 0) {
+ heal(damageable, -damage);
return;
}
- e.damage(d * 2);
+ damageable.damage(damage * 2);
+ }
+
+ @SuppressWarnings("UnstableApiUsage")
+ public static void damage(Damageable damageable, double damage, DamageSource cause) {
+ if (damage < 0) {
+ heal(damageable, -damage);
+ return;
+ }
+ damageable.damage(damage * 2, cause);
}
/**
* Heal an entity
- * @param e Entity to heal
- * @param h Amount of hearts to heal
+ *
+ * @param damageable Entity to heal
+ * @param health Amount of hearts to heal
*/
- public static void heal(Damageable e, double h) {
- if (h < 0) {
- damage(e, -h);
+ public static void heal(Damageable damageable, double health) {
+ if (health < 0) {
+ damage(damageable, -health);
return;
}
- setHealth(e, getHealth(e) + h);
+ setHealth(damageable, getHealth(damageable) + health);
}
-
- public static double getDamage(EntityDamageEvent e) {
- return e.getDamage() / 2;
+
+ public static double getDamage(EntityDamageEvent event) {
+ return event.getDamage() / 2;
}
-
- public static double getFinalDamage(EntityDamageEvent e) {
- return e.getFinalDamage() / 2;
+
+ public static double getFinalDamage(EntityDamageEvent event) {
+ return event.getFinalDamage() / 2;
}
-
+
public static void setDamage(EntityDamageEvent event, double damage) {
event.setDamage(damage * 2);
// Set last damage manually as Bukkit doesn't appear to do that
@@ -110,27 +133,15 @@ public static void setDamage(EntityDamageEvent event, double damage) {
((LivingEntity) event.getEntity()).setLastDamage(damage * 2);
}
- @Nullable
- private static final Constructor OLD_DAMAGE_EVENT_CONSTRUCTOR;
-
- static {
- Constructor constructor = null;
- try {
- constructor = EntityDamageEvent.class.getConstructor(Damageable.class, DamageCause.class, double.class);
- } catch (NoSuchMethodException ignored) { }
- OLD_DAMAGE_EVENT_CONSTRUCTOR = constructor;
- }
-
- public static void setDamageCause(Damageable e, DamageCause cause) {
+ public static void setDamageCause(Damageable damageable, DamageCause cause) {
if (OLD_DAMAGE_EVENT_CONSTRUCTOR != null) {
try {
- e.setLastDamageCause(OLD_DAMAGE_EVENT_CONSTRUCTOR.newInstance(e, cause, 0));
+ damageable.setLastDamageCause(OLD_DAMAGE_EVENT_CONSTRUCTOR.newInstance(damageable, cause, 0));
} catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
Skript.exception("Failed to set last damage cause");
}
} else {
- e.setLastDamageCause(new EntityDamageEvent(e, cause, DamageSource.builder(DamageType.GENERIC).build(), 0));
+ damageable.setLastDamageCause(new EntityDamageEvent(damageable, cause, DamageSource.builder(DamageType.GENERIC).build(), 0));
}
}
-
}
diff --git a/src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java b/src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java
index 2af432ce6d3..ae37c272750 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/PaperEntityUtils.java b/src/main/java/ch/njol/skript/bukkitutil/PaperEntityUtils.java
index 00a95c7ffca..b488fcbc9a7 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/PaperEntityUtils.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/PaperEntityUtils.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil;
import java.util.EnumSet;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/PassengerUtils.java b/src/main/java/ch/njol/skript/bukkitutil/PassengerUtils.java
index 70b84941f93..9d2af9fbfb0 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/PassengerUtils.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/PassengerUtils.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil;
import java.lang.reflect.Method;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/PlayerUtils.java b/src/main/java/ch/njol/skript/bukkitutil/PlayerUtils.java
index 5132dc521c6..6f3791fa34d 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/PlayerUtils.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/PlayerUtils.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/SoundUtils.java b/src/main/java/ch/njol/skript/bukkitutil/SoundUtils.java
index 36ad5136d9a..0debb60adf4 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/SoundUtils.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/SoundUtils.java
@@ -2,6 +2,7 @@
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
+import org.bukkit.Registry;
import org.bukkit.Sound;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,19 +26,17 @@ public final class SoundUtils {
soundString = soundString.toUpperCase(Locale.ENGLISH);
if (SOUND_IS_INTERFACE) {
try {
- //noinspection deprecation
+ //noinspection deprecation,removal
return Sound.valueOf(soundString).getKey();
- } catch (IllegalArgumentException ignore) {
- }
+ } catch (Exception ignored) {}
} else {
try {
//noinspection unchecked,rawtypes
Enum soundEnum = Enum.valueOf((Class) Sound.class, soundString);
return ((Keyed) soundEnum).getKey();
- } catch (IllegalArgumentException ignore) {
- }
+ } catch (IllegalArgumentException ignored) {}
}
- return null;
+ return NamespacedKey.fromString(soundString.toLowerCase(Locale.ENGLISH));
}
/**
@@ -47,11 +46,23 @@ public final class SoundUtils {
*/
public static @NotNull NamespacedKey getKey(Sound sound) {
if (SOUND_IS_INTERFACE) {
- //noinspection deprecation
+ //noinspection deprecation,removal
return sound.getKey();
} else {
return ((Keyed) sound).getKey();
}
}
+ /**
+ * Retrieves the sound correlating to the provided {@code soundString}
+ * @param soundString The string to get the correlating sound
+ * @return The correlating {@link Sound}
+ */
+ public static @Nullable Sound getSound(String soundString) {
+ NamespacedKey key = getKey(soundString);
+ if (key == null)
+ return null;
+ return Registry.SOUNDS.get(key);
+ }
+
}
diff --git a/src/main/java/ch/njol/skript/bukkitutil/WorldUtils.java b/src/main/java/ch/njol/skript/bukkitutil/WorldUtils.java
index b08e464088b..9862eb379c4 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/WorldUtils.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/WorldUtils.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/block/BlockCompat.java b/src/main/java/ch/njol/skript/bukkitutil/block/BlockCompat.java
index f6866b595f7..cd1045b47ec 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/block/BlockCompat.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/block/BlockCompat.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil.block;
import java.util.Map;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/block/BlockSetter.java b/src/main/java/ch/njol/skript/bukkitutil/block/BlockSetter.java
index e428734fe20..bfcdb41854a 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/block/BlockSetter.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/block/BlockSetter.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil.block;
import org.bukkit.Location;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/block/BlockValues.java b/src/main/java/ch/njol/skript/bukkitutil/block/BlockValues.java
index 0cf4e1a3c21..48a338d2174 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/block/BlockValues.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/block/BlockValues.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil.block;
import ch.njol.skript.aliases.MatchQuality;
diff --git a/src/main/java/ch/njol/skript/bukkitutil/block/NewBlockCompat.java b/src/main/java/ch/njol/skript/bukkitutil/block/NewBlockCompat.java
index c20febc95e9..6307a4634cd 100644
--- a/src/main/java/ch/njol/skript/bukkitutil/block/NewBlockCompat.java
+++ b/src/main/java/ch/njol/skript/bukkitutil/block/NewBlockCompat.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.bukkitutil.block;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/classes/AnyInfo.java b/src/main/java/ch/njol/skript/classes/AnyInfo.java
new file mode 100644
index 00000000000..283e0c5189b
--- /dev/null
+++ b/src/main/java/ch/njol/skript/classes/AnyInfo.java
@@ -0,0 +1,40 @@
+package ch.njol.skript.classes;
+
+import ch.njol.skript.lang.util.common.AnyProvider;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * A special kind of {@link ClassInfo} for dealing with 'any'-accepting types.
+ * These auto-generate their user patterns (e.g. {@code named} -> {@code any named thing}).
+ *
+ * @see AnyProvider
+ */
+public class AnyInfo extends ClassInfo {
+
+ /**
+ * @param c The class
+ * @param codeName The name used in patterns
+ */
+ public AnyInfo(Class c, String codeName) {
+ super(c, codeName);
+ this.user("(any )?" + codeName + " (thing|object)s?");
+ }
+
+ @Override
+ public ClassInfo user(String... userInputPatterns) throws PatternSyntaxException {
+ if (this.userInputPatterns == null)
+ return super.user(userInputPatterns);
+ // Allow appending the patterns.
+ List list = new ArrayList<>(List.of(this.userInputPatterns));
+ for (String pattern : userInputPatterns) {
+ list.add(Pattern.compile(pattern));
+ }
+ this.userInputPatterns = list.toArray(new Pattern[0]);
+ return this;
+ }
+
+}
diff --git a/src/main/java/ch/njol/skript/classes/Arithmetic.java b/src/main/java/ch/njol/skript/classes/Arithmetic.java
index 2365c3a64da..f381e012d52 100644
--- a/src/main/java/ch/njol/skript/classes/Arithmetic.java
+++ b/src/main/java/ch/njol/skript/classes/Arithmetic.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
/**
diff --git a/src/main/java/ch/njol/skript/classes/ChainedConverter.java b/src/main/java/ch/njol/skript/classes/ChainedConverter.java
index 7e560d3dd20..418d8620d31 100644
--- a/src/main/java/ch/njol/skript/classes/ChainedConverter.java
+++ b/src/main/java/ch/njol/skript/classes/ChainedConverter.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/ch/njol/skript/classes/Changer.java b/src/main/java/ch/njol/skript/classes/Changer.java
index 138f6279740..544433b6ee6 100644
--- a/src/main/java/ch/njol/skript/classes/Changer.java
+++ b/src/main/java/ch/njol/skript/classes/Changer.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import org.bukkit.event.Event;
diff --git a/src/main/java/ch/njol/skript/classes/ClassInfo.java b/src/main/java/ch/njol/skript/classes/ClassInfo.java
index 56b24d4dceb..3c96028c58a 100644
--- a/src/main/java/ch/njol/skript/classes/ClassInfo.java
+++ b/src/main/java/ch/njol/skript/classes/ClassInfo.java
@@ -28,23 +28,22 @@
*/
@SuppressFBWarnings("DM_STRING_VOID_CTOR")
public class ClassInfo implements Debuggable {
-
+
private final Class c;
private final String codeName;
private final Noun name;
-
+
@Nullable
private DefaultExpression defaultExpression = null;
-
+
@Nullable
private Parser extends T> parser = null;
-
+
@Nullable
private Cloner cloner = null;
-
- @Nullable
- private Pattern[] userInputPatterns = null;
-
+
+ @Nullable Pattern[] userInputPatterns = null;
+
@Nullable
private Changer super T> changer = null;
@@ -55,12 +54,12 @@ public class ClassInfo implements Debuggable {
private Serializer super T> serializer = null;
@Nullable
private Class> serializeAs = null;
-
+
@Nullable
private Arithmetic super T, ?> math = null;
@Nullable
private Class> mathRelativeType = null;
-
+
@Nullable
private String docName = null;
@Nullable
@@ -73,13 +72,13 @@ public class ClassInfo implements Debuggable {
private String since = null;
@Nullable
private String[] requiredPlugins = null;
-
+
/**
* Overrides documentation id assigned from class name.
*/
@Nullable
private String documentationId = null;
-
+
/**
* @param c The class
* @param codeName The name used in patterns
@@ -91,7 +90,7 @@ public ClassInfo(final Class c, final String codeName) {
this.codeName = codeName;
name = new Noun("types." + codeName);
}
-
+
/**
* Incorrect spelling in method name. This will be removed in the future.
*/
@@ -99,13 +98,13 @@ public ClassInfo(final Class c, final String codeName) {
public static boolean isVaildCodeName(final String name) {
return isValidCodeName(name);
}
-
+
public static boolean isValidCodeName(final String name) {
- return name.matches("[a-z0-9]+");
+ return name.matches("(?:any-)?[a-z0-9]+");
}
-
+
// === FACTORY METHODS ===
-
+
/**
* @param parser A parser to parse values of this class or null if not applicable
*/
@@ -114,7 +113,7 @@ public ClassInfo parser(final Parser extends T> parser) {
this.parser = parser;
return this;
}
-
+
/**
* @param cloner A {@link Cloner} to clone values when setting variables
* or passing function arguments.
@@ -124,7 +123,7 @@ public ClassInfo cloner(Cloner cloner) {
this.cloner = cloner;
return this;
}
-
+
/**
* @param userInputPatterns Regex patterns to match this class, e.g. in the expressions loop-[type], random [type] out of ..., or as command arguments. These patterns
* must be english and match singular and plural.
@@ -139,7 +138,7 @@ public ClassInfo user(final String... userInputPatterns) throws PatternSyntax
}
return this;
}
-
+
/**
* @param defaultExpression The default (event) value of this class or null if not applicable
* @see EventValueExpression
@@ -187,7 +186,7 @@ public ClassInfo serializer(final Serializer super T> serializer) {
serializer.register(this);
return this;
}
-
+
public ClassInfo serializeAs(final Class> serializeAs) {
assert this.serializeAs == null;
if (serializer != null)
@@ -195,12 +194,12 @@ public ClassInfo serializeAs(final Class> serializeAs) {
this.serializeAs = serializeAs;
return this;
}
-
+
@Deprecated
public ClassInfo changer(final SerializableChanger super T> changer) {
return changer((Changer super T>) changer);
}
-
+
public ClassInfo changer(final Changer super T> changer) {
assert this.changer == null;
this.changer = changer;
@@ -221,15 +220,15 @@ public ClassInfo math(final Class relativeType, final Arithmetic sup
Arithmetics.registerDifference(c, relativeType, math::difference);
return this;
}
-
+
/**
* Use this as {@link #name(String)} to suppress warnings about missing documentation.
*/
public final static String NO_DOC = new String();
-
+
/**
* Only used for Skript's documentation.
- *
+ *
* @param name
* @return This ClassInfo object
*/
@@ -238,10 +237,10 @@ public ClassInfo name(final String name) {
this.docName = name;
return this;
}
-
+
/**
* Only used for Skript's documentation.
- *
+ *
* @param description
* @return This ClassInfo object
*/
@@ -250,10 +249,10 @@ public ClassInfo description(final String... description) {
this.description = description;
return this;
}
-
+
/**
* Only used for Skript's documentation.
- *
+ *
* @param usage
* @return This ClassInfo object
*/
@@ -262,10 +261,10 @@ public ClassInfo usage(final String... usage) {
this.usage = usage;
return this;
}
-
+
/**
* Only used for Skript's documentation.
- *
+ *
* @param examples
* @return This ClassInfo object
*/
@@ -274,10 +273,10 @@ public ClassInfo examples(final String... examples) {
this.examples = examples;
return this;
}
-
+
/**
* Only used for Skript's documentation.
- *
+ *
* @param since
* @return This ClassInfo object
*/
@@ -286,7 +285,7 @@ public ClassInfo since(final String since) {
this.since = since;
return this;
}
-
+
/**
* Other plugin dependencies for this ClassInfo.
*
@@ -300,7 +299,7 @@ public ClassInfo requiredPlugins(final String... pluginNames) {
this.requiredPlugins = pluginNames;
return this;
}
-
+
/**
* Overrides default documentation id, which is assigned from class name.
* This is especially useful for inner classes whose names are useless without
@@ -313,36 +312,36 @@ public ClassInfo documentationId(String id) {
this.documentationId = id;
return this;
}
-
+
// === GETTERS ===
-
+
public Class getC() {
return c;
}
-
+
public Noun getName() {
return name;
}
-
+
public String getCodeName() {
return codeName;
}
-
+
@Nullable
public DefaultExpression getDefaultExpression() {
return defaultExpression;
}
-
+
@Nullable
public Parser extends T> getParser() {
return parser;
}
-
+
@Nullable
public Cloner extends T> getCloner() {
return cloner;
}
-
+
/**
* Clones the given object using {@link ClassInfo#cloner},
* returning the given object if no {@link Cloner} is registered.
@@ -350,12 +349,12 @@ public Cloner extends T> getCloner() {
public T clone(T t) {
return cloner == null ? t : cloner.clone(t);
}
-
+
@Nullable
public Pattern[] getUserInputPatterns() {
return userInputPatterns;
}
-
+
@Nullable
public Changer super T> getChanger() {
return changer;
@@ -372,12 +371,12 @@ public Supplier> getSupplier() {
public Serializer super T> getSerializer() {
return serializer;
}
-
+
@Nullable
public Class> getSerializeAs() {
return serializeAs;
}
-
+
@Nullable
@Deprecated
public Arithmetic super T, ?> getMath() {
@@ -389,33 +388,33 @@ public Class> getSerializeAs() {
public Arithmetic getRelativeMath() {
return (Arithmetic) math;
}
-
+
@Nullable
@Deprecated
public Class> getMathRelativeType() {
return mathRelativeType;
}
-
+
@Nullable
public String[] getDescription() {
return description;
}
-
+
@Nullable
public String[] getUsage() {
return usage;
}
-
+
@Nullable
public String[] getExamples() {
return examples;
}
-
+
@Nullable
public String getSince() {
return since;
}
-
+
@Nullable
public String getDocName() {
return docName;
@@ -425,7 +424,7 @@ public String getDocName() {
public String[] getRequiredPlugins() {
return requiredPlugins;
}
-
+
/**
* Gets overridden documentation id of this this type. If no override has
* been set, null is returned and the caller may try to derive this from
@@ -440,13 +439,13 @@ public String getDocumentationID() {
public boolean hasDocs() {
return getDocName() != null && !ClassInfo.NO_DOC.equals(getDocName());
}
-
+
// === ORDERING ===
-
+
@Nullable
private Set before;
private final Set after = new HashSet<>();
-
+
/**
* Sets one or more classes that this class should occur before in the class info list. This only affects the order in which classes are parsed if it's unknown of which type
* the parsed string is.
@@ -454,7 +453,7 @@ public boolean hasDocs() {
* Please note that subclasses will always be registered before superclasses, no matter what is defined here or in {@link #after(String...)}.
*
* This list can safely contain classes that may not exist.
- *
+ *
* @param before
* @return this ClassInfo
*/
@@ -463,7 +462,7 @@ public ClassInfo before(final String... before) {
this.before = new HashSet<>(Arrays.asList(before));
return this;
}
-
+
/**
* Sets one or more classes that this class should occur after in the class info list. This only affects the order in which classes are parsed if it's unknown of which type
* the parsed string is.
@@ -471,7 +470,7 @@ public ClassInfo before(final String... before) {
* Please note that subclasses will always be registered before superclasses, no matter what is defined here or in {@link #before(String...)}.
*
* This list can safely contain classes that may not exist.
- *
+ *
* @param after
* @return this ClassInfo
*/
@@ -479,7 +478,7 @@ public ClassInfo after(final String... after) {
this.after.addAll(Arrays.asList(after));
return this;
}
-
+
/**
* @return Set of classes that should be after this one. May return null.
*/
@@ -487,26 +486,26 @@ public ClassInfo after(final String... after) {
public Set before() {
return before;
}
-
+
/**
* @return Set of classes that should be before this one. Never returns null.
*/
public Set after() {
return after;
}
-
+
// === GENERAL ===
-
+
@Override
@NotNull
public String toString() {
return getName().getSingular();
}
-
+
public String toString(final int flags) {
return getName().toString(flags);
}
-
+
@Override
@NotNull
public String toString(final @Nullable Event event, final boolean debug) {
@@ -514,5 +513,5 @@ public String toString(final @Nullable Event event, final boolean debug) {
return codeName + " (" + c.getCanonicalName() + ")";
return getName().getSingular();
}
-
+
}
diff --git a/src/main/java/ch/njol/skript/classes/Cloner.java b/src/main/java/ch/njol/skript/classes/Cloner.java
index 4625980496a..6f1e35d2d22 100644
--- a/src/main/java/ch/njol/skript/classes/Cloner.java
+++ b/src/main/java/ch/njol/skript/classes/Cloner.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
/**
diff --git a/src/main/java/ch/njol/skript/classes/Comparator.java b/src/main/java/ch/njol/skript/classes/Comparator.java
index ae71dd3c8de..31e8ac607e0 100644
--- a/src/main/java/ch/njol/skript/classes/Comparator.java
+++ b/src/main/java/ch/njol/skript/classes/Comparator.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
/**
diff --git a/src/main/java/ch/njol/skript/classes/ConfigurationSerializer.java b/src/main/java/ch/njol/skript/classes/ConfigurationSerializer.java
index b70d843ba7a..de0491c1b62 100644
--- a/src/main/java/ch/njol/skript/classes/ConfigurationSerializer.java
+++ b/src/main/java/ch/njol/skript/classes/ConfigurationSerializer.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import java.io.NotSerializableException;
diff --git a/src/main/java/ch/njol/skript/classes/Converter.java b/src/main/java/ch/njol/skript/classes/Converter.java
index abb6399dacb..f9aefe2d8f2 100644
--- a/src/main/java/ch/njol/skript/classes/Converter.java
+++ b/src/main/java/ch/njol/skript/classes/Converter.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import ch.njol.skript.lang.Debuggable;
diff --git a/src/main/java/ch/njol/skript/classes/EnumSerializer.java b/src/main/java/ch/njol/skript/classes/EnumSerializer.java
index 812ec4491b4..a4440e5e192 100644
--- a/src/main/java/ch/njol/skript/classes/EnumSerializer.java
+++ b/src/main/java/ch/njol/skript/classes/EnumSerializer.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import java.io.StreamCorruptedException;
diff --git a/src/main/java/ch/njol/skript/classes/InverseComparator.java b/src/main/java/ch/njol/skript/classes/InverseComparator.java
index dc9ccf5f003..a8ae1d2dba8 100644
--- a/src/main/java/ch/njol/skript/classes/InverseComparator.java
+++ b/src/main/java/ch/njol/skript/classes/InverseComparator.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
/**
diff --git a/src/main/java/ch/njol/skript/classes/NumberArithmetic.java b/src/main/java/ch/njol/skript/classes/NumberArithmetic.java
index 71c035ebd7d..cc5e487f7a1 100644
--- a/src/main/java/ch/njol/skript/classes/NumberArithmetic.java
+++ b/src/main/java/ch/njol/skript/classes/NumberArithmetic.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
/**
diff --git a/src/main/java/ch/njol/skript/classes/Parser.java b/src/main/java/ch/njol/skript/classes/Parser.java
index 9060a36b430..16f85792571 100644
--- a/src/main/java/ch/njol/skript/classes/Parser.java
+++ b/src/main/java/ch/njol/skript/classes/Parser.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/ch/njol/skript/classes/SerializableChanger.java b/src/main/java/ch/njol/skript/classes/SerializableChanger.java
index 2bbbc86e44b..e2967a6de81 100644
--- a/src/main/java/ch/njol/skript/classes/SerializableChanger.java
+++ b/src/main/java/ch/njol/skript/classes/SerializableChanger.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
/**
diff --git a/src/main/java/ch/njol/skript/classes/SerializableChecker.java b/src/main/java/ch/njol/skript/classes/SerializableChecker.java
index 3b7d4e3643f..216e2b750b1 100644
--- a/src/main/java/ch/njol/skript/classes/SerializableChecker.java
+++ b/src/main/java/ch/njol/skript/classes/SerializableChecker.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import ch.njol.util.Checker;
diff --git a/src/main/java/ch/njol/skript/classes/SerializableGetter.java b/src/main/java/ch/njol/skript/classes/SerializableGetter.java
index 0dbd5c2098b..69b37ceeb65 100644
--- a/src/main/java/ch/njol/skript/classes/SerializableGetter.java
+++ b/src/main/java/ch/njol/skript/classes/SerializableGetter.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import ch.njol.skript.util.Getter;
diff --git a/src/main/java/ch/njol/skript/classes/Serializer.java b/src/main/java/ch/njol/skript/classes/Serializer.java
index 64b9375e27a..aec12090692 100644
--- a/src/main/java/ch/njol/skript/classes/Serializer.java
+++ b/src/main/java/ch/njol/skript/classes/Serializer.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import java.io.NotSerializableException;
diff --git a/src/main/java/ch/njol/skript/classes/VectorArithmethic.java b/src/main/java/ch/njol/skript/classes/VectorArithmethic.java
index 5bdac60af9a..a4d7db28b4e 100644
--- a/src/main/java/ch/njol/skript/classes/VectorArithmethic.java
+++ b/src/main/java/ch/njol/skript/classes/VectorArithmethic.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import org.bukkit.util.Vector;
diff --git a/src/main/java/ch/njol/skript/classes/YggdrasilSerializer.java b/src/main/java/ch/njol/skript/classes/YggdrasilSerializer.java
index 5fab3d52342..5add92542c0 100644
--- a/src/main/java/ch/njol/skript/classes/YggdrasilSerializer.java
+++ b/src/main/java/ch/njol/skript/classes/YggdrasilSerializer.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes;
import java.io.NotSerializableException;
diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
index 64a47196bb5..6acf2d9be75 100644
--- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
+++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes.data;
import ch.njol.skript.Skript;
@@ -67,14 +49,8 @@
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentOffer;
-import org.bukkit.entity.Cat;
-import org.bukkit.entity.Wolf;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Item;
-import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.*;
import org.bukkit.entity.Panda.Gene;
-import org.bukkit.entity.Player;
-import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityPotionEffectEvent;
@@ -1565,6 +1541,33 @@ public String toVariableNameString(EnchantmentOffer eo) {
.name("Experience Cooldown Change Reason")
.description("Represents a change reason of an experience cooldown change event.")
.since("INSERT VERSION"));
+
+ Classes.registerClass(new RegistryClassInfo<>(Villager.Type.class, Registry.VILLAGER_TYPE, "villagertype", "villager types")
+ .user("villager ?types?")
+ .name("Villager Type")
+ .description("Represents the different types of villagers. These are usually the biomes a villager can be from.")
+ .after("biome")
+ .since("INSERT VERSION"));
+
+ Classes.registerClass(new RegistryClassInfo<>(Villager.Profession.class, Registry.VILLAGER_PROFESSION, "villagerprofession", "villager professions")
+ .user("villager ?professions?")
+ .name("Villager Profession")
+ .description("Represents the different professions of villagers.")
+ .since("INSERT VERSION"));
+
+ if (Skript.classExists("org.bukkit.entity.EntitySnapshot")) {
+ Classes.registerClass(new ClassInfo<>(EntitySnapshot.class, "entitysnapshot")
+ .user("entity ?snapshots?")
+ .name("Entity Snapshot")
+ .description("Represents a snapshot of an entity's data.",
+ "This includes all of the data associated with an entity (its name, health, attributes, etc.), at the time this expression is used. "
+ + "Essentially, these are a way to create templates for entities.",
+ "Individual attributes of a snapshot cannot be modified or retrieved.")
+ .requiredPlugins("Minecraft 1.20.2+")
+ .since("INSERT VERSION")
+ );
+ }
+
}
}
diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
index f9a2accca7d..ab91438aaf2 100644
--- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
+++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
@@ -1,18 +1,10 @@
package ch.njol.skript.classes.data;
-import java.time.Duration;
-import java.time.temporal.TemporalAmount;
-import java.time.temporal.TemporalUnit;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.function.Function;
-
import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.InventoryUtils;
import ch.njol.skript.command.CommandEvent;
+import ch.njol.skript.command.ScriptCommandEvent;
import ch.njol.skript.events.bukkit.ScriptEvent;
import ch.njol.skript.events.bukkit.SkriptStartEvent;
import ch.njol.skript.events.bukkit.SkriptStopEvent;
@@ -26,18 +18,15 @@
import com.destroystokyo.paper.event.entity.EndermanAttackPlayerEvent;
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
+import com.destroystokyo.paper.event.player.PlayerElytraBoostEvent;
import io.papermc.paper.event.entity.EntityMoveEvent;
-import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
-import io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent;
-import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
-import io.papermc.paper.event.player.PlayerTradeEvent;
-import org.bukkit.*;
import io.papermc.paper.event.player.*;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
+import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
import org.bukkit.event.block.*;
@@ -66,9 +55,13 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
-import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
public final class BukkitEventValues {
public BukkitEventValues() {
@@ -974,6 +967,8 @@ public World get(final CommandEvent e) {
return e.getSender() instanceof Player ? ((Player) e.getSender()).getWorld() : null;
}
}, 0);
+ EventValues.registerEventValue(CommandEvent.class, Block.class,
+ event -> event.getSender() instanceof BlockCommandSender sender ? sender.getBlock() : null);
// === ServerEvents ===
// Script load/unload event
@@ -1629,24 +1624,6 @@ public ItemType get(PlayerStopUsingItemEvent event) {
}, EventValues.TIME_NOW);
}
- // LootGenerateEvent
- if (Skript.classExists("org.bukkit.event.world.LootGenerateEvent")) {
- EventValues.registerEventValue(LootGenerateEvent.class, Entity.class, new Getter() {
- @Override
- @Nullable
- public Entity get(LootGenerateEvent event) {
- return event.getEntity();
- }
- }, EventValues.TIME_NOW);
- EventValues.registerEventValue(LootGenerateEvent.class, Location.class, new Getter() {
- @Override
- @Nullable
- public Location get(LootGenerateEvent event) {
- return event.getLootContext().getLocation();
- }
- }, EventValues.TIME_NOW);
- }
-
// EntityResurrectEvent
EventValues.registerEventValue(EntityResurrectEvent.class, Slot.class, new Getter() {
@Override
@@ -1810,6 +1787,12 @@ public RegainReason get(EntityRegainHealthEvent event) {
}
}, EventValues.TIME_NOW);
+ // FurnaceExtractEvent
+ EventValues.registerEventValue(FurnaceExtractEvent.class, Player.class, FurnaceExtractEvent::getPlayer);
+ EventValues.registerEventValue(FurnaceExtractEvent.class, ItemStack[].class,
+ event -> new ItemStack[]{ItemStack.of(event.getItemType(), event.getItemAmount())
+ });
+
// BlockDropItemEvent
EventValues.registerEventValue(BlockDropItemEvent.class, Block.class, new Getter() {
@Override
@@ -1894,6 +1877,13 @@ public Block get(PlayerChangeBeaconEffectEvent event) {
}
}, EventValues.TIME_NOW);
}
+
+ // PlayerElytraBoostEvent
+ if (Skript.classExists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent")) {
+ EventValues.registerEventValue(PlayerElytraBoostEvent.class, ItemStack.class, PlayerElytraBoostEvent::getItemStack);
+ EventValues.registerEventValue(PlayerElytraBoostEvent.class, Entity.class, PlayerElytraBoostEvent::getFirework);
+ }
+
}
}
diff --git a/src/main/java/ch/njol/skript/classes/data/DefaultChangers.java b/src/main/java/ch/njol/skript/classes/data/DefaultChangers.java
index 7d6aff7f333..8a8ce77dc55 100644
--- a/src/main/java/ch/njol/skript/classes/data/DefaultChangers.java
+++ b/src/main/java/ch/njol/skript/classes/data/DefaultChangers.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes.data;
import org.bukkit.Material;
diff --git a/src/main/java/ch/njol/skript/classes/data/DefaultComparators.java b/src/main/java/ch/njol/skript/classes/data/DefaultComparators.java
index dbaf030c374..f6a2759c201 100644
--- a/src/main/java/ch/njol/skript/classes/data/DefaultComparators.java
+++ b/src/main/java/ch/njol/skript/classes/data/DefaultComparators.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes.data;
import ch.njol.skript.Skript;
@@ -52,11 +34,7 @@
import org.bukkit.block.data.BlockData;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.EnchantmentOffer;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.FallingBlock;
-import org.bukkit.entity.Item;
-import org.bukkit.entity.Projectile;
-import org.bukkit.entity.Wither;
+import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
@@ -670,6 +648,23 @@ public boolean supportsOrdering() {
Comparators.registerComparator(Color.class, Color.class, (one, two) -> Relation.get(one.asBukkitColor().equals(two.asBukkitColor())));
Comparators.registerComparator(Color.class, org.bukkit.Color.class, (one, two) -> Relation.get(one.asBukkitColor().equals(two)));
Comparators.registerComparator(org.bukkit.Color.class, org.bukkit.Color.class, (one, two) -> Relation.get(one.equals(two)));
+
+ if (Skript.classExists("org.bukkit.entity.EntitySnapshot")) {
+ boolean SNAPSHOT_AS_STRING_EXISTS = Skript.methodExists(EntitySnapshot.class, "getAsString");
+ Comparators.registerComparator(EntitySnapshot.class, EntitySnapshot.class, new Comparator() {
+ @Override
+ public Relation compare(EntitySnapshot snap1, EntitySnapshot snap2) {
+ if (!snap1.getEntityType().equals(snap1.getEntityType()))
+ return Relation.NOT_EQUAL;
+ boolean isEqual;
+ if (!SNAPSHOT_AS_STRING_EXISTS)
+ isEqual = snap1.equals(snap2) || snap1.hashCode() == snap2.hashCode();
+ else
+ isEqual = snap1.getAsString().equalsIgnoreCase(snap2.getAsString());
+ return Relation.get(isEqual);
+ }
+ });
+ }
}
}
diff --git a/src/main/java/ch/njol/skript/classes/data/DefaultConverters.java b/src/main/java/ch/njol/skript/classes/data/DefaultConverters.java
index a90de6957d3..a73fece5a1f 100644
--- a/src/main/java/ch/njol/skript/classes/data/DefaultConverters.java
+++ b/src/main/java/ch/njol/skript/classes/data/DefaultConverters.java
@@ -1,39 +1,20 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes.data;
+import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.command.Commands;
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.entity.EntityType;
import ch.njol.skript.entity.XpOrbData;
+import ch.njol.skript.lang.util.common.AnyAmount;
+import ch.njol.skript.lang.util.common.AnyNamed;
import ch.njol.skript.util.BlockInventoryHolder;
import ch.njol.skript.util.BlockUtils;
import ch.njol.skript.util.Direction;
import ch.njol.skript.util.EnchantmentType;
import ch.njol.skript.util.Experience;
import ch.njol.skript.util.slot.Slot;
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.World;
+import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
@@ -48,14 +29,19 @@
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.scoreboard.Objective;
+import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.UnknownNullability;
import org.skriptlang.skript.lang.converter.Converter;
import org.skriptlang.skript.lang.converter.Converters;
public class DefaultConverters {
-
+
public DefaultConverters() {}
-
+
static {
// Number to subtypes converters
Converters.registerConverter(Number.class, Byte.class, Number::byteValue);
@@ -100,27 +86,27 @@ public DefaultConverters() {}
return (LivingEntity) e;
return null;
});
-
+
// Block - Inventory
Converters.registerConverter(Block.class, Inventory.class, b -> {
if (b.getState() instanceof InventoryHolder)
return ((InventoryHolder) b.getState()).getInventory();
return null;
}, Commands.CONVERTER_NO_COMMAND_ARGUMENTS);
-
+
// Entity - Inventory
Converters.registerConverter(Entity.class, Inventory.class, e -> {
if (e instanceof InventoryHolder)
return ((InventoryHolder) e).getInventory();
return null;
}, Commands.CONVERTER_NO_COMMAND_ARGUMENTS);
-
+
// Block - ItemType
Converters.registerConverter(Block.class, ItemType.class, ItemType::new, Converter.NO_LEFT_CHAINING | Commands.CONVERTER_NO_COMMAND_ARGUMENTS);
// Block - Location
Converters.registerConverter(Block.class, Location.class, BlockUtils::getLocation, Commands.CONVERTER_NO_COMMAND_ARGUMENTS);
-
+
// Entity - Location
Converters.registerConverter(Entity.class, Location.class, Entity::getLocation, Commands.CONVERTER_NO_COMMAND_ARGUMENTS);
@@ -129,21 +115,21 @@ public DefaultConverters() {}
// EntityData - EntityType
Converters.registerConverter(EntityData.class, EntityType.class, data -> new EntityType(data, -1));
-
+
// ItemType - ItemStack
Converters.registerConverter(ItemType.class, ItemStack.class, ItemType::getRandom);
Converters.registerConverter(ItemStack.class, ItemType.class, ItemType::new);
-
+
// Experience - XpOrbData
Converters.registerConverter(Experience.class, XpOrbData.class, e -> new XpOrbData(e.getXP()));
Converters.registerConverter(XpOrbData.class, Experience.class, e -> new Experience(e.getExperience()));
-
+
// Slot - ItemType
Converters.registerConverter(Slot.class, ItemType.class, s -> {
ItemStack i = s.getItem();
return new ItemType(i != null ? i : new ItemStack(Material.AIR, 1));
});
-
+
// Block - InventoryHolder
Converters.registerConverter(Block.class, InventoryHolder.class, b -> {
BlockState s = b.getState();
@@ -162,25 +148,108 @@ public DefaultConverters() {}
// InventoryHolder - Entity
Converters.registerConverter(InventoryHolder.class, Entity.class, holder -> {
- if (holder instanceof Entity)
- return (Entity) holder;
+ if (holder instanceof Entity entity)
+ return entity;
return null;
}, Converter.NO_CHAINING);
+ // Anything with a name -> AnyNamed
+ Converters.registerConverter(OfflinePlayer.class, AnyNamed.class, player -> player::getName, Converter.NO_RIGHT_CHAINING);
+ if (Skript.classExists("org.bukkit.generator.WorldInfo"))
+ Converters.registerConverter(World.class, AnyNamed.class, world -> world::getName, Converter.NO_RIGHT_CHAINING);
+ else //noinspection RedundantCast getName method is on World itself in older versions
+ Converters.registerConverter(World.class, AnyNamed.class, world -> () -> ((World) world).getName(), Converter.NO_RIGHT_CHAINING);
+ Converters.registerConverter(GameRule.class, AnyNamed.class, rule -> rule::getName, Converter.NO_RIGHT_CHAINING);
+ Converters.registerConverter(Server.class, AnyNamed.class, server -> server::getName, Converter.NO_RIGHT_CHAINING);
+ Converters.registerConverter(Plugin.class, AnyNamed.class, plugin -> plugin::getName, Converter.NO_RIGHT_CHAINING);
+ Converters.registerConverter(WorldType.class, AnyNamed.class, type -> type::getName, Converter.NO_RIGHT_CHAINING);
+ Converters.registerConverter(Team.class, AnyNamed.class, team -> team::getName, Converter.NO_RIGHT_CHAINING);
+ Converters.registerConverter(Objective.class, AnyNamed.class, objective -> objective::getName, Converter.NO_RIGHT_CHAINING);
+ Converters.registerConverter(Nameable.class, AnyNamed.class, //
+ nameable -> new AnyNamed() {
+ @Override
+ public @UnknownNullability String name() {
+ //noinspection deprecation
+ return nameable.getCustomName();
+ }
+
+ @Override
+ public boolean supportsNameChange() {
+ return true;
+ }
+
+ @Override
+ public void setName(String name) {
+ //noinspection deprecation
+ nameable.setCustomName(name);
+ }
+ },
+ //
+ Converter.NO_RIGHT_CHAINING);
+ Converters.registerConverter(Block.class, AnyNamed.class, //
+ block -> new AnyNamed() {
+ @Override
+ public @UnknownNullability String name() {
+ BlockState state = block.getState();
+ if (state instanceof Nameable nameable)
+ //noinspection deprecation
+ return nameable.getCustomName();
+ return null;
+ }
+
+ @Override
+ public boolean supportsNameChange() {
+ return true;
+ }
+
+ @Override
+ public void setName(String name) {
+ BlockState state = block.getState();
+ if (state instanceof Nameable nameable)
+ //noinspection deprecation
+ nameable.setCustomName(name);
+ }
+ },
+ //
+ Converter.NO_RIGHT_CHAINING);
+ Converters.registerConverter(CommandSender.class, AnyNamed.class, thing -> thing::getName, Converter.NO_RIGHT_CHAINING);
+ // Command senders should be done last because there might be a better alternative above
+
+ // Anything with an amount -> AnyAmount
+ Converters.registerConverter(ItemStack.class, AnyAmount.class, //
+ item -> new AnyAmount() {
+
+ @Override
+ public @NotNull Number amount() {
+ return item.getAmount();
+ }
+
+ @Override
+ public boolean supportsAmountChange() {
+ return true;
+ }
+
+ @Override
+ public void setAmount(Number amount) {
+ item.setAmount(amount != null ? amount.intValue() : 0);
+ }
+ },
+ //
+ Converter.NO_RIGHT_CHAINING);
+
// InventoryHolder - Location
// since the individual ones can't be trusted to chain.
Converters.registerConverter(InventoryHolder.class, Location.class, holder -> {
- if (holder instanceof Entity)
- return ((Entity) holder).getLocation();
- if (holder instanceof Block)
- return ((Block) holder).getLocation();
- if (holder instanceof BlockState)
- return BlockUtils.getLocation(((BlockState) holder).getBlock());
- if (holder instanceof DoubleChest) {
- DoubleChest doubleChest = (DoubleChest) holder;
+ if (holder instanceof Entity entity)
+ return entity.getLocation();
+ if (holder instanceof Block block)
+ return block.getLocation();
+ if (holder instanceof BlockState state)
+ return BlockUtils.getLocation(state.getBlock());
+ if (holder instanceof DoubleChest doubleChest) {
if (doubleChest.getLeftSide() != null) {
return BlockUtils.getLocation(((BlockState) doubleChest.getLeftSide()).getBlock());
- } else if (((DoubleChest) holder).getRightSide() != null) {
+ } else if (doubleChest.getRightSide() != null) {
return BlockUtils.getLocation(((BlockState) doubleChest.getRightSide()).getBlock());
}
}
diff --git a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
index 5c770ca0d5e..3450a1a1438 100644
--- a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
+++ b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes.data;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/classes/data/DefaultOperations.java b/src/main/java/ch/njol/skript/classes/data/DefaultOperations.java
index 48bf82939fd..907de84ef89 100644
--- a/src/main/java/ch/njol/skript/classes/data/DefaultOperations.java
+++ b/src/main/java/ch/njol/skript/classes/data/DefaultOperations.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes.data;
import ch.njol.skript.util.Date;
diff --git a/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java b/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
index 57704e760ee..f3e02109153 100644
--- a/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
+++ b/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
@@ -1,17 +1,20 @@
package ch.njol.skript.classes.data;
+import ch.njol.skript.classes.*;
+import ch.njol.skript.lang.util.common.AnyAmount;
+import ch.njol.skript.lang.util.common.AnyContains;
+import ch.njol.skript.lang.util.common.AnyNamed;
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.Nullable;
+
import ch.njol.skript.Skript;
import ch.njol.skript.aliases.Aliases;
import ch.njol.skript.aliases.ItemData;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.EnchantmentUtils;
import ch.njol.skript.bukkitutil.ItemUtils;
-import ch.njol.skript.classes.Changer;
-import ch.njol.skript.classes.ClassInfo;
-import ch.njol.skript.classes.EnumSerializer;
-import ch.njol.skript.classes.Parser;
-import ch.njol.skript.classes.Serializer;
-import ch.njol.skript.classes.YggdrasilSerializer;
import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.lang.util.SimpleLiteral;
@@ -36,21 +39,17 @@
import ch.njol.skript.util.visual.VisualEffect;
import ch.njol.skript.util.visual.VisualEffects;
import ch.njol.yggdrasil.Fields;
-import org.bukkit.Material;
-import org.bukkit.enchantments.Enchantment;
-import org.bukkit.inventory.ItemStack;
-import org.jetbrains.annotations.Nullable;
import java.io.StreamCorruptedException;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.Locale;
import java.util.regex.Pattern;
+import java.util.Arrays;
@SuppressWarnings("rawtypes")
public class SkriptClasses {
public SkriptClasses() {}
-
+
static {
//noinspection unchecked
Classes.registerClass(new ClassInfo<>(ClassInfo.class, "classinfo")
@@ -73,17 +72,17 @@ public SkriptClasses() {}
public ClassInfo parse(final String s, final ParseContext context) {
return Classes.getClassInfoFromUserInput(Noun.stripIndefiniteArticle(s));
}
-
+
@Override
public String toString(final ClassInfo c, final int flags) {
return c.toString(flags);
}
-
+
@Override
public String toVariableNameString(final ClassInfo c) {
return c.getCodeName();
}
-
+
@Override
public String getDebugMessage(final ClassInfo c) {
return c.getCodeName();
@@ -97,17 +96,17 @@ public Fields serialize(final ClassInfo c) {
f.putObject("codeName", c.getCodeName());
return f;
}
-
+
@Override
public boolean canBeInstantiated() {
return false;
}
-
+
@Override
public void deserialize(final ClassInfo o, final Fields f) throws StreamCorruptedException {
assert false;
}
-
+
@Override
protected ClassInfo deserialize(final Fields fields) throws StreamCorruptedException {
final String codeName = fields.getObject("codeName", String.class);
@@ -118,20 +117,20 @@ protected ClassInfo deserialize(final Fields fields) throws StreamCorruptedExcep
throw new StreamCorruptedException("Invalid ClassInfo " + codeName);
return ci;
}
-
+
// return c.getCodeName();
@Override
@Nullable
public ClassInfo deserialize(final String s) {
return Classes.getClassInfoNoError(s);
}
-
+
@Override
public boolean mustSyncDeserialization() {
return false;
}
}));
-
+
Classes.registerClass(new ClassInfo<>(WeatherType.class, "weathertype")
.user("weather ?types?", "weather conditions?", "weathers?")
.name("Weather Type")
@@ -148,12 +147,12 @@ public boolean mustSyncDeserialization() {
public WeatherType parse(final String s, final ParseContext context) {
return WeatherType.parse(s);
}
-
+
@Override
public String toString(final WeatherType o, final int flags) {
return o.toString(flags);
}
-
+
@Override
public String toVariableNameString(final WeatherType o) {
return "" + o.name().toLowerCase(Locale.ENGLISH);
@@ -161,7 +160,7 @@ public String toVariableNameString(final WeatherType o) {
})
.serializer(new EnumSerializer<>(WeatherType.class)));
-
+
Classes.registerClass(new ClassInfo<>(ItemType.class, "itemtype")
.user("item ?types?", "materials?")
.name("Item Type")
@@ -603,7 +602,7 @@ public String toVariableNameString(final EnchantmentType o) {
.since("2.0")
.parser(new Parser() {
private final RegexMessage pattern = new RegexMessage("types.experience.pattern", Pattern.CASE_INSENSITIVE);
-
+
@Override
@Nullable
public Experience parse(String s, final ParseContext context) {
@@ -616,12 +615,12 @@ public Experience parse(String s, final ParseContext context) {
return new Experience(xp);
return null;
}
-
+
@Override
public String toString(final Experience xp, final int flags) {
return xp.toString();
}
-
+
@Override
public String toVariableNameString(final Experience xp) {
return "" + xp.getXP();
@@ -658,7 +657,7 @@ public String toVariableNameString(VisualEffect e) {
})
.serializer(new YggdrasilSerializer<>()));
-
+
Classes.registerClass(new ClassInfo<>(GameruleValue.class, "gamerulevalue")
.user("gamerule values?")
.name("Gamerule Value")
@@ -668,6 +667,31 @@ public String toVariableNameString(VisualEffect e) {
.since("2.5")
.serializer(new YggdrasilSerializer())
);
+
+ Classes.registerClass(new AnyInfo<>(AnyNamed.class, "named")
+ .name("Any Named Thing")
+ .description("Something that has a name (e.g. an item).")
+ .usage("")
+ .examples("{thing}'s name")
+ .since("INSERT VERSION")
+ );
+
+ Classes.registerClass(new AnyInfo<>(AnyAmount.class, "numbered")
+ .name("Any Numbered/Sized Thing")
+ .description("Something that has an amount or size.")
+ .usage("")
+ .examples("the size of {thing}", "the amount of {thing}")
+ .since("INSERT VERSION")
+ );
+
+ Classes.registerClass(new AnyInfo<>(AnyContains.class, "containing")
+ .user("any container")
+ .name("Anything with Contents")
+ .description("Something that contains other things.")
+ .usage("")
+ .examples("{a} contains {b}")
+ .since("INSERT VERSION")
+ );
}
-
+
}
diff --git a/src/main/java/ch/njol/skript/classes/registry/RegistryClassInfo.java b/src/main/java/ch/njol/skript/classes/registry/RegistryClassInfo.java
index 012cbf2eb90..be7c4c8076b 100644
--- a/src/main/java/ch/njol/skript/classes/registry/RegistryClassInfo.java
+++ b/src/main/java/ch/njol/skript/classes/registry/RegistryClassInfo.java
@@ -66,7 +66,7 @@ public RegistryClassInfo(Class registryClass, Registry registry, String co
.parser(registryParser);
if (registerComparator)
- Comparators.registerComparator(registryClass, registryClass, (o1, o2) -> Relation.get(o1.getKey() == o2.getKey()));
+ Comparators.registerComparator(registryClass, registryClass, (o1, o2) -> Relation.get(o1.getKey().equals(o2.getKey())));
}
}
diff --git a/src/main/java/ch/njol/skript/classes/registry/RegistryParser.java b/src/main/java/ch/njol/skript/classes/registry/RegistryParser.java
index dc9bf9f00b7..ba35553f297 100644
--- a/src/main/java/ch/njol/skript/classes/registry/RegistryParser.java
+++ b/src/main/java/ch/njol/skript/classes/registry/RegistryParser.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes.registry;
import ch.njol.skript.classes.Parser;
diff --git a/src/main/java/ch/njol/skript/classes/registry/RegistrySerializer.java b/src/main/java/ch/njol/skript/classes/registry/RegistrySerializer.java
index 33f6645fe52..1a58d6b0912 100644
--- a/src/main/java/ch/njol/skript/classes/registry/RegistrySerializer.java
+++ b/src/main/java/ch/njol/skript/classes/registry/RegistrySerializer.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.classes.registry;
import ch.njol.skript.classes.Serializer;
diff --git a/src/main/java/ch/njol/skript/command/Argument.java b/src/main/java/ch/njol/skript/command/Argument.java
index c66f278d5c4..4147987b404 100644
--- a/src/main/java/ch/njol/skript/command/Argument.java
+++ b/src/main/java/ch/njol/skript/command/Argument.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.command;
import java.util.WeakHashMap;
diff --git a/src/main/java/ch/njol/skript/command/CommandEvent.java b/src/main/java/ch/njol/skript/command/CommandEvent.java
index 07bf63ff046..803debab9f5 100644
--- a/src/main/java/ch/njol/skript/command/CommandEvent.java
+++ b/src/main/java/ch/njol/skript/command/CommandEvent.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.command;
import org.bukkit.command.CommandSender;
diff --git a/src/main/java/ch/njol/skript/command/CommandHelp.java b/src/main/java/ch/njol/skript/command/CommandHelp.java
index 55eea97a06e..f38a73229cf 100644
--- a/src/main/java/ch/njol/skript/command/CommandHelp.java
+++ b/src/main/java/ch/njol/skript/command/CommandHelp.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.command;
import static org.bukkit.ChatColor.GRAY;
diff --git a/src/main/java/ch/njol/skript/command/CommandUsage.java b/src/main/java/ch/njol/skript/command/CommandUsage.java
index c746d93cf8a..8d27f74a87c 100644
--- a/src/main/java/ch/njol/skript/command/CommandUsage.java
+++ b/src/main/java/ch/njol/skript/command/CommandUsage.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.command;
import ch.njol.skript.lang.VariableString;
diff --git a/src/main/java/ch/njol/skript/command/Commands.java b/src/main/java/ch/njol/skript/command/Commands.java
index f6e448b3dad..e8c778bf559 100644
--- a/src/main/java/ch/njol/skript/command/Commands.java
+++ b/src/main/java/ch/njol/skript/command/Commands.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.command;
import ch.njol.skript.ScriptLoader;
@@ -77,7 +59,7 @@ public abstract class Commands {
/**
* A Converter flag declaring that a Converter cannot be used for parsing command arguments.
*/
- public static final int CONVERTER_NO_COMMAND_ARGUMENTS = 4;
+ public static final int CONVERTER_NO_COMMAND_ARGUMENTS = 8;
private final static Map commands = new HashMap<>();
diff --git a/src/main/java/ch/njol/skript/command/EffectCommandEvent.java b/src/main/java/ch/njol/skript/command/EffectCommandEvent.java
index dc411d3547d..76859f65a8d 100644
--- a/src/main/java/ch/njol/skript/command/EffectCommandEvent.java
+++ b/src/main/java/ch/njol/skript/command/EffectCommandEvent.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.command;
import org.bukkit.command.CommandSender;
diff --git a/src/main/java/ch/njol/skript/command/ScriptCommand.java b/src/main/java/ch/njol/skript/command/ScriptCommand.java
index 52e320c9298..e1ed5831108 100644
--- a/src/main/java/ch/njol/skript/command/ScriptCommand.java
+++ b/src/main/java/ch/njol/skript/command/ScriptCommand.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.command;
import ch.njol.skript.ScriptLoader;
diff --git a/src/main/java/ch/njol/skript/command/ScriptCommandEvent.java b/src/main/java/ch/njol/skript/command/ScriptCommandEvent.java
index 91b8f16567c..deed6c35be0 100644
--- a/src/main/java/ch/njol/skript/command/ScriptCommandEvent.java
+++ b/src/main/java/ch/njol/skript/command/ScriptCommandEvent.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.command;
import ch.njol.skript.effects.Delay;
diff --git a/src/main/java/ch/njol/skript/conditions/CondAI.java b/src/main/java/ch/njol/skript/conditions/CondAI.java
index 52370cd07a3..4e4b602f4f7 100644
--- a/src/main/java/ch/njol/skript/conditions/CondAI.java
+++ b/src/main/java/ch/njol/skript/conditions/CondAI.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.entity.LivingEntity;
diff --git a/src/main/java/ch/njol/skript/conditions/CondAlphanumeric.java b/src/main/java/ch/njol/skript/conditions/CondAlphanumeric.java
index d52713979c6..01702442428 100644
--- a/src/main/java/ch/njol/skript/conditions/CondAlphanumeric.java
+++ b/src/main/java/ch/njol/skript/conditions/CondAlphanumeric.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.apache.commons.lang.StringUtils;
diff --git a/src/main/java/ch/njol/skript/conditions/CondAnchorWorks.java b/src/main/java/ch/njol/skript/conditions/CondAnchorWorks.java
index a6c1aafacb1..03768c63793 100644
--- a/src/main/java/ch/njol/skript/conditions/CondAnchorWorks.java
+++ b/src/main/java/ch/njol/skript/conditions/CondAnchorWorks.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/conditions/CondCanFly.java b/src/main/java/ch/njol/skript/conditions/CondCanFly.java
index 478c0e862d4..efbd07272d4 100644
--- a/src/main/java/ch/njol/skript/conditions/CondCanFly.java
+++ b/src/main/java/ch/njol/skript/conditions/CondCanFly.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.entity.Player;
diff --git a/src/main/java/ch/njol/skript/conditions/CondCanHold.java b/src/main/java/ch/njol/skript/conditions/CondCanHold.java
index 8705c325a81..bfbcd70af9e 100644
--- a/src/main/java/ch/njol/skript/conditions/CondCanHold.java
+++ b/src/main/java/ch/njol/skript/conditions/CondCanHold.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.event.Event;
diff --git a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java
index 07f5735e4f9..1bfb6d0aeac 100644
--- a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java
+++ b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.conditions.base.PropertyCondition;
diff --git a/src/main/java/ch/njol/skript/conditions/CondCancelled.java b/src/main/java/ch/njol/skript/conditions/CondCancelled.java
index 4fcf70dfd03..29e98ae3c54 100644
--- a/src/main/java/ch/njol/skript/conditions/CondCancelled.java
+++ b/src/main/java/ch/njol/skript/conditions/CondCancelled.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/conditions/CondChance.java b/src/main/java/ch/njol/skript/conditions/CondChance.java
index 88359eb4867..1b2326adafb 100644
--- a/src/main/java/ch/njol/skript/conditions/CondChance.java
+++ b/src/main/java/ch/njol/skript/conditions/CondChance.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.event.Event;
diff --git a/src/main/java/ch/njol/skript/conditions/CondCompare.java b/src/main/java/ch/njol/skript/conditions/CondCompare.java
index e17cb31e861..bcdc9556de9 100644
--- a/src/main/java/ch/njol/skript/conditions/CondCompare.java
+++ b/src/main/java/ch/njol/skript/conditions/CondCompare.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.lang.VerboseAssert;
diff --git a/src/main/java/ch/njol/skript/conditions/CondContains.java b/src/main/java/ch/njol/skript/conditions/CondContains.java
index 0c54c1be88d..366141ae0b3 100644
--- a/src/main/java/ch/njol/skript/conditions/CondContains.java
+++ b/src/main/java/ch/njol/skript/conditions/CondContains.java
@@ -1,26 +1,9 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
import ch.njol.skript.SkriptConfig;
import ch.njol.skript.aliases.ItemType;
+import ch.njol.skript.lang.util.common.AnyContains;
import org.skriptlang.skript.lang.comparator.Relation;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
@@ -36,14 +19,16 @@
import org.bukkit.event.Event;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
+import org.skriptlang.skript.lang.converter.Converters;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Objects;
@Name("Contains")
-@Description("Checks whether an inventory contains an item, a text contains another piece of text, " +
- "or a list (e.g. {list variable::*} or 'drops') contains another object.")
+@Description("Checks whether an inventory contains an item, a text contains another piece of text, "
+ + "a container contains something, "
+ + "or a list (e.g. {list variable::*} or 'drops') contains another object.")
@Examples({"block contains 20 cobblestone",
"player has 4 flint and 2 iron ingots",
"{list::*} contains 5"})
@@ -63,16 +48,13 @@ public class CondContains extends Condition {
* The type of check to perform
*/
private enum CheckType {
- STRING, INVENTORY, OBJECTS, UNKNOWN
+ STRING, INVENTORY, OBJECTS, UNKNOWN, CONTAINER
}
- @SuppressWarnings("NotNullFieldNotInitialized")
private Expression> containers;
- @SuppressWarnings("NotNullFieldNotInitialized")
private Expression> items;
private boolean explicitSingle;
- @SuppressWarnings("NotNullFieldNotInitialized")
private CheckType checkType;
@Override
@@ -88,15 +70,15 @@ public boolean init(Expression>[] exprs, int matchedPattern, Kleenean isDelaye
checkType = CheckType.UNKNOWN;
}
- setNegated(matchedPattern % 2 == 1);
+ this.setNegated(matchedPattern % 2 == 1);
return true;
}
@Override
- public boolean check(Event e) {
+ public boolean check(Event event) {
CheckType checkType = this.checkType;
- Object[] containerValues = containers.getAll(e);
+ Object[] containerValues = containers.getAll(event);
if (containerValues.length == 0)
return isNegated();
@@ -106,6 +88,11 @@ public boolean check(Event e) {
if (Arrays.stream(containerValues)
.allMatch(Inventory.class::isInstance)) {
checkType = CheckType.INVENTORY;
+ } else if (explicitSingle
+ && Arrays.stream(containerValues)
+ .allMatch(object -> object instanceof AnyContains>
+ || Converters.converterExists(object.getClass(), AnyContains.class))) {
+ checkType = CheckType.CONTAINER;
} else if (explicitSingle
&& Arrays.stream(containerValues)
.allMatch(String.class::isInstance)) {
@@ -115,48 +102,60 @@ public boolean check(Event e) {
}
}
- if (checkType == CheckType.INVENTORY) {
- return SimpleExpression.check(containerValues, o -> {
+ return switch (checkType) {
+ case INVENTORY -> SimpleExpression.check(containerValues, o -> {
Inventory inventory = (Inventory) o;
- return items.check(e, o1 -> {
- if (o1 instanceof ItemType)
- return ((ItemType) o1).isContainedIn(inventory);
- else if (o1 instanceof ItemStack)
- return inventory.containsAtLeast((ItemStack) o1, ((ItemStack) o1).getAmount());
- else if (o1 instanceof Inventory)
+ return items.check(event, o1 -> {
+ if (o1 instanceof ItemType type) {
+ return type.isContainedIn(inventory);
+ } else if (o1 instanceof ItemStack stack) {
+ return inventory.containsAtLeast(stack, stack.getAmount());
+ } else if (o1 instanceof Inventory) {
return Objects.equals(inventory, o1);
- else
- return false;
- });
- }, isNegated(), containers.getAnd());
- } else if (checkType == CheckType.STRING) {
- boolean caseSensitive = SkriptConfig.caseSensitive.value();
-
- return SimpleExpression.check(containerValues, o -> {
- String string = (String) o;
-
- return items.check(e, o1 -> {
- if (o1 instanceof String) {
- return StringUtils.contains(string, (String) o1, caseSensitive);
- } else {
- return false;
}
+ return false;
});
}, isNegated(), containers.getAnd());
- } else {
- assert checkType == CheckType.OBJECTS;
-
- return items.check(e, o1 -> {
- for (Object o2 : containerValues) {
- if (Comparators.compare(o1, o2) == Relation.EQUAL)
- return true;
+ case STRING -> {
+ boolean caseSensitive = SkriptConfig.caseSensitive.value();
+
+ yield SimpleExpression.check(containerValues, o -> {
+ String string = (String) o;
+
+ return items.check(event, o1 -> {
+ if (o1 instanceof String text) {
+ return StringUtils.contains(string, text, caseSensitive);
+ } else {
+ return false;
+ }
+ });
+ }, isNegated(), containers.getAnd());
+ }
+ case CONTAINER -> SimpleExpression.check(containerValues, object -> {
+ AnyContains container;
+ if (object instanceof AnyContains>) {
+ container = (AnyContains) object;
+ } else {
+ container = Converters.convert(object, AnyContains.class);
}
- return false;
- }, isNegated());
- }
+ if (container == null)
+ return false;
+ return items.check(event, container::checkSafely);
+ }, isNegated(), containers.getAnd());
+ default -> {
+ assert checkType == CheckType.OBJECTS;
+ yield items.check(event, o1 -> {
+ for (Object o2 : containerValues) {
+ if (Comparators.compare(o1, o2) == Relation.EQUAL)
+ return true;
+ }
+ return false;
+ }, isNegated());
+ }
+ };
}
-
+
@Override
public String toString(@Nullable Event e, boolean debug) {
return containers.toString(e, debug) + (isNegated() ? " doesn't contain " : " contains ") + items.toString(e, debug);
diff --git a/src/main/java/ch/njol/skript/conditions/CondDamageCause.java b/src/main/java/ch/njol/skript/conditions/CondDamageCause.java
index 59c6421af77..53cda6b0c00 100644
--- a/src/main/java/ch/njol/skript/conditions/CondDamageCause.java
+++ b/src/main/java/ch/njol/skript/conditions/CondDamageCause.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.event.Event;
diff --git a/src/main/java/ch/njol/skript/conditions/CondDate.java b/src/main/java/ch/njol/skript/conditions/CondDate.java
index 7172e9e80b1..47a20522fb3 100644
--- a/src/main/java/ch/njol/skript/conditions/CondDate.java
+++ b/src/main/java/ch/njol/skript/conditions/CondDate.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.event.Event;
diff --git a/src/main/java/ch/njol/skript/conditions/CondElytraBoostConsume.java b/src/main/java/ch/njol/skript/conditions/CondElytraBoostConsume.java
new file mode 100644
index 00000000000..ed971a3aed2
--- /dev/null
+++ b/src/main/java/ch/njol/skript/conditions/CondElytraBoostConsume.java
@@ -0,0 +1,56 @@
+package ch.njol.skript.conditions;
+
+import ch.njol.skript.Skript;
+import ch.njol.skript.doc.*;
+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 com.destroystokyo.paper.event.player.PlayerElytraBoostEvent;
+import org.bukkit.event.Event;
+import org.jetbrains.annotations.Nullable;
+
+@Name("Will Consume Boosting Firework")
+@Description("Checks to see if the firework used in an 'elytra boost' event will be consumed.")
+@Examples({
+ "on elytra boost:",
+ "\tif the used firework will be consumed:",
+ "\t\tprevent the used firework from being consume"
+})
+@RequiredPlugins("Paper")
+@Since("INSERT VERSION")
+public class CondElytraBoostConsume extends Condition {
+
+ static {
+ if (Skript.classExists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent")) {
+ Skript.registerCondition(CondElytraBoostConsume.class,
+ "[the] (boosting|used) firework will be consumed",
+ "[the] (boosting|used) firework (will not|won't) be consumed");
+ }
+ }
+
+ private boolean checkConsume;
+
+ @Override
+ public boolean init(Expression>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
+ if (!getParser().isCurrentEvent(PlayerElytraBoostEvent.class)) {
+ Skript.error("This condition can only be used in an 'elytra boost' event.");
+ return false;
+ }
+ checkConsume = matchedPattern == 0;
+ return true;
+ }
+
+ @Override
+ public boolean check(Event event) {
+ if (!(event instanceof PlayerElytraBoostEvent boostEvent))
+ return false;
+ return boostEvent.shouldConsume() == checkConsume;
+ }
+
+ @Override
+ public String toString(@Nullable Event event, boolean debug) {
+ return "the boosting firework will " + (checkConsume ? "" : "not") + " be consumed";
+ }
+
+}
diff --git a/src/main/java/ch/njol/skript/conditions/CondEntityIsInLiquid.java b/src/main/java/ch/njol/skript/conditions/CondEntityIsInLiquid.java
index c2f838e148c..d470d0b14e8 100644
--- a/src/main/java/ch/njol/skript/conditions/CondEntityIsInLiquid.java
+++ b/src/main/java/ch/njol/skript/conditions/CondEntityIsInLiquid.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/conditions/CondEntityIsWet.java b/src/main/java/ch/njol/skript/conditions/CondEntityIsWet.java
index e013696582b..4b1dd579236 100644
--- a/src/main/java/ch/njol/skript/conditions/CondEntityIsWet.java
+++ b/src/main/java/ch/njol/skript/conditions/CondEntityIsWet.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/conditions/CondGlowingText.java b/src/main/java/ch/njol/skript/conditions/CondGlowingText.java
index aaf14939305..f7d42248377 100644
--- a/src/main/java/ch/njol/skript/conditions/CondGlowingText.java
+++ b/src/main/java/ch/njol/skript/conditions/CondGlowingText.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/conditions/CondHasClientWeather.java b/src/main/java/ch/njol/skript/conditions/CondHasClientWeather.java
index e9284a38807..0719ebf94ac 100755
--- a/src/main/java/ch/njol/skript/conditions/CondHasClientWeather.java
+++ b/src/main/java/ch/njol/skript/conditions/CondHasClientWeather.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.entity.Player;
diff --git a/src/main/java/ch/njol/skript/conditions/CondHasCustomModelData.java b/src/main/java/ch/njol/skript/conditions/CondHasCustomModelData.java
index 98f86424826..66621f9e91b 100644
--- a/src/main/java/ch/njol/skript/conditions/CondHasCustomModelData.java
+++ b/src/main/java/ch/njol/skript/conditions/CondHasCustomModelData.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.inventory.meta.ItemMeta;
diff --git a/src/main/java/ch/njol/skript/conditions/CondHasItemCooldown.java b/src/main/java/ch/njol/skript/conditions/CondHasItemCooldown.java
index 9e1d1fcf4db..dd67a64d6fc 100644
--- a/src/main/java/ch/njol/skript/conditions/CondHasItemCooldown.java
+++ b/src/main/java/ch/njol/skript/conditions/CondHasItemCooldown.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/conditions/CondHasLineOfSight.java b/src/main/java/ch/njol/skript/conditions/CondHasLineOfSight.java
index 706fa4f8629..b5e8dae5571 100644
--- a/src/main/java/ch/njol/skript/conditions/CondHasLineOfSight.java
+++ b/src/main/java/ch/njol/skript/conditions/CondHasLineOfSight.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/conditions/CondHasMetadata.java b/src/main/java/ch/njol/skript/conditions/CondHasMetadata.java
index 876a74249f8..cfb60086fd5 100644
--- a/src/main/java/ch/njol/skript/conditions/CondHasMetadata.java
+++ b/src/main/java/ch/njol/skript/conditions/CondHasMetadata.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java
index 41aa7fa55c8..b71b6298d27 100644
--- a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java
+++ b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.Skript;
diff --git a/src/main/java/ch/njol/skript/conditions/CondHasResourcePack.java b/src/main/java/ch/njol/skript/conditions/CondHasResourcePack.java
index 3d0eda99ef0..1b944f97134 100644
--- a/src/main/java/ch/njol/skript/conditions/CondHasResourcePack.java
+++ b/src/main/java/ch/njol/skript/conditions/CondHasResourcePack.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.entity.Player;
diff --git a/src/main/java/ch/njol/skript/conditions/CondHasScoreboardTag.java b/src/main/java/ch/njol/skript/conditions/CondHasScoreboardTag.java
index 0fe7942cf62..db7ffd61df4 100644
--- a/src/main/java/ch/njol/skript/conditions/CondHasScoreboardTag.java
+++ b/src/main/java/ch/njol/skript/conditions/CondHasScoreboardTag.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import java.util.Arrays;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIgnitionProcess.java b/src/main/java/ch/njol/skript/conditions/CondIgnitionProcess.java
index e0d0f1849c9..f59bc77a819 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIgnitionProcess.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIgnitionProcess.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.entity.Creeper;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIncendiary.java b/src/main/java/ch/njol/skript/conditions/CondIncendiary.java
index a4d47b012ac..5ee20c07cec 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIncendiary.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIncendiary.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.entity.Entity;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIsAlive.java b/src/main/java/ch/njol/skript/conditions/CondIsAlive.java
index 714b0ae5953..5026d5199ab 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIsAlive.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIsAlive.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.entity.Entity;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIsBanned.java b/src/main/java/ch/njol/skript/conditions/CondIsBanned.java
index 212da063416..37fc818c2ac 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIsBanned.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIsBanned.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import java.net.InetSocketAddress;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIsBlock.java b/src/main/java/ch/njol/skript/conditions/CondIsBlock.java
index efafb2583b7..ee4035336b4 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIsBlock.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIsBlock.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.aliases.ItemType;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIsBlockRedstonePowered.java b/src/main/java/ch/njol/skript/conditions/CondIsBlockRedstonePowered.java
index b7ec7be8027..86cba581c0e 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIsBlockRedstonePowered.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIsBlockRedstonePowered.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.block.Block;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIsBlocking.java b/src/main/java/ch/njol/skript/conditions/CondIsBlocking.java
index 6d81a2633a6..684c3c38370 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIsBlocking.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIsBlocking.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.entity.Player;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIsBurning.java b/src/main/java/ch/njol/skript/conditions/CondIsBurning.java
index b1b42efa5e0..f2e7838edf8 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIsBurning.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIsBurning.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.entity.Entity;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIsClimbing.java b/src/main/java/ch/njol/skript/conditions/CondIsClimbing.java
index 48cdfe5eb40..0acb7ffeeba 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIsClimbing.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIsClimbing.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import org.bukkit.entity.LivingEntity;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIsEdible.java b/src/main/java/ch/njol/skript/conditions/CondIsEdible.java
index 8545da529f9..d386c321a0f 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIsEdible.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIsEdible.java
@@ -1,21 +1,3 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
import ch.njol.skript.aliases.ItemType;
diff --git a/src/main/java/ch/njol/skript/conditions/CondIsEmpty.java b/src/main/java/ch/njol/skript/conditions/CondIsEmpty.java
index 972f38ed5d3..d3eb1825c3e 100644
--- a/src/main/java/ch/njol/skript/conditions/CondIsEmpty.java
+++ b/src/main/java/ch/njol/skript/conditions/CondIsEmpty.java
@@ -1,70 +1,51 @@
-/**
- * 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 .
- *
- * Copyright Peter Güttinger, SkriptLang team and contributors
- */
package ch.njol.skript.conditions;
-import org.bukkit.Material;
-import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.ItemStack;
-
import ch.njol.skript.conditions.base.PropertyCondition;
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.util.common.AnyAmount;
import ch.njol.skript.util.slot.Slot;
+import org.bukkit.Material;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
-/**
- * @author Peter Güttinger
- */
@Name("Is Empty")
@Description("Checks whether an inventory, an inventory slot, or a text is empty.")
@Examples("player's inventory is empty")
@Since("unknown (before 2.1)")
public class CondIsEmpty extends PropertyCondition