Skip to content

Commit 371fb88

Browse files
Stabilize Registration API (SkriptLang#8316)
1 parent 24a2435 commit 371fb88

42 files changed

Lines changed: 554 additions & 349 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/ch/njol/skript/Skript.java

Lines changed: 130 additions & 25 deletions
Large diffs are not rendered by default.

src/main/java/ch/njol/skript/SkriptAddon.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
import java.util.regex.Matcher;
77
import java.util.regex.Pattern;
88

9-
import org.bukkit.Bukkit;
10-
import org.bukkit.plugin.Plugin;
119
import org.bukkit.plugin.java.JavaPlugin;
1210
import org.jetbrains.annotations.Nullable;
1311

1412
import ch.njol.skript.util.Utils;
1513
import ch.njol.skript.util.Version;
16-
import org.jetbrains.annotations.ApiStatus;
1714
import org.skriptlang.skript.localization.Localizer;
1815
import org.skriptlang.skript.registration.SyntaxRegistry;
1916
import org.skriptlang.skript.util.Registry;
2017

2118
/**
2219
* Utility class for Skript addons. Use {@link Skript#registerAddon(JavaPlugin)} to create a SkriptAddon instance for your plugin.
20+
* @deprecated Use {@link org.skriptlang.skript.addon.SkriptAddon} instead.
21+
* Register using {@link org.skriptlang.skript.Skript#registerAddon(Class, String)}.
22+
* Obtain a Skript instance with {@link Skript#instance()}.
2323
*/
24+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
2425
public final class SkriptAddon implements org.skriptlang.skript.addon.SkriptAddon {
2526

2627
public final JavaPlugin plugin;
@@ -114,61 +115,51 @@ public File getFile() {
114115
// Modern SkriptAddon Compatibility
115116
//
116117

117-
@ApiStatus.Experimental
118118
static SkriptAddon fromModern(org.skriptlang.skript.addon.SkriptAddon addon) {
119119
return new SkriptAddon(JavaPlugin.getProvidingPlugin(addon.source()), addon);
120120
}
121121

122122
@Override
123-
@ApiStatus.Experimental
124123
public Class<?> source() {
125124
return addon.source();
126125
}
127126

128127
@Override
129-
@ApiStatus.Experimental
130128
public String name() {
131129
return addon.name();
132130
}
133131

134132
@Override
135-
@ApiStatus.Experimental
136133
public <R extends Registry<?>> void storeRegistry(Class<R> registryClass, R registry) {
137134
addon.storeRegistry(registryClass, registry);
138135
}
139136

140137
@Override
141-
@ApiStatus.Experimental
142138
public void removeRegistry(Class<? extends Registry<?>> registryClass) {
143139
addon.removeRegistry(registryClass);
144140
}
145141

146142
@Override
147-
@ApiStatus.Experimental
148143
public boolean hasRegistry(Class<? extends Registry<?>> registryClass) {
149144
return addon.hasRegistry(registryClass);
150145
}
151146

152147
@Override
153-
@ApiStatus.Experimental
154148
public <R extends Registry<?>> R registry(Class<R> registryClass) {
155149
return addon.registry(registryClass);
156150
}
157151

158152
@Override
159-
@ApiStatus.Experimental
160153
public <R extends Registry<?>> R registry(Class<R> registryClass, Supplier<R> putIfAbsent) {
161154
return addon.registry(registryClass, putIfAbsent);
162155
}
163156

164157
@Override
165-
@ApiStatus.Experimental
166158
public SyntaxRegistry syntaxRegistry() {
167159
return addon.syntaxRegistry();
168160
}
169161

170162
@Override
171-
@ApiStatus.Experimental
172163
public Localizer localizer() {
173164
return addon.localizer();
174165
}

src/main/java/ch/njol/skript/SkriptCommand.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import org.bukkit.command.CommandSender;
3030
import org.bukkit.plugin.Plugin;
3131
import org.bukkit.plugin.PluginDescriptionFile;
32+
import org.bukkit.plugin.java.JavaPlugin;
3233
import org.jetbrains.annotations.Nullable;
34+
import org.skriptlang.skript.addon.SkriptAddon;
3335
import org.skriptlang.skript.lang.script.Script;
3436

3537
import java.io.File;
@@ -356,10 +358,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
356358
info(sender, "info.version", Skript.getVersion());
357359
}
358360

359-
Collection<SkriptAddon> addons = Skript.getAddons();
361+
Collection<SkriptAddon> addons = Skript.instance().addons();
360362
info(sender, "info.addons", addons.isEmpty() ? "None" : "");
361363
for (SkriptAddon addon : addons) {
362-
PluginDescriptionFile desc = addon.plugin.getDescription();
364+
JavaPlugin plugin = JavaPlugin.getProvidingPlugin(addon.source());
365+
PluginDescriptionFile desc = plugin.getDescription();
363366
String web = desc.getWebsite();
364367
Skript.info(sender, " - " + desc.getFullName() + (web != null ? " (" + web + ")" : ""));
365368
}

src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
import ch.njol.skript.lang.SkriptParser.ParseResult;
88
import ch.njol.util.Kleenean;
99
import org.bukkit.event.Event;
10-
import org.jetbrains.annotations.ApiStatus;
1110
import org.jetbrains.annotations.NotNull;
1211
import org.jetbrains.annotations.Nullable;
1312
import org.skriptlang.skript.registration.SyntaxInfo;
14-
import org.skriptlang.skript.registration.SyntaxRegistry;
1513
import org.skriptlang.skript.util.Priority;
1614

1715
import java.util.function.Predicate;
@@ -46,7 +44,6 @@ public abstract class PropertyCondition<T> extends Condition implements Predicat
4644
* They will be registered before {@link SyntaxInfo#PATTERN_MATCHES_EVERYTHING} expressions
4745
* but after {@link SyntaxInfo#COMBINED} expressions.
4846
*/
49-
@ApiStatus.Experimental
5047
public static final Priority DEFAULT_PRIORITY = Priority.before(SyntaxInfo.PATTERN_MATCHES_EVERYTHING);
5148

5249
/**
@@ -78,43 +75,6 @@ public enum PropertyType {
7875
WILL
7976
}
8077

81-
/**
82-
* @param registry The SyntaxRegistry to register with.
83-
* @param condition The class to register
84-
* @param property The property name, for example <i>fly</i> in <i>players can fly</i>
85-
* @param type Must be plural, for example <i>players</i> in <i>players can fly</i>
86-
* @param <E> The Condition type.
87-
* @return The registered {@link SyntaxInfo}.
88-
* @deprecated Use {@link #infoBuilder(Class, PropertyType, String, String)} to build a {@link SyntaxInfo}
89-
* and then register it using {@code registry} ({@link SyntaxRegistry#register(SyntaxRegistry.Key, SyntaxInfo)}).
90-
*/
91-
@ApiStatus.Experimental
92-
@Deprecated(since = "2.12", forRemoval = true)
93-
public static <E extends Condition> SyntaxInfo<E> register(SyntaxRegistry registry, Class<E> condition, String property, String type) {
94-
return register(registry, condition, PropertyType.BE, property, type);
95-
}
96-
97-
/**
98-
* @param registry The SyntaxRegistry to register with.
99-
* @param condition The class to register
100-
* @param propertyType The property type, see {@link PropertyType}
101-
* @param property The property name, for example <i>fly</i> in <i>players can fly</i>
102-
* @param type Must be plural, for example <i>players</i> in <i>players can fly</i>
103-
* @param <E> The Condition type.
104-
* @return The registered {@link SyntaxInfo}.
105-
* @deprecated Use {@link #infoBuilder(Class, PropertyType, String, String)} to build a {@link SyntaxInfo}
106-
* and then register it using {@code registry} ({@link SyntaxRegistry#register(SyntaxRegistry.Key, SyntaxInfo)}).
107-
*/
108-
@ApiStatus.Experimental
109-
@Deprecated(since = "2.12", forRemoval = true)
110-
public static <E extends Condition> SyntaxInfo<E> register(SyntaxRegistry registry, Class<E> condition, PropertyType propertyType, String property, String type) {
111-
if (type.contains("%"))
112-
throw new SkriptAPIException("The type argument must not contain any '%'s");
113-
SyntaxInfo<E> info = infoBuilder(condition, propertyType, property, type).build();
114-
registry.register(SyntaxRegistry.CONDITION, info);
115-
return info;
116-
}
117-
11878
/**
11979
* Creates a builder for a {@link SyntaxInfo} representing a {@link PropertyCondition}.
12080
* Patterns will be appended based on the {@code propertyType} (see {@link #getPatterns(PropertyType, String, String)}).
@@ -127,7 +87,6 @@ public static <E extends Condition> SyntaxInfo<E> register(SyntaxRegistry regist
12787
* @param <E> The Condition type.
12888
* @return A {@link SyntaxInfo} representing the property conditon.
12989
*/
130-
@ApiStatus.Experimental
13190
public static <E extends Condition> SyntaxInfo.Builder<? extends SyntaxInfo.Builder<?, E>, E> infoBuilder(
13291
Class<E> condition, PropertyType propertyType, String property, String type) {
13392
if (type.contains("%"))
@@ -143,7 +102,10 @@ public static <E extends Condition> SyntaxInfo.Builder<? extends SyntaxInfo.Buil
143102
* @param condition the class to register
144103
* @param property the property name, for example <i>fly</i> in <i>players can fly</i>
145104
* @param type must be plural, for example <i>players</i> in <i>players can fly</i>
105+
* @deprecated Register the standard way using {@link #infoBuilder(Class, PropertyType, String, String)}
106+
* to create a {@link SyntaxInfo}.
146107
*/
108+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
147109
public static void register(Class<? extends Condition> condition, String property, String type) {
148110
register(condition, PropertyType.BE, property, type);
149111
}
@@ -155,7 +117,10 @@ public static void register(Class<? extends Condition> condition, String propert
155117
* @param propertyType the property type, see {@link PropertyType}
156118
* @param property the property name, for example <i>fly</i> in <i>players can fly</i>
157119
* @param type must be plural, for example <i>players</i> in <i>players can fly</i>
120+
* @deprecated Register the standard way using {@link #infoBuilder(Class, PropertyType, String, String)}
121+
* to create a {@link SyntaxInfo}.
158122
*/
123+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
159124
public static void register(Class<? extends Condition> condition, PropertyType propertyType, String property, String type) {
160125
Skript.registerCondition(condition, ConditionType.PROPERTY,
161126
getPatterns(propertyType, property, type));
@@ -167,7 +132,7 @@ public static void register(Class<? extends Condition> condition, PropertyType p
167132
* @param propertyType the property type, see {@link PropertyType}
168133
* @param property the property name, for example <i>fly</i> in <i>players can fly</i>
169134
* @param type must be plural, for example <i>players</i> in <i>players can fly</i>
170-
* @return patterns formmated for {@link Skript#registerCondition(Class, String...)}
135+
* @return Patterns formatted for syntax registration.
171136
*/
172137
public static String[] getPatterns(PropertyType propertyType, String property, String type) {
173138
if (type.contains("%"))

src/main/java/ch/njol/skript/doc/JSONGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.jetbrains.annotations.Nullable;
2626
import org.skriptlang.skript.lang.experiment.Experiment;
2727
import org.skriptlang.skript.addon.SkriptAddon;
28-
import org.skriptlang.skript.bukkit.registration.BukkitRegistryKeys;
2928
import org.skriptlang.skript.bukkit.registration.BukkitSyntaxInfos;
3029
import org.skriptlang.skript.lang.properties.Property;
3130
import org.skriptlang.skript.lang.properties.PropertyRegistry;
@@ -659,7 +658,7 @@ public void generate(@NotNull Path path) throws IOException {
659658
jsonDocs.add("conditions", generateSyntaxElementArray(source.syntaxRegistry().syntaxes(SyntaxRegistry.CONDITION)));
660659
jsonDocs.add("effects", generateSyntaxElementArray(source.syntaxRegistry().syntaxes(SyntaxRegistry.EFFECT)));
661660
jsonDocs.add("expressions", generateSyntaxElementArray(source.syntaxRegistry().syntaxes(SyntaxRegistry.EXPRESSION)));
662-
jsonDocs.add("events", generateStructureElementArray(source.syntaxRegistry().syntaxes(BukkitRegistryKeys.EVENT)));
661+
jsonDocs.add("events", generateStructureElementArray(source.syntaxRegistry().syntaxes(BukkitSyntaxInfos.Event.KEY)));
663662
jsonDocs.add("structures", generateStructureElementArray(source.syntaxRegistry().syntaxes(SyntaxRegistry.STRUCTURE)));
664663
jsonDocs.add("sections", generateSyntaxElementArray(source.syntaxRegistry().syntaxes(SyntaxRegistry.SECTION)));
665664
jsonDocs.add("types", generateClassInfoArray(Classes.getClassInfos().iterator()));

src/main/java/ch/njol/skript/expressions/base/EventValueExpression.java

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -61,58 +61,8 @@ public class EventValueExpression<T> extends SimpleExpression<T> implements Defa
6161
* They will be registered before {@link SyntaxInfo#COMBINED} expressions
6262
* but after {@link SyntaxInfo#SIMPLE} expressions.
6363
*/
64-
@ApiStatus.Experimental
6564
public static final Priority DEFAULT_PRIORITY = Priority.before(SyntaxInfo.COMBINED);
6665

67-
/**
68-
* Registers an event value expression with the provided pattern.
69-
* The syntax info will be forced to use the {@link #DEFAULT_PRIORITY} priority.
70-
* This also adds '[the]' to the start of the pattern.
71-
*
72-
* @param registry The SyntaxRegistry to register with.
73-
* @param expressionClass The EventValueExpression class being registered.
74-
* @param returnType The class representing the expression's return type.
75-
* @param pattern The pattern to match for creating this expression.
76-
* @param <T> The return type.
77-
* @param <E> The Expression type.
78-
* @return The registered {@link SyntaxInfo}.
79-
* @deprecated Use {@link #infoBuilder(Class, Class, String...)} to build a {@link SyntaxInfo}
80-
* and then register it using {@code registry} ({@link SyntaxRegistry#register(SyntaxRegistry.Key, SyntaxInfo)}).
81-
*/
82-
@ApiStatus.Experimental
83-
@Deprecated(since = "2.12", forRemoval = true)
84-
public static <E extends EventValueExpression<T>, T> SyntaxInfo.Expression<E, T> register(SyntaxRegistry registry, Class<E> expressionClass, Class<T> returnType, String pattern) {
85-
return register(registry, expressionClass, returnType, new String[]{pattern});
86-
}
87-
88-
/**
89-
* Registers an event value expression with the provided patterns.
90-
* The syntax info will be forced to use the {@link #DEFAULT_PRIORITY} priority.
91-
* This also adds '[the]' to the start of the patterns.
92-
*
93-
* @param registry The SyntaxRegistry to register with.
94-
* @param expressionClass The EventValueExpression class being registered.
95-
* @param returnType The class representing the expression's return type.
96-
* @param patterns The patterns to match for creating this expression.
97-
* @param <T> The return type.
98-
* @param <E> The Expression type.
99-
* @return The registered {@link SyntaxInfo}.
100-
* @deprecated Use {@link #infoBuilder(Class, Class, String...)} to build a {@link SyntaxInfo}
101-
* and then register it using {@code registry} ({@link SyntaxRegistry#register(SyntaxRegistry.Key, SyntaxInfo)}).
102-
*/
103-
@ApiStatus.Experimental
104-
@Deprecated(since = "2.12", forRemoval = true)
105-
public static <E extends EventValueExpression<T>, T> DefaultSyntaxInfos.Expression<E, T> register(
106-
SyntaxRegistry registry,
107-
Class<E> expressionClass,
108-
Class<T> returnType,
109-
String ... patterns
110-
) {
111-
SyntaxInfo.Expression<E, T> info = infoBuilder(expressionClass, returnType, patterns).build();
112-
registry.register(SyntaxRegistry.EXPRESSION, info);
113-
return info;
114-
}
115-
11666
/**
11767
* Creates a builder for a {@link SyntaxInfo} representing a {@link EventValueExpression} with the provided patterns.
11868
* The info will use {@link #DEFAULT_PRIORITY} as its {@link SyntaxInfo#priority()}.
@@ -124,7 +74,6 @@ public static <E extends EventValueExpression<T>, T> DefaultSyntaxInfos.Expressi
12474
* @param <E> The Expression type.
12575
* @return The registered {@link SyntaxInfo}.
12676
*/
127-
@ApiStatus.Experimental
12877
public static <E extends EventValueExpression<T>, T> SyntaxInfo.Expression.Builder<? extends SyntaxInfo.Expression.Builder<?, E, T>, E, T> infoBuilder(
12978
Class<E> expressionClass, Class<T> returnType, String... patterns) {
13079
for (int i = 0; i < patterns.length; i++) {
@@ -142,7 +91,10 @@ public static <E extends EventValueExpression<T>, T> SyntaxInfo.Expression.Build
14291
* @param expression The class that represents this EventValueExpression.
14392
* @param type The return type of the expression.
14493
* @param pattern The pattern for this syntax.
94+
* @deprecated Register the standard way using {@link #infoBuilder(Class, Class, String...)}
95+
* to create a {@link SyntaxInfo}.
14596
*/
97+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
14698
public static <T> void register(Class<? extends EventValueExpression<T>> expression, Class<T> type, String pattern) {
14799
Skript.registerExpression(expression, type, ExpressionType.EVENT, "[the] " + pattern);
148100
}
@@ -154,7 +106,10 @@ public static <T> void register(Class<? extends EventValueExpression<T>> express
154106
* @param expression The class that represents this EventValueExpression.
155107
* @param type The return type of the expression.
156108
* @param patterns The patterns for this syntax.
109+
* @deprecated Register the standard way using {@link #infoBuilder(Class, Class, String...)}
110+
* to create a {@link SyntaxInfo}.
157111
*/
112+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
158113
public static <T> void register(Class<? extends EventValueExpression<T>> expression, Class<T> type, String ... patterns) {
159114
for (int i = 0; i < patterns.length; i++) {
160115
if (!StringUtils.startsWithIgnoreCase(patterns[i], "[the] "))

src/main/java/ch/njol/skript/lang/Condition.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import ch.njol.skript.lang.util.SimpleExpression;
88
import ch.njol.util.Kleenean;
99
import org.bukkit.event.Event;
10-
import org.jetbrains.annotations.ApiStatus;
1110
import org.jetbrains.annotations.NotNull;
1211
import org.jetbrains.annotations.Nullable;
1312
import org.skriptlang.skript.lang.condition.Conditional;
@@ -20,41 +19,45 @@
2019

2120
/**
2221
* A condition which must be fulfilled for the trigger to continue. If the condition is in a section the behaviour depends on the section.
23-
*
24-
* @see Skript#registerCondition(Class, String...)
2522
*/
2623
public abstract class Condition extends Statement implements Conditional<Event>, SyntaxRuntimeErrorProducer, Simplifiable<Condition> {
2724

25+
/**
26+
* @deprecated This has been replaced by {@link Priority}.
27+
* See the documentation of each element to determine their replacements.
28+
*/
29+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
2830
public enum ConditionType {
31+
2932
/**
3033
* Conditions that contain other expressions, e.g. "%properties% is/are within %expressions%"
3134
*
3235
* @see #PROPERTY
36+
* @deprecated Use {@link SyntaxInfo#COMBINED}.
3337
*/
3438
COMBINED(SyntaxInfo.COMBINED),
3539

3640
/**
3741
* Property conditions, e.g. "%properties% is/are data value[s]"
42+
* @deprecated Use {@link PropertyCondition#DEFAULT_PRIORITY}.
3843
*/
3944
PROPERTY(PropertyCondition.DEFAULT_PRIORITY),
4045

4146
/**
4247
* Conditions whose pattern matches (almost) everything or should be last checked.
48+
* @deprecated Use {@link SyntaxInfo#PATTERN_MATCHES_EVERYTHING}.
4349
*/
4450
PATTERN_MATCHES_EVERYTHING(SyntaxInfo.PATTERN_MATCHES_EVERYTHING);
4551

46-
@ApiStatus.Experimental
4752
private final Priority priority;
4853

49-
@ApiStatus.Experimental
5054
ConditionType(Priority priority) {
5155
this.priority = priority;
5256
}
5357

5458
/**
5559
* @return The Priority equivalent of this ConditionType.
5660
*/
57-
@ApiStatus.Experimental
5861
public Priority priority() {
5962
return this.priority;
6063
}

src/main/java/ch/njol/skript/lang/ExpressionInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
/**
88
* Represents an expression's information, for use when creating new instances of expressions.
9+
* @deprecated Use {@link SyntaxInfo.Expression} ({@link SyntaxInfo.Expression#builder(Class, Class)}) instead.
910
*/
11+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
1012
public class ExpressionInfo<E extends Expression<T>, T> extends SyntaxElementInfo<E> {
1113

1214
public @Nullable ExpressionType expressionType;

0 commit comments

Comments
 (0)