Skip to content

Commit

Permalink
Delay listening behavior logic until after the event implementation i…
Browse files Browse the repository at this point in the history
…nitializes (#6948)
  • Loading branch information
APickledWalrus authored Aug 1, 2024
1 parent ad1a492 commit 2f94384
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/main/java/ch/njol/skript/events/EvtMove.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,14 @@ public boolean check(Event event) {
}

@Override
@Nullable
@SuppressWarnings("unchecked")
public Class<? extends Event> [] getEventClasses() {
if (isPlayer) {
return new Class[] {PlayerMoveEvent.class};
} else if (HAS_ENTITY_MOVE) {
return new Class[] {EntityMoveEvent.class};
}
return null;
throw new IllegalStateException("This event has not yet initialized!");
}

@Override
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/ch/njol/skript/lang/SkriptEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,32 @@ public final boolean init(Literal<?>[] args, int matchedPattern, ParseResult par
throw new IllegalStateException();
skriptEventInfo = (SkriptEventInfo<?>) syntaxElementInfo;

assert entryContainer != null; // cannot be null for non-simple structures
this.source = entryContainer.getSource();

// use default value for now
listeningBehavior = eventData.getListenerBehavior();

// initialize implementation
if (!init(args, matchedPattern, parseResult))
return false;

// evaluate whether this event supports listening to cancelled events
supportsListeningBehavior = false;
for (Class<? extends Event> eventClass : getEventClasses()) {
if (Cancellable.class.isAssignableFrom(eventClass)) {
supportsListeningBehavior = true;
break;
}
}

listeningBehavior = eventData.getListenerBehavior();
// if the behavior is non-null, it was set by the user
if (listeningBehavior != null && !isListeningBehaviorSupported()) {
String eventName = skriptEventInfo.name.toLowerCase(Locale.ENGLISH);
Skript.error(Utils.A(eventName) + " event does not support listening for cancelled or uncancelled events.");
return false;
}

assert entryContainer != null; // cannot be null for non-simple structures
this.source = entryContainer.getSource();

return init(args, matchedPattern, parseResult);
return true;
}

/**
Expand Down

0 comments on commit 2f94384

Please sign in to comment.