mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-30 01:35:24 +00:00
Use a custom consumer instead of the built-in one
This commit is contained in:
parent
993255235e
commit
88bdaf155f
@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.server.event.Event;
|
||||
import emu.grasscutter.server.event.EventHandler;
|
||||
import emu.grasscutter.server.event.HandlerPriority;
|
||||
import emu.grasscutter.utils.EventConsumer;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
@ -14,7 +15,6 @@ import java.net.URLClassLoader;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Manages the server's plugins and the event system.
|
||||
@ -164,6 +164,6 @@ public final class PluginManager {
|
||||
private void invokeHandler(Event event, EventHandler handler) {
|
||||
if(!event.isCanceled() ||
|
||||
(event.isCanceled() && handler.ignoresCanceled())
|
||||
) handler.getCallback().accept(event);
|
||||
) handler.getCallback().consume(event);
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
package emu.grasscutter.server.event;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import emu.grasscutter.utils.EventConsumer;
|
||||
|
||||
public final class EventHandler {
|
||||
private final Class<? extends Event> event;
|
||||
@ -16,15 +15,11 @@ public final class EventHandler {
|
||||
return new EventHandler(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Will be replaced with a private constructor instead. Use {@link #forEvent(Class)} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.0.1")
|
||||
public EventHandler(Class<? extends Event> event) {
|
||||
private EventHandler(Class<? extends Event> event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
private Consumer<Event> listener;
|
||||
private EventConsumer listener;
|
||||
private HandlerPriority priority;
|
||||
private boolean handleCanceled;
|
||||
|
||||
@ -40,7 +35,7 @@ public final class EventHandler {
|
||||
* Returns the callback for the handler.
|
||||
* @return A consumer callback.
|
||||
*/
|
||||
public Consumer<Event> getCallback() {
|
||||
public EventConsumer getCallback() {
|
||||
return this.listener;
|
||||
}
|
||||
|
||||
@ -65,7 +60,7 @@ public final class EventHandler {
|
||||
* @param listener An event handler method.
|
||||
* @return Method chaining.
|
||||
*/
|
||||
public EventHandler listener(Consumer<Event> listener) {
|
||||
public EventHandler listener(EventConsumer listener) {
|
||||
this.listener = listener; return this;
|
||||
}
|
||||
|
||||
|
7
src/main/java/emu/grasscutter/utils/EventConsumer.java
Normal file
7
src/main/java/emu/grasscutter/utils/EventConsumer.java
Normal file
@ -0,0 +1,7 @@
|
||||
package emu.grasscutter.utils;
|
||||
|
||||
import emu.grasscutter.server.event.Event;
|
||||
|
||||
public interface EventConsumer {
|
||||
<T extends Event> void consume(T event);
|
||||
}
|
Loading…
Reference in New Issue
Block a user