Remove unnecessary contains before add and remove on HashSet
This commit is contained in:
@@ -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,12 +152,10 @@ 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canSeeNPC(Player player) {
|
private boolean canSeeNPC(Player player) {
|
||||||
Vector dir = location.toVector().subtract(player.getEyeLocation().toVector()).normalize();
|
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) {
|
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,16 +25,12 @@ 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user