Fix method signature of removeListener method

This commit is contained in:
Stone_Red
2022-05-07 03:54:58 +02:00
parent 00c96a42b8
commit 9670391019
4 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ public abstract class Entity extends javafx.scene.Group {
handler.addListener(eventName, function); handler.addListener(eventName, function);
} }
public final void removeListener(String eventName, Function<Object, Void> function) { public final <T> void removeListener(String eventName, Consumer<T> function) {
handler.removeListener(eventName, function); handler.removeListener(eventName, function);
} }
@@ -17,7 +17,7 @@ public class EventHandler {
events.get(eventName).add((e) -> function.accept((T) e)); events.get(eventName).add((e) -> function.accept((T) e));
} }
public void removeListener(String eventName, Function<Object, Void> function) throws IllegalArgumentException { public <T> void removeListener(String eventName, Consumer<T> function) throws IllegalArgumentException {
//NOTE: This needs to be called otherwise memory leak //NOTE: This needs to be called otherwise memory leak
if (!events.containsKey(eventName)) { if (!events.containsKey(eventName)) {
throw new IllegalArgumentException("Event " + eventName + " does not exist!"); throw new IllegalArgumentException("Event " + eventName + " does not exist!");
@@ -13,7 +13,7 @@ public class GlobalEventHandler {
handler.addListener(eventName, function); handler.addListener(eventName, function);
} }
public static void removeListener(String eventName, Function<Object, Void> function) { public static <T> void removeListener(String eventName, Consumer<T> function) {
handler.removeListener(eventName, function); handler.removeListener(eventName, function);
} }
+2 -1
View File
@@ -44,7 +44,8 @@ public class Chunk extends GridPane {
} }
public void removeEntity(Coordinate pos) { public void removeEntity(Coordinate pos) {
this.getChildren().remove(data[pos.x + pos.y * CHUNK_SIZE]); Entity entity = getEntity(pos);
this.getChildren().remove(entity);
data[pos.x + pos.y * CHUNK_SIZE] = null; data[pos.x + pos.y * CHUNK_SIZE] = null;
} }