diff --git a/plugin/src/main/java/org/battleplugins/arena/Arena.java b/plugin/src/main/java/org/battleplugins/arena/Arena.java index 8b34a0ee..4bcd3d4f 100644 --- a/plugin/src/main/java/org/battleplugins/arena/Arena.java +++ b/plugin/src/main/java/org/battleplugins/arena/Arena.java @@ -102,7 +102,6 @@ public class Arena implements ArenaLike, ArenaListener { public Arena() { this.eventManager = new ArenaEventManager(this); - this.eventManager.registerEvents(this); } // API methods diff --git a/plugin/src/main/java/org/battleplugins/arena/ArenaLoader.java b/plugin/src/main/java/org/battleplugins/arena/ArenaLoader.java index 58acb886..f21814f4 100644 --- a/plugin/src/main/java/org/battleplugins/arena/ArenaLoader.java +++ b/plugin/src/main/java/org/battleplugins/arena/ArenaLoader.java @@ -23,11 +23,16 @@ public void load() { try { ArenaType arenaType = this.battleArena.arenaTypes.get(this.mode); if (arenaType == null) { - this.battleArena.info("Arena {} does not have a valid mode! Recognized modes: {}", this.arenaPath.getFileName(), this.battleArena.arenaTypes.keySet()); + this.battleArena.info("Arena {} specified the mode as {}, which is not valid! Recognized modes: {}", this.arenaPath.getFileName(), this.mode, this.battleArena.arenaTypes.keySet()); return; } Arena arena = ArenaConfigParser.newInstance(this.arenaPath, arenaType.arenaClass(), this.configuration, this.battleArena); + + // Need to call this here rather than in the Arena constructor + // so third party arenas can register their own event resolvers + arena.getEventManager().registerEvents(arena); + Bukkit.getPluginManager().registerEvents(arena, this.battleArena); this.battleArena.arenas.put(arena.getName(), arena); diff --git a/plugin/src/main/java/org/battleplugins/arena/event/ArenaEventManager.java b/plugin/src/main/java/org/battleplugins/arena/event/ArenaEventManager.java index 2c483d86..0d0f9de2 100644 --- a/plugin/src/main/java/org/battleplugins/arena/event/ArenaEventManager.java +++ b/plugin/src/main/java/org/battleplugins/arena/event/ArenaEventManager.java @@ -88,8 +88,9 @@ public ArenaEventManager(Arena arena) { * @param eventClass the event class * @param resolver the resolver for the event class */ - public void registerArenaResolver(Class eventClass, Function> resolver) { - this.arenaEventResolvers.put(eventClass, resolver); + @SuppressWarnings("unchecked") + public void registerArenaResolver(Class eventClass, Function> resolver) { + this.arenaEventResolvers.put(eventClass, (Function>) resolver); } /** @@ -203,12 +204,14 @@ public void registerEvents(ArenaListener listener) { ArenaEventHandler eventHandler = method.getAnnotation(ArenaEventHandler.class); if (method.getParameterCount() == 0) { + this.arena.getPlugin().warn("Event method {} in {} has no parameters. Not registering.", method.getName(), listener.getClass()); continue; } // The first argument should be an ArenaEvent or a Player event Class eventClass = method.getParameterTypes()[0]; if (!ArenaEvent.class.isAssignableFrom(eventClass) && PLAYER_EVENT_RESOLVERS.get(eventClass) == null && this.arenaEventResolvers.get(eventClass) == null) { + this.arena.getPlugin().warn("Event method {} ({}) in {} was not an ArenaEvent or a Player event. Custom resolvers can be added using the ArenaEventManager#registerArenaResolver.", method.getName(), eventClass.getSimpleName(), listener.getClass()); continue; } @@ -321,15 +324,17 @@ private Pair> extractContext(Event event) { } Function eventPlayerFunction = PLAYER_EVENT_RESOLVERS.get(event.getClass()); + + playerEventResolver: if (eventPlayerFunction != null) { Player player = eventPlayerFunction.apply(event); if (player == null) { - return null; + break playerEventResolver; } ArenaPlayer arenaPlayer = ArenaPlayer.getArenaPlayer(player); if (arenaPlayer == null) { - return null; + break playerEventResolver; } return Pair.of(arenaPlayer.getArena(), arenaPlayer.getCompetition()); diff --git a/plugin/src/main/java/org/battleplugins/arena/util/InteractionInputs.java b/plugin/src/main/java/org/battleplugins/arena/util/InteractionInputs.java index 548f90d0..36adf8d8 100644 --- a/plugin/src/main/java/org/battleplugins/arena/util/InteractionInputs.java +++ b/plugin/src/main/java/org/battleplugins/arena/util/InteractionInputs.java @@ -151,7 +151,7 @@ public void onInteract(PlayerInteractEvent event) { return; } - if (event.getInteractionPoint() == null) { + if (event.getClickedBlock() == null) { return; } @@ -163,7 +163,7 @@ public void onInteract(PlayerInteractEvent event) { // Need to run a tick later so Bukkit can handle the event cancellation Bukkit.getScheduler().runTaskLater(BattleArena.getInstance(), () -> { - onPositionInteract(event.getInteractionPoint()); + onPositionInteract(event.getClickedBlock().getLocation()); }, 1); event.setCancelled(true);