Fixed respawn issue (#69) and updated version to 2.5.1.-SNAPSHOT.
This commit is contained in:
parent
a9d2e090a6
commit
eb01c0ff46
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>npclib</artifactId>
|
<artifactId>npclib</artifactId>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-api</artifactId>
|
<artifactId>npclib-api</artifactId>
|
||||||
|
@ -31,6 +31,12 @@
|
||||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot</artifactId>
|
||||||
|
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mojang</groupId>
|
<groupId>com.mojang</groupId>
|
||||||
<artifactId>authlib</artifactId>
|
<artifactId>authlib</artifactId>
|
||||||
|
|
|
@ -14,7 +14,9 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jitse Boonstra
|
* @author Jitse Boonstra
|
||||||
|
@ -42,6 +44,40 @@ public class PlayerListener implements Listener {
|
||||||
npc.onLogout(player);
|
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
|
@EventHandler
|
||||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
@ -77,20 +113,20 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleMove(Player player) {
|
private void handleMove(Player player) {
|
||||||
World world = player.getWorld();
|
Location location = player.getLocation();
|
||||||
for (NPCBase npc : NPCManager.getAllNPCs()) {
|
for (NPCBase npc : NPCManager.getAllNPCs()) {
|
||||||
if (!npc.getShown().contains(player.getUniqueId())) {
|
if (!npc.getShown().contains(player.getUniqueId())) {
|
||||||
continue; // NPC was never supposed to be shown to the player.
|
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.
|
continue; // NPC is not in the same world.
|
||||||
}
|
}
|
||||||
|
|
||||||
// If Bukkit doesn't track the NPC entity anymore, bypass the hiding distance variable.
|
// If Bukkit doesn't track the NPC entity anymore, bypass the hiding distance variable.
|
||||||
// This will cause issues otherwise (e.g. custom skin disappearing).
|
// This will cause issues otherwise (e.g. custom skin disappearing).
|
||||||
double hideDistance = instance.getAutoHideDistance();
|
double hideDistance = instance.getAutoHideDistance();
|
||||||
double distanceSquared = player.getLocation().distanceSquared(npc.getLocation());
|
double distanceSquared = location.distanceSquared(npc.getLocation());
|
||||||
|
|
||||||
int tempRange = Bukkit.getViewDistance() << 4;
|
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.
|
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.
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib</artifactId>
|
<artifactId>npclib</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_10_R1</artifactId>
|
<artifactId>npclib-nms-v1_10_R1</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_11_R1</artifactId>
|
<artifactId>npclib-nms-v1_11_R1</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_12_R1</artifactId>
|
<artifactId>npclib-nms-v1_12_R1</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_13_R1</artifactId>
|
<artifactId>npclib-nms-v1_13_R1</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_13_R2</artifactId>
|
<artifactId>npclib-nms-v1_13_R2</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_14_R1</artifactId>
|
<artifactId>npclib-nms-v1_14_R1</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_15_R1</artifactId>
|
<artifactId>npclib-nms-v1_15_R1</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_8_R2</artifactId>
|
<artifactId>npclib-nms-v1_8_R2</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_8_R3</artifactId>
|
<artifactId>npclib-nms-v1_8_R3</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_9_R1</artifactId>
|
<artifactId>npclib-nms-v1_9_R1</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib-nms</artifactId>
|
<artifactId>npclib-nms</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-nms-v1_9_R2</artifactId>
|
<artifactId>npclib-nms-v1_9_R2</artifactId>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib</artifactId>
|
<artifactId>npclib</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>npclib-plugin</artifactId>
|
<artifactId>npclib-plugin</artifactId>
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
<groupId>net.jitse</groupId>
|
<groupId>net.jitse</groupId>
|
||||||
<artifactId>npclib</artifactId>
|
<artifactId>npclib</artifactId>
|
||||||
<version>2.5-SNAPSHOT</version>
|
<version>2.5.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
Loading…
Reference in New Issue