Potential packet fix

This commit is contained in:
Jitse Boonstra
2020-08-08 18:39:42 +02:00
parent 0a66b9dcef
commit 4eb7c8238d
4 changed files with 22 additions and 12 deletions
@@ -41,6 +41,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
protected UUID uuid = new UUID(new Random().nextLong(), 0);
protected String name = uuid.toString().replace("-", "").substring(0, 10);
protected GameProfile gameProfile = new GameProfile(uuid, name);
protected boolean created = false;
protected NPCLib instance;
protected List<String> text;
@@ -177,7 +178,7 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
@Override
public boolean isShown(Player player) {
if (player == null) return false;
Objects.requireNonNull(player, "Player object cannot be null");
return shown.contains(player.getUniqueId()) && !autoHidden.contains(player.getUniqueId());
}
@@ -190,9 +191,15 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
@Override
public NPC create() {
createPackets();
this.created = true;
return this;
}
@Override
public boolean isCreated() {
return created;
}
public void onLogout(Player player) {
getAutoHidden().remove(player.getUniqueId());
getShown().remove(player.getUniqueId()); // Don't need to use NPC#hide since the entity is not registered in the NMS server.