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

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib</artifactId> <artifactId>npclib</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-api</artifactId> <artifactId>npclib-api</artifactId>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib</artifactId> <artifactId>npclib</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-commons</artifactId> <artifactId>npclib-commons</artifactId>

View File

@ -57,7 +57,12 @@ public abstract class NPC {
return gameProfile; return gameProfile;
} }
public void destroy() { public void destroy() {
destroy(true);
}
public void destroy(boolean scheduler) {
NPCManager.remove(this); NPCManager.remove(this);
// Destroy NPC for every player that is still seeing it. // Destroy NPC for every player that is still seeing it.
@ -66,7 +71,7 @@ public abstract class NPC {
continue; 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); protected abstract void sendShowPackets(Player player);
public void hide(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); NPCDestroyEvent event = new NPCDestroyEvent(this, player, auto ? TriggerType.AUTOMATIC : TriggerType.MANUAL);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
@ -142,7 +147,7 @@ public abstract class NPC {
} }
if (auto) { if (auto) {
sendHidePackets(player); sendHidePackets(player, scheduler);
} else { } else {
if (!shown.contains(player.getUniqueId())) { if (!shown.contains(player.getUniqueId())) {
throw new RuntimeException("Cannot call hide method without calling NPC#show."); throw new RuntimeException("Cannot call hide method without calling NPC#show.");
@ -151,7 +156,7 @@ public abstract class NPC {
shown.remove(player.getUniqueId()); shown.remove(player.getUniqueId());
if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) <= autoHideDistance) { if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) <= autoHideDistance) {
sendHidePackets(player); sendHidePackets(player, scheduler);
} else { } else {
if (autoHidden.contains(player.getUniqueId())) { if (autoHidden.contains(player.getUniqueId())) {
autoHidden.remove(player.getUniqueId()); autoHidden.remove(player.getUniqueId());
@ -161,5 +166,5 @@ public abstract class NPC {
} }
// Internal method. // Internal method.
protected abstract void sendHidePackets(Player player); protected abstract void sendHidePackets(Player player, boolean scheduler);
} }

View File

@ -38,7 +38,7 @@ public class ChunkListener implements Listener {
continue; continue;
} }
npc.hide(Bukkit.getPlayer(uuid), true); npc.hide(Bukkit.getPlayer(uuid), true, true);
} }
} }
} }

View File

@ -47,7 +47,7 @@ public class PlayerListener implements Listener {
if (npc.getLocation().getWorld().equals(from)) { if (npc.getLocation().getWorld().equals(from)) {
if (!npc.getAutoHidden().contains(player.getUniqueId())) { if (!npc.getAutoHidden().contains(player.getUniqueId())) {
npc.getAutoHidden().add(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 { } else {
// Check if the player and NPC are out of range to sendHidePackets it. // Check if the player and NPC are out of range to sendHidePackets it.
if (!inRange) { if (!inRange) {
npc.hide(player, true); npc.hide(player, true, true);
npc.getAutoHidden().add(player.getUniqueId()); npc.getAutoHidden().add(player.getUniqueId());
} }
} }

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib</artifactId> <artifactId>npclib</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-nms</artifactId> <artifactId>npclib-nms</artifactId>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId> <artifactId>npclib-nms</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-nms-v1_10_R1</artifactId> <artifactId>npclib-nms-v1_10_R1</artifactId>

View File

@ -88,7 +88,7 @@ public class NPC_v1_10_R1 extends NPC {
} }
@Override @Override
public void sendHidePackets(Player player) { public void sendHidePackets(Player player, boolean scheduler) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityDestroy); playerConnection.sendPacket(packetPlayOutEntityDestroy);
@ -96,8 +96,12 @@ public class NPC_v1_10_R1 extends NPC {
hologram.destroy(player); hologram.destroy(player);
// Sending this a bit later so the player doesn't see the name (for that split second). if (scheduler) {
Bukkit.getScheduler().runTaskLater(plugin, () -> // Sending this a bit later so the player doesn't see the name (for that split second).
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); Bukkit.getScheduler().runTaskLater(plugin, () ->
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
} else {
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
}
} }
} }

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId> <artifactId>npclib-nms</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-nms-v1_11_R1</artifactId> <artifactId>npclib-nms-v1_11_R1</artifactId>

View File

@ -88,7 +88,7 @@ public class NPC_v1_11_R1 extends NPC {
} }
@Override @Override
public void sendHidePackets(Player player) { public void sendHidePackets(Player player, boolean scheduler) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityDestroy); playerConnection.sendPacket(packetPlayOutEntityDestroy);
@ -96,8 +96,12 @@ public class NPC_v1_11_R1 extends NPC {
hologram.destroy(player); hologram.destroy(player);
// Sending this a bit later so the player doesn't see the name (for that split second). if (scheduler) {
Bukkit.getScheduler().runTaskLater(plugin, () -> // Sending this a bit later so the player doesn't see the name (for that split second).
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); Bukkit.getScheduler().runTaskLater(plugin, () ->
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
} else {
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
}
} }
} }

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId> <artifactId>npclib-nms</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-nms-v1_12_R1</artifactId> <artifactId>npclib-nms-v1_12_R1</artifactId>

View File

