From 53657f57cae6d57ae9fd477620d8520bc8f0d554 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 8 Jan 2021 10:18:27 +1300 Subject: [PATCH] Fix an array bounds exception --- .../listeners/PlayerSkinHandler.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 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 be30a093..f8cbab54 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/listeners/PlayerSkinHandler.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/listeners/PlayerSkinHandler.java @@ -57,8 +57,8 @@ public class PlayerSkinHandler implements Listener { private boolean sleepPackets; public boolean canRemove(boolean onMoved) { - return firstPacketSent + (DisguiseConfig.getTablistRemoveDelay() * 50) + - (onMoved ? 0 : DisguiseConfig.getPlayerDisguisesSkinExpiresMove() * 50) < System.currentTimeMillis(); + return firstPacketSent + (DisguiseConfig.getTablistRemoveDelay() * 50) + (onMoved ? 0 : DisguiseConfig.getPlayerDisguisesSkinExpiresMove() * 50) < + System.currentTimeMillis(); } @Override @@ -75,21 +75,21 @@ public class PlayerSkinHandler implements Listener { } @Getter - private final Cache> cache = CacheBuilder.newBuilder().weakKeys() - .expireAfterWrite(DisguiseConfig.getPlayerDisguisesSkinExpiresMove() * 50, TimeUnit.MILLISECONDS) - .removalListener((event) -> { - if (event.getCause() != RemovalCause.EXPIRED) { - return; - } + private final Cache> cache = + CacheBuilder.newBuilder().weakKeys().expireAfterWrite(DisguiseConfig.getPlayerDisguisesSkinExpiresMove() * 50, TimeUnit.MILLISECONDS) + .removalListener((event) -> { + if (event.getCause() != RemovalCause.EXPIRED) { + return; + } - List skins = (List) event.getValue(); + List skins = (List) event.getValue(); - for (PlayerSkin skin : skins) { - doPacketRemoval((Player) event.getKey(), skin); - } + for (PlayerSkin skin : skins) { + doPacketRemoval((Player) event.getKey(), skin); + } - skins.clear(); - }).build(); + skins.clear(); + }).build(); public PlayerSkinHandler() { new BukkitRunnable() { @@ -130,8 +130,8 @@ public class PlayerSkinHandler implements Listener { packet.getModifier().write(2, loc.getY()); packet.getModifier().write(3, loc.getZ()); - for (PlayerSkin skin : value) { - if (!skin.isSleepPackets()) { + for (PlayerSkin skin : new ArrayList<>(value)) { + if (!value.contains(skin) || !skin.isSleepPackets()) { continue; } @@ -176,8 +176,7 @@ public class PlayerSkinHandler implements Listener { if (spawn) { packets.getDelayedPacketsMap().entrySet().removeIf(entry -> { - entry.getValue() - .removeIf(packet -> packet.getType() == Server.ENTITY_EQUIPMENT && isRemove(skin, packet)); + entry.getValue().removeIf(packet -> packet.getType() == Server.ENTITY_EQUIPMENT && isRemove(skin, packet)); return entry.getValue().isEmpty(); }); @@ -209,8 +208,7 @@ public class PlayerSkinHandler implements Listener { return true; } - @EventHandler(priority = EventPriority.MONITOR, - ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) private void onUndisguise(UndisguiseEvent event) { if (!event.getDisguise().isPlayerDisguise()) { return; @@ -246,12 +244,11 @@ public class PlayerSkinHandler implements Listener { private void addMetadata(Player player, PlayerSkin skin) throws InvocationTargetException { PlayerDisguise disguise = skin.getDisguise().get(); Entity entity = disguise.getEntity(); - WrappedDataWatcher watcher = DisguiseUtilities - .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(entity), disguise.getWatcher()); + WrappedDataWatcher watcher = DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(entity), disguise.getWatcher()); - PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() - .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entity.getEntityId(), watcher, true) - .createPacket(entity.getEntityId(), watcher, true); + PacketContainer metaPacket = + ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entity.getEntityId(), watcher, true) + .createPacket(entity.getEntityId(), watcher, true); ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket, false); @@ -339,8 +336,7 @@ public class PlayerSkinHandler implements Listener { } if (skin.isDoTabList()) { - PacketContainer packetContainer = - DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER); + PacketContainer packetContainer = DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer); }