-
-
Notifications
You must be signed in to change notification settings - Fork 382
/
Copy pathEffectSection.java
67 lines (57 loc) · 2.35 KB
/
EffectSection.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ch.njol.skript.lang;
import ch.njol.skript.Skript;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.parser.ParserInstance;
import ch.njol.util.Kleenean;
import org.jetbrains.annotations.Nullable;
import java.util.Iterator;
import java.util.List;
/**
* A {@link Section} that may also be used as an effect,
* meaning there may be no section to parse.
* <br><br>
* When loading code, all EffectSections should first verify whether a section actually
* exists through the usage of {@link #hasSection}. If this method returns true, it is
* safe to assert that the section node and list of trigger items are not null.
* <br><br>
* @see Section
* @see Skript#registerSection(Class, String...)
*/
public abstract class EffectSection extends Section {
private boolean hasSection;
public boolean hasSection() {
return hasSection;
}
/**
* This method should not be overridden unless you know what you are doing!
*/
@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
SectionContext sectionContext = getParser().getData(SectionContext.class);
//noinspection ConstantConditions - For an EffectSection, it may be null
hasSection = sectionContext.sectionNode != null;
return super.init(expressions, matchedPattern, isDelayed, parseResult);
}
@Override
public abstract boolean init(Expression<?>[] expressions,
int matchedPattern,
Kleenean isDelayed,
ParseResult parseResult,
@Nullable SectionNode sectionNode,
@Nullable List<TriggerItem> triggerItems);
/**
* Similar to {@link Section#parse(String, String, SectionNode, List)}, but will only attempt to parse from other {@link EffectSection}s.
*/
public static @Nullable EffectSection parse(String input, @Nullable String defaultError, @Nullable SectionNode sectionNode, @Nullable List<TriggerItem> triggerItems) {
SectionContext sectionContext = ParserInstance.get().getData(SectionContext.class);
//noinspection unchecked,rawtypes
return sectionContext.modify(sectionNode, triggerItems, () ->
(EffectSection) SkriptParser.parse(
input,
(Iterator) Skript.getSections().stream()
.filter(info -> EffectSection.class.isAssignableFrom(info.getElementClass()))
.iterator(),
defaultError));
}
}