From 4f06b1833f280cee997588a7e76dc50c180e1ea6 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 23 Nov 2018 13:29:02 +1300 Subject: [PATCH] Resend self disguises if player teleports further than 64 blocks --- .../disguise/DisguiseListener.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseListener.java b/src/main/java/me/libraryaddict/disguise/DisguiseListener.java index 50a3930c..be4a8c28 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseListener.java @@ -601,6 +601,34 @@ public class DisguiseListener implements Listener { disguise.removeDisguise(); } } + + if (DisguiseAPI.isSelfDisguised(player)) { + Disguise disguise = DisguiseAPI.getDisguise(player, player); + + // If further than 64 blocks, resend the self disguise + if (disguise != null && disguise.isSelfDisguiseVisible() && from.distanceSquared(to) > 4096) { + // Send a packet to destroy the fake entity so that we can resend it without glitches + PacketContainer packet = DisguiseUtilities.getDestroyPacket(DisguiseAPI.getSelfDisguiseId()); + + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); + } + catch (Exception ex) { + ex.printStackTrace(); + } + + new BukkitRunnable() { + @Override + public void run() { + if (event.isCancelled() || !disguise.isDisguiseInUse()) { + return; + } + + DisguiseUtilities.sendSelfDisguise(player, (TargetedDisguise) disguise); + } + }.runTaskLater(LibsDisguises.getInstance(), 4); + } + } } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)