Skip to content

Commit

Permalink
Allow SkriptEvent to specify Event classes for ParserInstance (Skript…
Browse files Browse the repository at this point in the history
  • Loading branch information
TPGamesNL authored Jan 18, 2022
1 parent 581c8a8 commit bc8458f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/ch/njol/skript/ScriptLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,12 @@ private static ScriptInfo loadScript(@Nullable Config config) {

if (Skript.debug() || node.debug())
Skript.debug(event + " (" + parsedEvent.getSecond().toString(null, true) + "):");


Class<? extends Event>[] eventClasses = parsedEvent.getSecond().getEventClasses();
if (eventClasses == null)
eventClasses = parsedEvent.getFirst().events;
try {
getParser().setCurrentEvent("" + parsedEvent.getFirst().getName().toLowerCase(Locale.ENGLISH), parsedEvent.getFirst().events);
getParser().setCurrentEvent(parsedEvent.getFirst().getName().toLowerCase(Locale.ENGLISH), eventClasses);
getParser().setCurrentSkriptEvent(parsedEvent.getSecond());
events.add(new ParsedEventData(parsedEvent, event, node, loadItems(node)));
} finally {
Expand Down Expand Up @@ -788,7 +791,10 @@ private static ScriptInfo loadScript(@Nullable Config config) {
}

for (ParsedEventData event : events) {
getParser().setCurrentEvent("" + event.info.getFirst().getName().toLowerCase(Locale.ENGLISH), event.info.getFirst().events);
Class<? extends Event>[] eventClasses = event.info.getSecond().getEventClasses();
if (eventClasses == null)
eventClasses = event.info.getFirst().events;
getParser().setCurrentEvent(event.info.getFirst().getName().toLowerCase(Locale.ENGLISH), eventClasses);
getParser().setCurrentSkriptEvent(event.info.getSecond());

Trigger trigger;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ch/njol/skript/lang/SkriptEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public boolean shouldLoadEvent() {
return true;
}

/**
* @return the Event classes to use in {@link ch.njol.skript.lang.parser.ParserInstance},
* or {@code null} if the Event classes this SkriptEvent was registered with should be used.
*/
public Class<? extends Event> @Nullable[] getEventClasses() {
return null;
}

@Override
public String toString() {
return toString(null, false);
Expand Down

0 comments on commit bc8458f

Please sign in to comment.