diff --git a/src/main/java/us/myles/ViaVersion/ViaIdleThread.java b/src/main/java/us/myles/ViaVersion/ViaIdleThread.java index 7bcd59d6a..56b819eaa 100644 --- a/src/main/java/us/myles/ViaVersion/ViaIdleThread.java +++ b/src/main/java/us/myles/ViaVersion/ViaIdleThread.java @@ -1,7 +1,6 @@ package us.myles.ViaVersion; import org.bukkit.scheduler.BukkitRunnable; -import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; @@ -13,14 +12,15 @@ import java.util.UUID; public class ViaIdleThread extends BukkitRunnable { private final Map portedPlayers; - private final Class idlePacketClass; + private final Object idlePacket; public ViaIdleThread(Map portedPlayers) { this.portedPlayers = portedPlayers; try { - this.idlePacketClass = ReflectionUtil.nms("PacketPlayInFlying"); - } catch (ClassNotFoundException e) { - throw new RuntimeException("Couldn't find player idle packet, help!", e); + Class idlePacketClass = ReflectionUtil.nms("PacketPlayInFlying"); + idlePacket = idlePacketClass.newInstance(); + } catch (InstantiationException | IllegalArgumentException | IllegalAccessException | ClassNotFoundException e) { + throw new RuntimeException("Couldn't find/make player idle packet, help!", e); } } @@ -30,17 +30,8 @@ public class ViaIdleThread extends BukkitRunnable { if (info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket(); if (nextIdleUpdate <= System.currentTimeMillis()) { - try { - Object packet = idlePacketClass.newInstance(); - info.getChannel().pipeline().fireChannelRead(packet); - } catch (InstantiationException | IllegalAccessException e) { - System.out.println("Failed to create idle packet."); - if (ViaVersion.getInstance().isDebug()) { - e.printStackTrace(); - } - } finally { - info.get(MovementTracker.class).incrementIdlePacket(); - } + info.getChannel().pipeline().fireChannelRead(idlePacket); + info.get(MovementTracker.class).incrementIdlePacket(); } } }