Skip to content

Commit

Permalink
Fixed npc not looking back if there was a player within 5 blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxikle committed May 25, 2023
1 parent a9d58a9 commit 034c1cc
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/main/java/dev/foxikle/customnpcs/listeners/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ public void onChat(AsyncPlayerChatEvent e) {
CustomNPCs.getInstance().waiting.remove(e.getPlayer());
CustomNPCs.getInstance().menus.get(e.getPlayer()).getNpc().setCommand(e.getMessage());
e.getPlayer().sendMessage(ChatColor.GREEN + "Successfully set command to be '" + e.getMessage().replace("/", "") + "'");
Bukkit.getScheduler().runTask(CustomNPCs.getInstance(), new Runnable() {
@Override
public void run() {
e.getPlayer().openInventory(CustomNPCs.getInstance().menus.get(e.getPlayer()).getMainMenu());
}
});
Bukkit.getScheduler().runTask(CustomNPCs.getInstance(), () -> e.getPlayer().openInventory(CustomNPCs.getInstance().menus.get(e.getPlayer()).getMainMenu()));
e.setCancelled(true);
}
}
Expand All @@ -69,7 +64,7 @@ public void onPlayerLogin(PlayerJoinEvent e) {
public void onMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
for (NPC npc : CustomNPCs.getInstance().npcs.values()) {
if (getDistance(e.getPlayer().getLocation(), npc.getLocation()) <= 5) { // should be 5
if (getDistance(e.getPlayer().getLocation(), npc.getLocation()) <= 5) {
npc.lookAt(EntityAnchorArgument.Anchor.EYES, ((CraftPlayer) player).getHandle(), EntityAnchorArgument.Anchor.EYES);
} else if (getDistance(e.getFrom(), npc.getLocation()) >= 48 && getDistance(e.getTo(), npc.getLocation()) <= 48) {
npc.injectPlayer(player);
Expand All @@ -79,6 +74,8 @@ public void onMove(PlayerMoveEvent e) {
entities.removeIf(entity -> entity.getScoreboardTags().contains("NPC"));
for (Entity en : entities) {
if (en.getType() == EntityType.PLAYER) {
Player p = (Player) en;
npc.lookAt(EntityAnchorArgument.Anchor.EYES, ((CraftPlayer) p).getHandle(), EntityAnchorArgument.Anchor.EYES);
return;
}
}
Expand Down

0 comments on commit 034c1cc

Please sign in to comment.