diff --git a/src/main/java/io/josemmo/bukkit/plugin/renderer/ImageRenderer.java b/src/main/java/io/josemmo/bukkit/plugin/renderer/ImageRenderer.java index f43f617..8c6f694 100644 --- a/src/main/java/io/josemmo/bukkit/plugin/renderer/ImageRenderer.java +++ b/src/main/java/io/josemmo/bukkit/plugin/renderer/ImageRenderer.java @@ -425,16 +425,16 @@ public void onPlayerRespawn(@NotNull PlayerRespawnEvent event) { onPlayerLocationChange(event.getPlayer(), event.getPlayer().getLocation()); } - @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) - public void onPlayerChangedWorld(@NotNull PlayerChangedWorldEvent event) { - onPlayerLocationChange(event.getPlayer(), event.getPlayer().getLocation()); - } - @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) { if (event.getTo() == null) return; if (event.getFrom().getChunk().equals(event.getTo().getChunk())) return; - onPlayerLocationChange(event.getPlayer(), event.getTo()); + + // Wait until next server tick before handling location change + // This is necessary as teleport events get fired *before* teleporting the player + Bukkit.getScheduler().runTask(plugin, () -> { + onPlayerLocationChange(event.getPlayer(), event.getTo()); + }); } @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)