diff --git a/.vscode/settings.json b/.vscode/settings.json index 3964542..00a149a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,7 @@ "cliffbreak", "mkdir", "teamcolors", + "testremove", "unban", "varo" ], diff --git a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java index 3b40793..5ea01ed 100644 --- a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java +++ b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java @@ -83,12 +83,7 @@ public class VaroCommand implements CommandExecutor { sender.sendMessage(MessageUtils.getRichTextComponent("§5" + "Team 10", "")); } else if (args.length == 1 && args[0].equals("test")) { if (sender instanceof Player) { - try { - plugin.npcManager.createClone((Player) sender, false); - } catch (IOException e) { - sender.sendMessage( - "§c§lFehler:§r§c beim Verbinden mit der Mojang-API ist ein Fehler aufgetreten. Eventuell sind die Mojang Server down."); - } + plugin.npcManager.createClone((Player) sender, false); } else { sender.sendMessage("§c§lFehler:§r§c Dieses Kommando kann nur durch einen Spieler ausgeführt werden."); } @@ -103,7 +98,7 @@ public class VaroCommand implements CommandExecutor { sender.sendMessage("§a/varo start: §rStarte das Varo Projekt!"); sender.sendMessage("§a/varo unban [Spieler]: §rSpieler wieder auf den Server lassen"); sender.sendMessage("§a/varo teamcolors: §rZeige verfügbare Team-Farben an"); - sender.sendMessage("§a/varo test: §rSpawne einen Klon"); + sender.sendMessage("§a/varo test: §rErstelle einen Klon"); sender.sendMessage("§a/varo testremove: §rLösche den Klon"); sender.sendMessage("\n§6=========================================="); } 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 967378e..b0d3519 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java @@ -27,11 +27,7 @@ public class PlayerJoinQuitListener implements Listener { @EventHandler() public void onPlayerQuit(final PlayerQuitEvent e) { e.setQuitMessage(null); - try { - plugin.npcManager.createClone(e.getPlayer(), true); - } catch (IOException ex) { - ex.printStackTrace(); - } + plugin.npcManager.createClone(e.getPlayer(), true); Bukkit.broadcast( MessageUtils.getRichTextComponent(e.getPlayer().getName(), "§f hat den Server verlassen.", true)); } diff --git a/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java b/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java index 547712d..ccfa252 100644 --- a/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java +++ b/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java @@ -13,6 +13,7 @@ import org.bukkit.craftbukkit.v1_15_R1.CraftServer; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; import org.json.simple.JSONArray; @@ -57,7 +58,7 @@ public class NPCManager { this.afkTeam.setColor(ChatColor.GRAY); } - public void createClone(final Player player, final boolean shouldHaveAFKPrefix) throws IOException { + public void createClone(final Player player, final boolean shouldHaveAFKPrefix) { final Location location = player.getLocation(); final MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer(); final WorldServer nmsWorld = ((CraftWorld) player.getWorld()).getHandle(); @@ -72,7 +73,6 @@ public class NPCManager { properties.get("signature").toString())); } catch (IOException | ParseException e) { plugin.getLogger().info(e.getMessage()); - throw new IOException(); } final EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld)); @@ -87,7 +87,12 @@ public class NPCManager { for (Player connectionPlayer : Bukkit.getOnlinePlayers()) { final PlayerConnection connection = ((CraftPlayer) connectionPlayer).getHandle().playerConnection; - connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc)); + new BukkitRunnable() { + @Override + public void run() { + connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc)); + } + }.runTaskLater(plugin, 20); connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc)); connection.sendPacket( new PacketPlayOutEntityHeadRotation(npc, (byte) ((location.getYaw() * 256.0F) / 360.0F))); @@ -123,7 +128,6 @@ public class NPCManager { for (Player connectionPlayer : Bukkit.getOnlinePlayers()) { final PlayerConnection connection = ((CraftPlayer) connectionPlayer).getHandle().playerConnection; - connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, npc)); connection.sendPacket(new PacketPlayOutEntityDestroy(npc.getId())); } this.players.remove(npc);