Skip to content

Commit 6e10d6b

Browse files
Syntax Info Improvements (SkriptLang#8355)
1 parent 3b13b78 commit 6e10d6b

19 files changed

Lines changed: 130 additions & 36 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Collection;
1717
import java.util.List;
1818
import java.util.Locale;
19+
import java.util.SequencedCollection;
1920

2021
/**
2122
* @deprecated Use {@link BukkitSyntaxInfos.Event} ({@link BukkitSyntaxInfos.Event#builder(Class, String)} instead.
@@ -294,13 +295,13 @@ public String id() {
294295
}
295296

296297
@Override
297-
public Collection<String> since() {
298+
public SequencedCollection<String> since() {
298299
String[] since = getSince();
299300
return since != null ? List.of(since) : List.of();
300301
}
301302

302303
@Override
303-
public Collection<String> description() {
304+
public SequencedCollection<String> description() {
304305
String[] description = getDescription();
305306
return description != null ? List.of(description) : List.of();
306307
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import java.lang.reflect.InvocationTargetException;
1616
import java.lang.reflect.Modifier;
1717
import java.util.Arrays;
18-
import java.util.Collection;
1918
import java.util.List;
19+
import java.util.SequencedCollection;
2020

2121
/**
2222
* @param <E> the syntax element this info is for
@@ -139,7 +139,7 @@ public E instance() {
139139

140140
@Override
141141
@ApiStatus.Internal
142-
public @Unmodifiable Collection<String> patterns() {
142+
public @Unmodifiable SequencedCollection<String> patterns() {
143143
if (source != null)
144144
return source.patterns();
145145
return List.of(getPatterns());

src/main/java/org/skriptlang/skript/addon/AddonModule.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@
1414
* The <code>load</code> phase should be used for loading components more specific to the module, such as syntax.
1515
* @see SkriptAddon#loadModules(AddonModule...)
1616
*/
17-
@FunctionalInterface
1817
public interface AddonModule {
1918

2019
/**
2120
* Constructs an origin from an addon and module name.
2221
* @param addon The addon providing the module.
23-
* @param moduleName The name of the providing module.
22+
* @param module The module to construct this origin from.
2423
* @return An origin from the provided information.
2524
*/
26-
static ModuleOrigin origin(SkriptAddon addon, String moduleName) {
27-
return new AddonModuleImpl.ModuleOriginImpl(addon, moduleName);
25+
static ModuleOrigin origin(SkriptAddon addon, AddonModule module) {
26+
return new AddonModuleImpl.ModuleOriginImpl(addon, module.name());
2827
}
2928

3029
/**
@@ -39,6 +38,17 @@ sealed interface ModuleOrigin extends AddonOrigin permits AddonModuleImpl.Module
3938

4039
}
4140

41+
/**
42+
* Allow addons to specify whether they can load or not.
43+
* Called prior to {@link #init(SkriptAddon)}
44+
*
45+
* @param addon The addon this module belongs to.
46+
* @return Whether this module can load.
47+
*/
48+
default boolean canLoad(SkriptAddon addon) {
49+
return true;
50+
}
51+
4252
/**
4353
* Used for loading the components of this module that are needed first or by other modules (e.g. class infos).
4454
* <b>This method will always be called before {@link #load(SkriptAddon)}</b>.
@@ -55,14 +65,8 @@ default void init(SkriptAddon addon) { }
5565
void load(SkriptAddon addon);
5666

5767
/**
58-
* Allow addons to specify whether they can load or not.
59-
* Called prior to {@link #init(SkriptAddon)}
60-
*
61-
* @param addon The addon this module belongs to.
62-
* @return Whether this module can load.
68+
* @return The name of this module.
6369
*/
64-
default boolean canLoad(SkriptAddon addon) {
65-
return true;
66-
}
70+
String name();
6771

6872
}

src/main/java/org/skriptlang/skript/addon/AddonModuleImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
class AddonModuleImpl {
66

7-
public record ModuleOriginImpl(SkriptAddon addon, String moduleName) implements ModuleOrigin { }
7+
public record ModuleOriginImpl(SkriptAddon addon, String moduleName) implements ModuleOrigin {
8+
9+
public ModuleOriginImpl(SkriptAddon addon, String moduleName) {
10+
this.addon = addon.unmodifiableView();
11+
this.moduleName = moduleName;
12+
}
13+
14+
}
815

916
}

src/main/java/org/skriptlang/skript/bukkit/brewing/BrewingModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ private void register(SyntaxRegistry registry, Consumer<SyntaxRegistry>... consu
4141
Arrays.stream(consumers).forEach(consumer -> consumer.accept(registry));
4242
}
4343

44+
@Override
45+
public String name() {
46+
return "brewing";
47+
}
48+
4449
}

src/main/java/org/skriptlang/skript/bukkit/damagesource/DamageSourceModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ public void load(SkriptAddon addon) {
6161
}
6262
}
6363

64+
@Override
65+
public String name() {
66+
return "damage source";
67+
}
68+
6469
}

src/main/java/org/skriptlang/skript/bukkit/entity/EntityModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ public void load(SkriptAddon addon) {
1818
}
1919
}
2020

21+
@Override
22+
public String name() {
23+
return "entity";
24+
}
25+
2126
}

src/main/java/org/skriptlang/skript/bukkit/interactions/InteractionModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ public enum InteractionType {
4848
return interact;
4949
}
5050

51+
@Override
52+
public String name() {
53+
return "interaction";
54+
}
55+
5156
}

src/main/java/org/skriptlang/skript/bukkit/itemcomponents/ItemComponentModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ public void load(SkriptAddon addon) {
5252
ExprItemCompCopy.register(addon.syntaxRegistry());
5353
}
5454

55+
@Override
56+
public String name() {
57+
return "item component";
58+
}
59+
5560
}

src/main/java/org/skriptlang/skript/bukkit/itemcomponents/equippable/EquippableModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,9 @@ private void register(SyntaxRegistry registry, Consumer<SyntaxRegistry>... consu
101101
Arrays.stream(consumers).forEach(consumer -> consumer.accept(registry));
102102
}
103103

104+
@Override
105+
public String name() {
106+
return "equippable component";
107+
}
108+
104109
}

0 commit comments

Comments
 (0)