diff --git a/src/main/java/de/cyklon/jevent/MethodHandler.java b/src/main/java/de/cyklon/jevent/MethodHandler.java index 2e1b3ac..9b70c6a 100644 --- a/src/main/java/de/cyklon/jevent/MethodHandler.java +++ b/src/main/java/de/cyklon/jevent/MethodHandler.java @@ -80,4 +80,14 @@ public static Collection> getHandlers(@NotNull D listener) return handlers; } + + @Override + public int hashCode() { + return handler.getMethod().hashCode(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof MethodHandler mh && mh.handler.equals(this.handler); + } } diff --git a/src/main/java/de/cyklon/jevent/RawHandler.java b/src/main/java/de/cyklon/jevent/RawHandler.java index 2db9d82..a622606 100644 --- a/src/main/java/de/cyklon/jevent/RawHandler.java +++ b/src/main/java/de/cyklon/jevent/RawHandler.java @@ -10,10 +10,12 @@ */ class RawHandler extends Handler { + private final long id; private final Consumer consumer; public RawHandler(Class eventType, Consumer consumer, byte priority, boolean ignoreCancelled) { super(eventType, priority, ignoreCancelled); + this.id = System.nanoTime(); this.consumer = consumer; } @@ -21,4 +23,14 @@ public RawHandler(Class eventType, Consumer consumer, byte priority, boole protected void invokeEvent(@NotNull EventManager manager, @NotNull T event) { consumer.accept(event); } + + @Override + public int hashCode() { + return Long.hashCode(id); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof RawHandler rh && rh.id==this.id; + } }