Skip to content

Commit

Permalink
Merge branch 'feature/consumer-registration-done' of https://github.c…
Browse files Browse the repository at this point in the history
…om/TheLimeGlass/skript-parser into feature/consumer-registration-done
  • Loading branch information
TheLimeGlass committed Oct 31, 2023
2 parents ed3c46d + f54af6d commit 25582d4
Showing 1 changed file with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand All @@ -60,20 +61,38 @@
* @see #getRegisterer()
*/
public class SkriptRegistration {
private final SkriptAddon registerer;
private final SkriptLogger logger = new SkriptLogger();

private final MultiMap<Class<?>, ExpressionInfo<?, ?>> expressions = new MultiMap<>();
private final List<SyntaxInfo<? extends Effect>> effects = new ArrayList<>();
private final List<SyntaxInfo<? extends CodeSection>> sections = new ArrayList<>();
private final List<SkriptEventInfo<?>> events = new ArrayList<>();
private final List<Type<?>> types = new ArrayList<>();
private final List<ConverterInfo<?, ?>> converters = new ArrayList<>();
private final List<SyntaxInfo<? extends Effect>> effects = new ArrayList<>();
private final List<Consumer<SkriptAddon>> finishConsumers = new ArrayList<>();
private final List<ContextValue<?, ?>> contextValues = new ArrayList<>();
private final List<ConverterInfo<?, ?>> converters = new ArrayList<>();
private final List<TagInfo<? extends Tag>> tags = new ArrayList<>();
private boolean newTypes = false;
private final List<SkriptEventInfo<?>> events = new ArrayList<>();
private final List<Type<?>> types = new ArrayList<>();
private final SkriptAddon registerer;
private final SkriptLogger logger;
private boolean newTypes;

/**
* Construct a SkriptRegistration around a SkriptAddon.
*
* @param registerer The SkriptAddon that this SkriptRegistration will be referencing.
*/
public SkriptRegistration(SkriptAddon registerer) {
this(registerer, new SkriptLogger());
}

/**
* Construct a SkriptRegistration around a SkriptAddon and the defined SkriptLogger to use.
*
* @param registerer The SkriptAddon that this SkriptRegistration will be referencing.
* @parm logger The SkriptLogger used in the registration process.
*/
public SkriptRegistration(SkriptAddon registerer, SkriptLogger logger) {
this.registerer = registerer;
this.logger = logger;
}

/**
Expand All @@ -96,6 +115,7 @@ public List<SyntaxInfo<? extends Effect>> getEffects() {
public List<SyntaxInfo<? extends CodeSection>> getSections() {
return sections;
}

/**
* @return all currently registered events
*/
Expand Down Expand Up @@ -554,6 +574,7 @@ public List<LogEntry> register(boolean ignoreLogs) {
TagManager.register(this);
Converters.registerConverters(this);
Converters.createMissingConverters();
finishConsumers.forEach(consumer -> consumer.accept(registerer));
if (ignoreLogs) {
logger.clearLogs();
return new ArrayList<>();
Expand Down Expand Up @@ -836,6 +857,15 @@ public void register() {
}
}

/**
* Add a consumer to be called when this SkriptRegistration finishes registration.
*
* @param consumer The consumer with the SkriptAddon reference.
*/
public void onFinishRegistration(Consumer<SkriptAddon> consumer) {
finishConsumers.add(consumer);
}

private void typeCheck() {
if (newTypes) {
TypeManager.register(this);
Expand Down

0 comments on commit 25582d4

Please sign in to comment.