@ -88,7 +88,7 @@ public class NPC_v1_12_R1 extends NPC {
} }
@Override @Override
public void sendHidePackets(Player player) { public void sendHidePackets(Player player, boolean scheduler) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityDestroy); playerConnection.sendPacket(packetPlayOutEntityDestroy);
@ -96,8 +96,12 @@ public class NPC_v1_12_R1 extends NPC {
hologram.destroy(player); hologram.destroy(player);
// Sending this a bit later so the player doesn't see the name (for that split second). if (scheduler) {
Bukkit.getScheduler().runTaskLater(plugin, () -> // Sending this a bit later so the player doesn't see the name (for that split second).
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); Bukkit.getScheduler().runTaskLater(plugin, () ->
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
} else {
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
}
} }
} }

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId> <artifactId>npclib-nms</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-nms-v1_8_R1</artifactId> <artifactId>npclib-nms-v1_8_R1</artifactId>

View File

@ -87,7 +87,7 @@ public class NPC_v1_8_R1 extends NPC {
} }
@Override @Override
public void sendHidePackets(Player player) { public void sendHidePackets(Player player, boolean scheduler) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityDestroy); playerConnection.sendPacket(packetPlayOutEntityDestroy);
@ -95,8 +95,12 @@ public class NPC_v1_8_R1 extends NPC {
hologram.destroy(player); hologram.destroy(player);
// Sending this a bit later so the player doesn't see the name (for that split second). if (scheduler) {
Bukkit.getScheduler().runTaskLater(plugin, () -> // Sending this a bit later so the player doesn't see the name (for that split second).
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); Bukkit.getScheduler().runTaskLater(plugin, () ->
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
} else {
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
}
} }
} }

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId> <artifactId>npclib-nms</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-nms-v1_8_R2</artifactId> <artifactId>npclib-nms-v1_8_R2</artifactId>

View File

@ -88,7 +88,7 @@ public class NPC_v1_8_R2 extends NPC {
} }
@Override @Override
public void sendHidePackets(Player player) { public void sendHidePackets(Player player, boolean scheduler) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityDestroy); playerConnection.sendPacket(packetPlayOutEntityDestroy);
@ -96,8 +96,12 @@ public class NPC_v1_8_R2 extends NPC {
hologram.destroy(player); hologram.destroy(player);
// Sending this a bit later so the player doesn't see the name (for that split second). if (scheduler) {
Bukkit.getScheduler().runTaskLater(plugin, () -> // Sending this a bit later so the player doesn't see the name (for that split second).
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); Bukkit.getScheduler().runTaskLater(plugin, () ->
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
} else {
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
}
} }
} }

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId> <artifactId>npclib-nms</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-nms-v1_8_R3</artifactId> <artifactId>npclib-nms-v1_8_R3</artifactId>

View File

@ -88,7 +88,7 @@ public class NPC_v1_8_R3 extends NPC {
} }
@Override @Override
public void sendHidePackets(Player player) { public void sendHidePackets(Player player, boolean scheduler) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityDestroy); playerConnection.sendPacket(packetPlayOutEntityDestroy);
@ -96,8 +96,12 @@ public class NPC_v1_8_R3 extends NPC {
hologram.destroy(player); hologram.destroy(player);
// Sending this a bit later so the player doesn't see the name (for that split second). if (scheduler) {
Bukkit.getScheduler().runTaskLater(plugin, () -> // Sending this a bit later so the player doesn't see the name (for that split second).
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); Bukkit.getScheduler().runTaskLater(plugin, () ->
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
} else {
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
}
} }
} }

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId> <artifactId>npclib-nms</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-nms-v1_9_R1</artifactId> <artifactId>npclib-nms-v1_9_R1</artifactId>

View File

@ -88,7 +88,7 @@ public class NPC_v1_9_R1 extends NPC {
} }
@Override @Override
public void sendHidePackets(Player player) { public void sendHidePackets(Player player, boolean scheduler) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityDestroy); playerConnection.sendPacket(packetPlayOutEntityDestroy);
@ -96,8 +96,12 @@ public class NPC_v1_9_R1 extends NPC {
hologram.destroy(player); hologram.destroy(player);
// Sending this a bit later so the player doesn't see the name (for that split second). if (scheduler) {
Bukkit.getScheduler().runTaskLater(plugin, () -> // Sending this a bit later so the player doesn't see the name (for that split second).
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); Bukkit.getScheduler().runTaskLater(plugin, () ->
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
} else {
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
}
} }
} }

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId> <artifactId>npclib-nms</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-nms-v1_9_R2</artifactId> <artifactId>npclib-nms-v1_9_R2</artifactId>

View File

@ -88,7 +88,7 @@ public class NPC_v1_9_R2 extends NPC {
} }
@Override @Override
public void sendHidePackets(Player player) { public void sendHidePackets(Player player, boolean scheduler) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityDestroy); playerConnection.sendPacket(packetPlayOutEntityDestroy);
@ -96,8 +96,12 @@ public class NPC_v1_9_R2 extends NPC {
hologram.destroy(player); hologram.destroy(player);
// Sending this a bit later so the player doesn't see the name (for that split second). if (scheduler) {
Bukkit.getScheduler().runTaskLater(plugin, () -> // Sending this a bit later so the player doesn't see the name (for that split second).
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5); Bukkit.getScheduler().runTaskLater(plugin, () ->
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
} else {
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister);
}
} }
} }

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib</artifactId> <artifactId>npclib</artifactId>
<version>1.1</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>npclib-plugin</artifactId> <artifactId>npclib-plugin</artifactId>

View File

@ -8,7 +8,7 @@
<groupId>net.jitse</groupId> <groupId>net.jitse</groupId>
<artifactId>npclib</artifactId> <artifactId>npclib</artifactId>
<version>1.1</version> <version>1.1.1</version>
<name>NPCLib</name> <name>NPCLib</name>
<url>https://github.com/JitseB/npclib</url> <url>https://github.com/JitseB/npclib</url>