Fix an array bounds exception

This commit is contained in:
libraryaddict 2021-01-08 10:18:27 +13:00
parent d29bdb70fe
commit 53657f57ca

View File

@ -57,8 +57,8 @@ public class PlayerSkinHandler implements Listener {
private boolean sleepPackets; private boolean sleepPackets;
public boolean canRemove(boolean onMoved) { public boolean canRemove(boolean onMoved) {
return firstPacketSent + (DisguiseConfig.getTablistRemoveDelay() * 50) + return firstPacketSent + (DisguiseConfig.getTablistRemoveDelay() * 50) + (onMoved ? 0 : DisguiseConfig.getPlayerDisguisesSkinExpiresMove() * 50) <
(onMoved ? 0 : DisguiseConfig.getPlayerDisguisesSkinExpiresMove() * 50) < System.currentTimeMillis(); System.currentTimeMillis();
} }
@Override @Override
@ -75,21 +75,21 @@ public class PlayerSkinHandler implements Listener {
} }
@Getter @Getter
private final Cache<Player, List<PlayerSkin>> cache = CacheBuilder.newBuilder().weakKeys() private final Cache<Player, List<PlayerSkin>> cache =
.expireAfterWrite(DisguiseConfig.getPlayerDisguisesSkinExpiresMove() * 50, TimeUnit.MILLISECONDS) CacheBuilder.newBuilder().weakKeys().expireAfterWrite(DisguiseConfig.getPlayerDisguisesSkinExpiresMove() * 50, TimeUnit.MILLISECONDS)
.removalListener((event) -> { .removalListener((event) -> {
if (event.getCause() != RemovalCause.EXPIRED) { if (event.getCause() != RemovalCause.EXPIRED) {
return; return;
} }
List<PlayerSkin> skins = (List<PlayerSkin>) event.getValue(); List<PlayerSkin> skins = (List<PlayerSkin>) event.getValue();
for (PlayerSkin skin : skins) { for (PlayerSkin skin : skins) {
doPacketRemoval((Player) event.getKey(), skin); doPacketRemoval((Player) event.getKey(), skin);
} }
skins.clear(); skins.clear();
}).build(); }).build();
public PlayerSkinHandler() { public PlayerSkinHandler() {
new BukkitRunnable() { new BukkitRunnable() {
@ -130,8 +130,8 @@ public class PlayerSkinHandler implements Listener {
packet.getModifier().write(2, loc.getY()); packet.getModifier().write(2, loc.getY());
packet.getModifier().write(3, loc.getZ()); packet.getModifier().write(3, loc.getZ());
for (PlayerSkin skin : value) { for (PlayerSkin skin : new ArrayList<>(value)) {
if (!skin.isSleepPackets()) { if (!value.contains(skin) || !skin.isSleepPackets()) {
continue; continue;
} }
@ -176,8 +176,7 @@ public class PlayerSkinHandler implements Listener {
if (spawn) { if (spawn) {
packets.getDelayedPacketsMap().entrySet().removeIf(entry -> { packets.getDelayedPacketsMap().entrySet().removeIf(entry -> {
entry.getValue() entry.getValue().removeIf(packet -> packet.getType() == Server.ENTITY_EQUIPMENT && isRemove(skin, packet));
.removeIf(packet -> packet.getType() == Server.ENTITY_EQUIPMENT && isRemove(skin, packet));
return entry.getValue().isEmpty(); return entry.getValue().isEmpty();
}); });
@ -209,8 +208,7 @@ public class PlayerSkinHandler implements Listener {
return true; return true;
} }
@EventHandler(priority = EventPriority.MONITOR, @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
ignoreCancelled = true)
private void onUndisguise(UndisguiseEvent event) { private void onUndisguise(UndisguiseEvent event) {
if (!event.getDisguise().isPlayerDisguise()) { if (!event.getDisguise().isPlayerDisguise()) {
return; return;
@ -246,12 +244,11 @@ public class PlayerSkinHandler implements Listener {
private void addMetadata(Player player, PlayerSkin skin) throws InvocationTargetException { private void addMetadata(Player player, PlayerSkin skin) throws InvocationTargetException {
PlayerDisguise disguise = skin.getDisguise().get(); PlayerDisguise disguise = skin.getDisguise().get();
Entity entity = disguise.getEntity(); Entity entity = disguise.getEntity();
WrappedDataWatcher watcher = DisguiseUtilities WrappedDataWatcher watcher = DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(entity), disguise.getWatcher());
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(entity), disguise.getWatcher());
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() PacketContainer metaPacket =
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entity.getEntityId(), watcher, true) ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entity.getEntityId(), watcher, true)
.createPacket(entity.getEntityId(), watcher, true); .createPacket(entity.getEntityId(), watcher, true);
ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket, false); ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket, false);
@ -339,8 +336,7 @@ public class PlayerSkinHandler implements Listener {
} }
if (skin.isDoTabList()) { if (skin.isDoTabList()) {
PacketContainer packetContainer = PacketContainer packetContainer = DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer);
} }