fix npc paths
This commit is contained in:
parent
b95c5ab3f3
commit
baa47c16df
5 changed files with 57 additions and 45 deletions
|
@ -312,8 +312,7 @@ public class NPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return this.npcPath != null ?
|
if (this.npcPath != null && this.npcPath.getLocation() != null) return this.npcPath.getLocation().bukkitLocation();
|
||||||
this.npcPath.getLocation().bukkitLocation() :
|
return this.npcPojo.getLocation().bukkitLocation();
|
||||||
this.npcPojo.getLocation().bukkitLocation();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
package io.github.znetworkw.znpcservers.npc.task;
|
|
||||||
|
|
||||||
import io.github.znetworkw.znpcservers.configuration.ConfigurationConstants;
|
|
||||||
import io.github.znetworkw.znpcservers.npc.FunctionFactory;
|
|
||||||
import io.github.znetworkw.znpcservers.npc.NPC;
|
|
||||||
import io.github.znetworkw.znpcservers.npc.conversation.ConversationModel;
|
|
||||||
import io.github.znetworkw.znpcservers.user.ZUser;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
public class NPCManagerTask extends BukkitRunnable {
|
|
||||||
public NPCManagerTask(Plugin serversNPC) {
|
|
||||||
runTaskTimerAsynchronously(serversNPC, 60L, 10L);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
int distSq = ConfigurationConstants.VIEW_DISTANCE * ConfigurationConstants.VIEW_DISTANCE;
|
|
||||||
for (NPC npc : NPC.all()) {
|
|
||||||
boolean hasPath = (npc.getNpcPath() != null);
|
|
||||||
if (hasPath) npc.getNpcPath().handle();
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
||||||
ZUser zUser = ZUser.find(player);
|
|
||||||
boolean canSeeNPC = (player.getWorld() == npc.getLocation().getWorld() && player.getLocation().distanceSquared(npc.getLocation()) <= distSq);
|
|
||||||
if (npc.getViewers().contains(zUser) && !canSeeNPC) {
|
|
||||||
npc.delete(zUser);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (canSeeNPC) {
|
|
||||||
if (!npc.getViewers().contains(zUser)) npc.spawn(zUser);
|
|
||||||
if (FunctionFactory.isTrue(npc, "look") && !hasPath) npc.lookAt(zUser, player.getLocation(), false);
|
|
||||||
npc.getHologram().updateNames(zUser);
|
|
||||||
ConversationModel conversationStorage = npc.getNpcPojo().getConversation();
|
|
||||||
if (conversationStorage != null && conversationStorage.getConversationType() == ConversationModel.ConversationType.RADIUS) npc.tryStartConversation(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package io.github.znetworkw.znpcservers.npc.task;
|
||||||
|
|
||||||
|
import io.github.znetworkw.znpcservers.npc.NPC;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class NPCPathTask extends BukkitRunnable {
|
||||||
|
public NPCPathTask(Plugin serversNPC) {
|
||||||
|
runTaskTimerAsynchronously(serversNPC, 60L, 1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
for (NPC npc : NPC.all()) if (npc.getNpcPath() != null) npc.getNpcPath().handle();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package io.github.znetworkw.znpcservers.npc.task;
|
||||||
|
|
||||||
|
import io.github.znetworkw.znpcservers.configuration.ConfigurationConstants;
|
||||||
|
import io.github.znetworkw.znpcservers.npc.FunctionFactory;
|
||||||
|
import io.github.znetworkw.znpcservers.npc.NPC;
|
||||||
|
import io.github.znetworkw.znpcservers.npc.conversation.ConversationModel;
|
||||||
|
import io.github.znetworkw.znpcservers.user.ZUser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class NPCUpdateTask extends BukkitRunnable {
|
||||||
|
public NPCUpdateTask(Plugin serversNPC) {
|
||||||
|
runTaskTimerAsynchronously(serversNPC, 60L, 10L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
int distSq = ConfigurationConstants.VIEW_DISTANCE * ConfigurationConstants.VIEW_DISTANCE;
|
||||||
|
for (NPC npc : NPC.all()) for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
ZUser zUser = ZUser.find(player);
|
||||||
|
boolean canSeeNPC = (player.getWorld() == npc.getLocation().getWorld() && player.getLocation().distanceSquared(npc.getLocation()) <= distSq);
|
||||||
|
if (npc.getViewers().contains(zUser) && !canSeeNPC) {
|
||||||
|
npc.delete(zUser);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (canSeeNPC) {
|
||||||
|
if (!npc.getViewers().contains(zUser)) npc.spawn(zUser);
|
||||||
|
if (FunctionFactory.isTrue(npc, "look") && npc.getNpcPath() == null) npc.lookAt(zUser, player.getLocation(), false);
|
||||||
|
npc.getHologram().updateNames(zUser);
|
||||||
|
ConversationModel conversationStorage = npc.getNpcPojo().getConversation();
|
||||||
|
if (conversationStorage != null && conversationStorage.getConversationType() == ConversationModel.ConversationType.RADIUS) npc.tryStartConversation(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,8 @@ import io.github.znetworkw.znpcservers.npc.NPC;
|
||||||
import io.github.znetworkw.znpcservers.npc.NPCModel;
|
import io.github.znetworkw.znpcservers.npc.NPCModel;
|
||||||
import io.github.znetworkw.znpcservers.npc.NPCPath;
|
import io.github.znetworkw.znpcservers.npc.NPCPath;
|
||||||
import io.github.znetworkw.znpcservers.npc.NPCType;
|
import io.github.znetworkw.znpcservers.npc.NPCType;
|
||||||
import io.github.znetworkw.znpcservers.npc.task.NPCManagerTask;
|
import io.github.znetworkw.znpcservers.npc.task.NPCPathTask;
|
||||||
|
import io.github.znetworkw.znpcservers.npc.task.NPCUpdateTask;
|
||||||
import io.github.znetworkw.znpcservers.npc.task.NPCSaveTask;
|
import io.github.znetworkw.znpcservers.npc.task.NPCSaveTask;
|
||||||
import io.github.znetworkw.znpcservers.user.ZUser;
|
import io.github.znetworkw.znpcservers.user.ZUser;
|
||||||
import io.github.znetworkw.znpcservers.utility.BungeeUtils;
|
import io.github.znetworkw.znpcservers.utility.BungeeUtils;
|
||||||
|
@ -77,7 +78,8 @@ public class ZNPCsPlus extends JavaPlugin {
|
||||||
SCHEDULER = new SchedulerUtils(this);
|
SCHEDULER = new SchedulerUtils(this);
|
||||||
BUNGEE_UTILS = new BungeeUtils(this);
|
BUNGEE_UTILS = new BungeeUtils(this);
|
||||||
Bukkit.getOnlinePlayers().forEach(ZUser::find);
|
Bukkit.getOnlinePlayers().forEach(ZUser::find);
|
||||||
new NPCManagerTask(this);
|
new NPCPathTask(this);
|
||||||
|
new NPCUpdateTask(this);
|
||||||
new NPCSaveTask(this, ConfigurationConstants.SAVE_DELAY);
|
new NPCSaveTask(this, ConfigurationConstants.SAVE_DELAY);
|
||||||
new PlayerListener(this);
|
new PlayerListener(this);
|
||||||
new InventoryListener(this);
|
new InventoryListener(this);
|
||||||
|
|
Loading…
Reference in a new issue