For v1.1.1, fixes reload bug.

This commit is contained in:
JitseB
2018-05-06 23:34:55 +02:00
parent 63f60c4208
commit 11936e630c
24 changed files with 91 additions and 54 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib</artifactId>
<version>1.1</version>
<version>1.1.1</version>
</parent>
<artifactId>npclib-commons</artifactId>
@@ -57,7 +57,12 @@ public abstract class NPC {
return gameProfile;
}
public void destroy() {
destroy(true);
}
public void destroy(boolean scheduler) {
NPCManager.remove(this);
// Destroy NPC for every player that is still seeing it.
@@ -66,7 +71,7 @@ public abstract class NPC {
continue;
}
hide(Bukkit.getPlayer(uuid), true);
hide(Bukkit.getPlayer(uuid), true, scheduler);
}
}
@@ -131,10 +136,10 @@ public abstract class NPC {
protected abstract void sendShowPackets(Player player);
public void hide(Player player) {
hide(player, false);
hide(player, false, true);
}
public void hide(Player player, boolean auto) {
public void hide(Player player, boolean auto, boolean scheduler) {
NPCDestroyEvent event = new NPCDestroyEvent(this, player, auto ? TriggerType.AUTOMATIC : TriggerType.MANUAL);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
@@ -142,7 +147,7 @@ public abstract class NPC {
}
if (auto) {
sendHidePackets(player);
sendHidePackets(player, scheduler);
} else {
if (!shown.contains(player.getUniqueId())) {
throw new RuntimeException("Cannot call hide method without calling NPC#show.");
@@ -151,7 +156,7 @@ public abstract class NPC {
shown.remove(player.getUniqueId());
if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) <= autoHideDistance) {
sendHidePackets(player);
sendHidePackets(player, scheduler);
} else {
if (autoHidden.contains(player.getUniqueId())) {
autoHidden.remove(player.getUniqueId());
@@ -161,5 +166,5 @@ public abstract class NPC {
}
// Internal method.
protected abstract void sendHidePackets(Player player);
protected abstract void sendHidePackets(Player player, boolean scheduler);
}
@@ -38,7 +38,7 @@ public class ChunkListener implements Listener {
continue;
}
npc.hide(Bukkit.getPlayer(uuid), true);
npc.hide(Bukkit.getPlayer(uuid), true, true);
}
}
}
@@ -47,7 +47,7 @@ public class PlayerListener implements Listener {
if (npc.getLocation().getWorld().equals(from)) {
if (!npc.getAutoHidden().contains(player.getUniqueId())) {
npc.getAutoHidden().add(player.getUniqueId());
npc.hide(player, true);
npc.hide(player, true, false);
}
}
}
@@ -95,7 +95,7 @@ public class PlayerListener implements Listener {
} else {
// Check if the player and NPC are out of range to sendHidePackets it.
if (!inRange) {
npc.hide(player, true);
npc.hide(player, true, true);
npc.getAutoHidden().add(player.getUniqueId());
}
}