From 9c96c78f3ada4169eca524583e76c52fd37975bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Moreno?= Date: Sun, 16 Jan 2022 20:46:26 +0100 Subject: [PATCH] Fixed improper rendering on teleportation - Removed unnecessary PlayerChangedWorldEvent listener (PlayerTeleportEvent also gets called) - Fixed ImageRenderer#onPlayerTeleport() > Related to #24 --- .../bukkit/plugin/renderer/ImageRenderer.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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)