From 6de077882c65c53532b04911c95429899de43edd Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 15 Sep 2020 21:58:33 +1200 Subject: [PATCH] Add null check, always try process packets after 30 seconds --- .../listeners/PlayerSkinHandler.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/listeners/PlayerSkinHandler.java b/src/main/java/me/libraryaddict/disguise/utilities/listeners/PlayerSkinHandler.java index f9b66a7d..062767ab 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/listeners/PlayerSkinHandler.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/listeners/PlayerSkinHandler.java @@ -53,7 +53,7 @@ public class PlayerSkinHandler implements Listener { @Getter private final Cache> cache = - CacheBuilder.newBuilder().weakKeys().expireAfterWrite(1, TimeUnit.MINUTES).removalListener((event) -> { + CacheBuilder.newBuilder().weakKeys().expireAfterWrite(30, TimeUnit.SECONDS).removalListener((event) -> { if (event.getCause() != RemovalCause.EXPIRED) { return; } @@ -74,6 +74,8 @@ public class PlayerSkinHandler implements Listener { }).build(); public void addPlayerSkin(Player player, PlayerDisguise disguise) { + tryProcess(player); + List skins = getCache().getIfPresent(player); if (skins == null) { @@ -117,6 +119,10 @@ public class PlayerSkinHandler implements Listener { } private void doPacketRemoval(Player player, PlayerDisguise disguise) { + if (disguise == null) { + return; + } + PacketContainer packetContainer = DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER); @@ -127,9 +133,8 @@ public class PlayerSkinHandler implements Listener { } } - @EventHandler - public void onMove(PlayerMoveEvent event) { - List skins = getCache().getIfPresent(event.getPlayer()); + private void tryProcess(Player player) { + List skins = getCache().getIfPresent(player); if (skins == null) { return; @@ -148,6 +153,12 @@ public class PlayerSkinHandler implements Listener { return; } - getCache().invalidate(event.getPlayer()); + getCache().invalidate(player); + + } + + @EventHandler + public void onMove(PlayerMoveEvent event) { + tryProcess(event.getPlayer()); } }