rename onlyIfNotCancelled to ignoreCancelled

This commit is contained in:
Bixilon 2020-10-10 16:29:46 +02:00
parent a570230b80
commit 110e0343e2
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 4 additions and 4 deletions

View File

@ -127,7 +127,7 @@ If you want to register an event depending on an IP (like server specific suppor
`getEventManager().registerConnectionListener(new XYEventListener(), new ServerAddress("127.0.0.1", 25565));`
Your event methods need to be annotated by `EventHandler`. `EventHandler` **can** take these arguments:
- `priority`: Pretty much self explaining. `HIGH` means, that it gets executed at "the beginning", `LOW` means the opposite. Defaults to `NORMAL`.
- `onlyIfNotCancelled`: If it is a cancellable event, your method only gets executed, when all prior listeners (potentially with a higher priority) did not cancel the event. Defaults to `true`.
- `ignoreCancelled`: If it is a cancellable event, your method only gets executed, when all prior listeners (potentially with a higher priority) did not cancel the event. Defaults to `false`.
Your XYEventListener class needs to extend `de.bixilon.minosoft.modding.event.EventListener`;
```java
@ -146,7 +146,7 @@ public class ChatEvent extends EventListener {
}
}
@EventHandler(onlyIfNotCancelled = false)
@EventHandler(ignoreCancelled = true)
public void onChatMessageSending(ChatMessageSendingEvent event) {
if (event.getMessage().contains("jeb_ is stupid")) {
event.setCancelled(true);

View File

@ -43,7 +43,7 @@ public class EventMethod {
if (!method.getParameters()[0].getType().isAssignableFrom(event.getClass())) {
return;
}
if (annotation.onlyIfNotCancelled() && event instanceof CancelableEvent && ((CancelableEvent) event).isCancelled()) {
if (!annotation.ignoreCancelled() && event instanceof CancelableEvent && ((CancelableEvent) event).isCancelled()) {
return;
}
try {

View File

@ -20,7 +20,7 @@ import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface EventHandler {
boolean onlyIfNotCancelled() default true;
boolean ignoreCancelled() default false;
Priorities priority() default Priorities.NORMAL;
}