mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 15:29:20 -04:00
rename onlyIfNotCancelled to ignoreCancelled
This commit is contained in:
parent
a570230b80
commit
110e0343e2
@ -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));`
|
`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:
|
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`.
|
- `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`;
|
Your XYEventListener class needs to extend `de.bixilon.minosoft.modding.event.EventListener`;
|
||||||
```java
|
```java
|
||||||
@ -146,7 +146,7 @@ public class ChatEvent extends EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(onlyIfNotCancelled = false)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onChatMessageSending(ChatMessageSendingEvent event) {
|
public void onChatMessageSending(ChatMessageSendingEvent event) {
|
||||||
if (event.getMessage().contains("jeb_ is stupid")) {
|
if (event.getMessage().contains("jeb_ is stupid")) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -43,7 +43,7 @@ public class EventMethod {
|
|||||||
if (!method.getParameters()[0].getType().isAssignableFrom(event.getClass())) {
|
if (!method.getParameters()[0].getType().isAssignableFrom(event.getClass())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (annotation.onlyIfNotCancelled() && event instanceof CancelableEvent && ((CancelableEvent) event).isCancelled()) {
|
if (!annotation.ignoreCancelled() && event instanceof CancelableEvent && ((CancelableEvent) event).isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -20,7 +20,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface EventHandler {
|
public @interface EventHandler {
|
||||||
boolean onlyIfNotCancelled() default true;
|
boolean ignoreCancelled() default false;
|
||||||
|
|
||||||
Priorities priority() default Priorities.NORMAL;
|
Priorities priority() default Priorities.NORMAL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user