Skip to content

Commit

Permalink
fix npc
Browse files Browse the repository at this point in the history
  • Loading branch information
boiscljo committed Apr 20, 2022
1 parent c366fab commit a71cb9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void commandSpawn(final @NotNull Player player,
}*/

GamesInventoryService.getInstance().addNPC(mode, player.getLocation());
GamesInventoryService.getInstance().addViewer(PlayerMapper.wrapPlayer(player));
GamesInventoryService.getInstance().addViewer(player);
LanguageService
.getInstance()
.get(MessageKeys.ADDED_NPC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ public void loadGamesInv() {
update();
}
Tasker.build(() -> Bukkit.getOnlinePlayers().forEach(player -> {
if (MainLobbyVisualsManager.isInWorld(player.getLocation())) {
addViewer(PlayerMapper.wrapPlayer(player));
}
addViewer(player);
})).delay(1L, TaskerTime.SECONDS).start();
}

Expand Down Expand Up @@ -231,17 +229,19 @@ public void update() {
}
}

public void addViewer(@NotNull PlayerWrapper player) {
public void addViewer(@NotNull Player player) {
removeViewer(player);
Logger.trace("addViewer", player.getName());

NPCs.forEach(npc -> {
Logger.trace("npc::addViewer", player.getName());
npc.npc.addViewer(player);
if (npc.location.getWorld().equals(player.getWorld()))
npc.npc.addViewer(PlayerMapper.wrapPlayer(player));
});
}

public void removeViewer(@NotNull PlayerWrapper player) {
NPCs.forEach(npc -> npc.npc.removeViewer(player));
public void removeViewer(@NotNull Player player) {
NPCs.forEach(npc -> npc.npc.removeViewer(PlayerMapper.wrapPlayer(player)));
}

@OnPreDisable
Expand All @@ -259,7 +259,7 @@ public void onPlayerJoin(PlayerJoinEvent e) {
final var player = e.getPlayer();
Tasker.build(() -> {
if (player.isOnline()) {
addViewer(PlayerMapper.wrapPlayer(player));
addViewer(player);
}
}).delay(1L, TaskerTime.TICKS).start();
}
Expand All @@ -269,7 +269,7 @@ public void onPlayerChangeWorld(PlayerChangedWorldEvent e) {
final var player = e.getPlayer();
Tasker.build(() -> {
if (player.isOnline()) {
addViewer(PlayerMapper.wrapPlayer(player));
addViewer(player);
}
}).delay(1L, TaskerTime.TICKS).start();
}
Expand Down

0 comments on commit a71cb9d

Please sign in to comment.