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());
}
if (!autoHidden.contains(player.getUniqueId())) {
autoHidden.add(player.getUniqueId());
}
return;
}
@@ -154,12 +152,10 @@ public abstract class NPC implements PacketHandler, ActionHandler {
if (player.getLocation().distance(location) <= autoHideDistance) {
sendShowPackets(player);
} else {
if (!autoHidden.contains(player.getUniqueId())) {
autoHidden.add(player.getUniqueId());
}
}
}
}
private boolean canSeeNPC(Player player) {
Vector dir = location.toVector().subtract(player.getEyeLocation().toVector()).normalize();
@@ -189,10 +185,8 @@ public abstract class NPC implements PacketHandler, ActionHandler {
if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) <= autoHideDistance) {
sendHidePackets(player, scheduler);
} else {
if (autoHidden.contains(player.getUniqueId())) {
autoHidden.remove(player.getUniqueId());
}
}
}
}
}
@@ -25,16 +25,12 @@ public class PlayerListener implements Listener {
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
for (NPC npc : NPCManager.getAllNPCs()) {
if (npc.getAutoHidden().contains(player.getUniqueId())) {
npc.getAutoHidden().remove(player.getUniqueId());
}
// 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());
}
}
}
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {