Remove unnecessary contains before add and remove on HashSet

This commit is contained in:
MrMicky
2019-02-21 16:52:13 +01:00
parent 001e3ea754
commit 4b9c4a97c3
2 changed files with 5 additions and 15 deletions
@@ -132,9 +132,7 @@ public abstract class NPC implements PacketHandler, ActionHandler {
shown.add(player.getUniqueId()); shown.add(player.getUniqueId());
} }
if (!autoHidden.contains(player.getUniqueId())) { autoHidden.add(player.getUniqueId());
autoHidden.add(player.getUniqueId());
}
return; return;
} }
@@ -154,9 +152,7 @@ public abstract class NPC implements PacketHandler, ActionHandler {
if (player.getLocation().distance(location) <= autoHideDistance) { if (player.getLocation().distance(location) <= autoHideDistance) {
sendShowPackets(player); sendShowPackets(player);
} else { } else {
if (!autoHidden.contains(player.getUniqueId())) { autoHidden.add(player.getUniqueId());
autoHidden.add(player.getUniqueId());
}
} }
} }
} }
@@ -189,9 +185,7 @@ public abstract class NPC implements PacketHandler, ActionHandler {
if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) <= autoHideDistance) { if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) <= autoHideDistance) {
sendHidePackets(player, scheduler); sendHidePackets(player, scheduler);
} else { } else {
if (autoHidden.contains(player.getUniqueId())) { autoHidden.remove(player.getUniqueId());
autoHidden.remove(player.getUniqueId());
}
} }
} }
} }
@@ -25,14 +25,10 @@ public class PlayerListener implements Listener {
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
for (NPC npc : NPCManager.getAllNPCs()) { for (NPC npc : NPCManager.getAllNPCs()) {
if (npc.getAutoHidden().contains(player.getUniqueId())) { npc.getAutoHidden().remove(player.getUniqueId());
npc.getAutoHidden().remove(player.getUniqueId());
}
// Don't need to use NPC#hide since the entity is not registered in the NMS server. // Don't need to use NPC#hide since the entity is not registered in the NMS server.
if (npc.getShown().contains(player.getUniqueId())) { npc.getShown().remove(player.getUniqueId());
npc.getShown().remove(player.getUniqueId());
}
} }
} }