From acb7372eb704790578176b73ed920bd0f6a62796 Mon Sep 17 00:00:00 2001 From: Myles Date: Fri, 22 Apr 2016 13:36:10 +0100 Subject: [PATCH] Ensure that the player is online. --- .../protocol1_9to1_8/ViaIdleThread.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java index a81eca3b0..d6fe76d5e 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ViaIdleThread.java @@ -50,7 +50,7 @@ public class ViaIdleThread extends BukkitRunnable { } catch (NoSuchFieldException | InstantiationException | IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException("Couldn't make player idle packet, help!", e); } - if(USE_NMS) { + if (USE_NMS) { try { getHandle = ReflectionUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle"); } catch (NoSuchMethodException | ClassNotFoundException e) { @@ -70,6 +70,7 @@ public class ViaIdleThread extends BukkitRunnable { } } } + @Override public void run() { for (UserConnection info : portedPlayers.values()) { @@ -79,15 +80,19 @@ public class ViaIdleThread extends BukkitRunnable { if (info.getChannel().isOpen()) { if (USE_NMS) { Player player = Bukkit.getPlayer(info.get(ProtocolInfo.class).getUuid()); - try { - // Tick player - Object entityPlayer = getHandle.invoke(player); - Object pc = connection.get(entityPlayer); - handleFlying.invoke(pc, (info.get(MovementTracker.class).isGround() ? idlePacket2 : idlePacket)); - // Tick world - info.get(MovementTracker.class).incrementIdlePacket(); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); + if (player != null) { + try { + // Tick player + Object entityPlayer = getHandle.invoke(player); + Object pc = connection.get(entityPlayer); + if (pc != null) { + handleFlying.invoke(pc, (info.get(MovementTracker.class).isGround() ? idlePacket2 : idlePacket)); + // Tick world + info.get(MovementTracker.class).incrementIdlePacket(); + } + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } } } else { // Old method using packets.