diff --git a/api/pom.xml b/api/pom.xml
index 6f746de..74058b3 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -8,7 +8,7 @@
npclib
net.jitse
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-api
@@ -31,6 +31,12 @@
1.15.2-R0.1-SNAPSHOT
provided
+
+ org.spigotmc
+ spigot
+ 1.15.2-R0.1-SNAPSHOT
+ provided
+
com.mojang
authlib
diff --git a/api/src/main/java/net/jitse/npclib/listeners/PlayerListener.java b/api/src/main/java/net/jitse/npclib/listeners/PlayerListener.java
index 7f31746..01b6e9d 100755
--- a/api/src/main/java/net/jitse/npclib/listeners/PlayerListener.java
+++ b/api/src/main/java/net/jitse/npclib/listeners/PlayerListener.java
@@ -14,7 +14,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
+import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.*;
+import org.bukkit.scheduler.BukkitRunnable;
/**
* @author Jitse Boonstra
@@ -42,6 +44,40 @@ public class PlayerListener implements Listener {
npc.onLogout(player);
}
+ @EventHandler
+ public void onPlayerDeath(PlayerDeathEvent event) {
+ // Need to auto hide the NPCs from the player, or else the system will think they can see the NPC on respawn.
+ Player player = event.getEntity();
+ for (NPCBase npc : NPCManager.getAllNPCs()) {
+ if (npc.getWorld().equals(player.getWorld())) {
+ if (!npc.getAutoHidden().contains(player.getUniqueId())) {
+ npc.getAutoHidden().add(player.getUniqueId());
+ npc.hide(player, true);
+ }
+ }
+ }
+ }
+
+ @EventHandler
+ public void onPlayerRespawn(PlayerRespawnEvent event) {
+ // If the player dies in the server spawn world, the world change event isn't called (nor is the PlayerTeleportEvent).
+ Player player = event.getPlayer();
+ Location respawn = event.getRespawnLocation();
+ if (respawn.getWorld() != null && respawn.getWorld().equals(player.getWorld())) {
+ // Waiting until the player is moved to the new location or else it'll mess things up.
+ // I.e. if the player is at great distance from the NPC spawning, they won't be able to see it.
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (player.isOnline() && player.getLocation().equals(respawn)) {
+ handleMove(player);
+ this.cancel();
+ }
+ }
+ }.runTaskTimerAsynchronously(instance.getPlugin(), 0, 1);
+ }
+ }
+
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
@@ -77,20 +113,20 @@ public class PlayerListener implements Listener {
}
private void handleMove(Player player) {
- World world = player.getWorld();
+ Location location = player.getLocation();
for (NPCBase npc : NPCManager.getAllNPCs()) {
if (!npc.getShown().contains(player.getUniqueId())) {
continue; // NPC was never supposed to be shown to the player.
}
- if (!npc.getWorld().equals(world)) {
+ if (!npc.getWorld().equals(location.getWorld())) {
continue; // NPC is not in the same world.
}
// If Bukkit doesn't track the NPC entity anymore, bypass the hiding distance variable.
// This will cause issues otherwise (e.g. custom skin disappearing).
double hideDistance = instance.getAutoHideDistance();
- double distanceSquared = player.getLocation().distanceSquared(npc.getLocation());
+ double distanceSquared = location.distanceSquared(npc.getLocation());
int tempRange = Bukkit.getViewDistance() << 4;
boolean inRange = distanceSquared <= (hideDistance * hideDistance) && distanceSquared <= (tempRange * tempRange); // Avoids Math.pow due to how intensive it is. Could make a static utility function for it.
diff --git a/nms/pom.xml b/nms/pom.xml
index 159bd4c..eb126b5 100644
--- a/nms/pom.xml
+++ b/nms/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms
diff --git a/nms/v1_10_R1/pom.xml b/nms/v1_10_R1/pom.xml
index 9f81f64..ead273f 100755
--- a/nms/v1_10_R1/pom.xml
+++ b/nms/v1_10_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_10_R1
diff --git a/nms/v1_11_R1/pom.xml b/nms/v1_11_R1/pom.xml
index cbdf03b..cfc7a1c 100755
--- a/nms/v1_11_R1/pom.xml
+++ b/nms/v1_11_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_11_R1
diff --git a/nms/v1_12_R1/pom.xml b/nms/v1_12_R1/pom.xml
index d0e6915..a34f4b5 100755
--- a/nms/v1_12_R1/pom.xml
+++ b/nms/v1_12_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_12_R1
diff --git a/nms/v1_13_R1/pom.xml b/nms/v1_13_R1/pom.xml
index 9a7f215..6a91cb4 100755
--- a/nms/v1_13_R1/pom.xml
+++ b/nms/v1_13_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_13_R1
diff --git a/nms/v1_13_R2/pom.xml b/nms/v1_13_R2/pom.xml
index e1f863f..f8c2d99 100755
--- a/nms/v1_13_R2/pom.xml
+++ b/nms/v1_13_R2/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_13_R2
diff --git a/nms/v1_14_R1/pom.xml b/nms/v1_14_R1/pom.xml
index 6f4188d..2770805 100755
--- a/nms/v1_14_R1/pom.xml
+++ b/nms/v1_14_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_14_R1
diff --git a/nms/v1_15_R1/pom.xml b/nms/v1_15_R1/pom.xml
index d0a1b99..65c78ce 100644
--- a/nms/v1_15_R1/pom.xml
+++ b/nms/v1_15_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_15_R1
diff --git a/nms/v1_8_R2/pom.xml b/nms/v1_8_R2/pom.xml
index 2b04bbd..03a3bcf 100755
--- a/nms/v1_8_R2/pom.xml
+++ b/nms/v1_8_R2/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_8_R2
diff --git a/nms/v1_8_R3/pom.xml b/nms/v1_8_R3/pom.xml
index 8ea9690..968647a 100755
--- a/nms/v1_8_R3/pom.xml
+++ b/nms/v1_8_R3/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_8_R3
diff --git a/nms/v1_9_R1/pom.xml b/nms/v1_9_R1/pom.xml
index b452b25..8a93603 100755
--- a/nms/v1_9_R1/pom.xml
+++ b/nms/v1_9_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_9_R1
diff --git a/nms/v1_9_R2/pom.xml b/nms/v1_9_R2/pom.xml
index 6e7bdcb..e2ad991 100755
--- a/nms/v1_9_R2/pom.xml
+++ b/nms/v1_9_R2/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-nms-v1_9_R2
diff --git a/plugin/pom.xml b/plugin/pom.xml
index 5947c44..6c99a69 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
npclib-plugin
diff --git a/pom.xml b/pom.xml
index e62072a..90a6556 100755
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
net.jitse
npclib
- 2.5-SNAPSHOT
+ 2.5.1-SNAPSHOT
UTF-8