From eb9bfc78d16732ff60f8c2e82fed240bb9941a98 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 27 May 2020 11:30:04 +0200 Subject: [PATCH] fix: player invisible in some cases after join --- .../listeners/PlayerJoinQuitListener.java | 1 - .../de/cliffbreak/varo/utils/PlayerUtils.java | 27 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java index 5098c81..b716c89 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java @@ -46,7 +46,6 @@ public class PlayerJoinQuitListener implements Listener { @EventHandler public void onPlayerJoin(final PlayerJoinEvent e) { e.setJoinMessage(null); - this.plugin.getNPCManager().syncClones(e.getPlayer()); if (!this.plugin.getTeamManager().setTeam(e.getPlayer())) { e.getPlayer().kickPlayer(this.plugin.getLangUtils().get("Error.NoTeam")); diff --git a/varo/src/main/java/de/cliffbreak/varo/utils/PlayerUtils.java b/varo/src/main/java/de/cliffbreak/varo/utils/PlayerUtils.java index 1b75dab..3b1aba5 100644 --- a/varo/src/main/java/de/cliffbreak/varo/utils/PlayerUtils.java +++ b/varo/src/main/java/de/cliffbreak/varo/utils/PlayerUtils.java @@ -41,13 +41,17 @@ public class PlayerUtils { this.plugin.getLangUtils().get("Service.LoadingSubTitle"), 20, (seconds - 2) * 20, 20); p.sendTitle(title); + p.removePotionEffect(PotionEffectType.BLINDNESS); p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, seconds * 20, 1, false, false)); final BukkitTask hidePlayersTask = new BukkitRunnable() { @Override public void run() { - for (final Player player : Bukkit.getOnlinePlayers()) - p.hidePlayer(plugin, player); + for (final Player player : Bukkit.getOnlinePlayers()) { + if (!p.equals(player)) { + player.hidePlayer(plugin, p); + } + } } }.runTaskTimer(this.plugin, 0l, 1l); @@ -68,14 +72,23 @@ public class PlayerUtils { new BukkitRunnable() { @Override public void run() { - plugin.getNPCManager().removeClone(p); + hidePlayersTask.cancel(); + plugin.getNPCManager().removeClone(p.getUniqueId()); + p.teleport(plugin.getPlayerCache().getPlayerLocationCache(p.getUniqueId().toString().replace("-", ""))); p.setGameMode(GameMode.SURVIVAL); p.setFlySpeed(0.1f); p.setFlying(false); - p.teleport(plugin.getPlayerCache().getPlayerLocationCache(p.getUniqueId().toString().replace("-", ""))); - hidePlayersTask.cancel(); - for (final Player player : Bukkit.getOnlinePlayers()) - p.showPlayer(plugin, player); + new BukkitRunnable() { + @Override + public void run() { + p.removePotionEffect(PotionEffectType.INVISIBILITY); + for (final Player player : Bukkit.getOnlinePlayers()) { + p.showPlayer(plugin, player); + player.showPlayer(plugin, p); + } + plugin.getNPCManager().syncClones(p); + } + }.runTaskLater(plugin, 10); } }.runTaskLater(this.plugin, seconds * 20); }