3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-19 18:40:04 +02:00

Merge branch 'master' into apiv2

Dieser Commit ist enthalten in:
Myles 2016-03-23 12:40:08 +00:00
Commit c1e77a49b6

Datei anzeigen

@ -1,7 +1,6 @@
package us.myles.ViaVersion; package us.myles.ViaVersion;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
@ -13,14 +12,15 @@ import java.util.UUID;
public class ViaIdleThread extends BukkitRunnable { public class ViaIdleThread extends BukkitRunnable {
private final Map<UUID, UserConnection> portedPlayers; private final Map<UUID, UserConnection> portedPlayers;
private final Class<?> idlePacketClass; private final Object idlePacket;
public ViaIdleThread(Map<UUID, UserConnection> portedPlayers) { public ViaIdleThread(Map<UUID, UserConnection> portedPlayers) {
this.portedPlayers = portedPlayers; this.portedPlayers = portedPlayers;
try { try {
this.idlePacketClass = ReflectionUtil.nms("PacketPlayInFlying"); Class<?> idlePacketClass = ReflectionUtil.nms("PacketPlayInFlying");
} catch (ClassNotFoundException e) { idlePacket = idlePacketClass.newInstance();
throw new RuntimeException("Couldn't find player idle packet, help!", e); } catch (InstantiationException | IllegalArgumentException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException("Couldn't find/make player idle packet, help!", e);
} }
} }
@ -30,19 +30,10 @@ public class ViaIdleThread extends BukkitRunnable {
if (info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { if (info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) {
long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket(); long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket();
if (nextIdleUpdate <= System.currentTimeMillis()) { if (nextIdleUpdate <= System.currentTimeMillis()) {
try { info.getChannel().pipeline().fireChannelRead(idlePacket);
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.get(MovementTracker.class).incrementIdlePacket();
} }
} }
} }
} }
} }
}