From 639c9ea8c1f6242c120df6c807467f2e30297d3e Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 30 Mar 2016 16:43:01 +0100 Subject: [PATCH] Fix 1.8R0.1 not working, ensure flying packets are sent from right place in pipeline, should fix #273 --- .../java/us/myles/ViaVersion/ViaIdleThread.java | 7 ++++++- .../java/us/myles/ViaVersion/ViaVersionPlugin.java | 7 +++++-- .../us/myles/ViaVersion/api/PacketWrapper.java | 11 ++--------- .../protocol1_9to1_8/Protocol1_9TO1_8.java | 3 +++ .../us/myles/ViaVersion/util/PipelineUtil.java | 14 ++++++++++++++ 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/ViaIdleThread.java b/src/main/java/us/myles/ViaVersion/ViaIdleThread.java index 56b819eaa..1a45dee76 100644 --- a/src/main/java/us/myles/ViaVersion/ViaIdleThread.java +++ b/src/main/java/us/myles/ViaVersion/ViaIdleThread.java @@ -1,10 +1,13 @@ package us.myles.ViaVersion; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; import org.bukkit.scheduler.BukkitRunnable; 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; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker; +import us.myles.ViaVersion.util.PipelineUtil; import us.myles.ViaVersion.util.ReflectionUtil; import java.util.Map; @@ -30,7 +33,9 @@ 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()) { - info.getChannel().pipeline().fireChannelRead(idlePacket); + ChannelHandlerContext context = PipelineUtil.getContextBefore("decoder", info.getChannel().pipeline()); + context.fireChannelRead(idlePacket); + info.get(MovementTracker.class).incrementIdlePacket(); } } diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index daa3e2af7..934d1dd71 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -70,8 +70,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe getLogger().info("ViaVersion " + getDescription().getVersion() + " is now enabled, injecting."); injectPacketHandler(); - if (getConfig().getBoolean("simulate-pt", true)) - new ViaIdleThread(portedPlayers).runTaskTimerAsynchronously(this, 1L, 1L); // Updates player's idle status + if (isCheckForUpdates()) UpdateUtil.sendUpdateMessage(this); @@ -359,4 +358,8 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe e.printStackTrace(); } } + + public Map getPortedPlayers() { + return portedPlayers; + } } diff --git a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index 47d9b690e..2f0dba7cc 100644 --- a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.TypeConverter; import us.myles.ViaVersion.exception.InformativeException; import us.myles.ViaVersion.handlers.ViaDecodeHandler; +import us.myles.ViaVersion.util.PipelineUtil; import java.io.IOException; import java.util.ArrayList; @@ -278,15 +279,7 @@ public class PacketWrapper { writeToBuffer(output); - boolean mark = false; - for (String s : user().getChannel().pipeline().names()) { - if (mark) { - user().getChannel().pipeline().context(user().getChannel().pipeline().get(s)).fireChannelRead(output); - return; - } - if (s.equalsIgnoreCase("decompress")) - mark = true; - } + PipelineUtil.getContextBefore("decompress", user().getChannel().pipeline()).fireChannelRead(output); } } } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java index 2986ca8a8..7ee7f7b14 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java @@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import org.bukkit.Bukkit; import org.bukkit.inventory.ItemStack; +import us.myles.ViaVersion.ViaIdleThread; import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.ViaVersion; @@ -103,6 +104,8 @@ public class Protocol1_9TO1_8 extends Protocol { plugin.getLogger().info("Enabling PaperSpigot patch: Fixes block placement."); Bukkit.getPluginManager().registerEvents(new PaperPatch(), plugin); } + if (plugin.getConfig().getBoolean("simulate-pt", true)) + new ViaIdleThread(plugin.getPortedPlayers()).runTaskTimerAsynchronously(plugin, 1L, 1L); // Updates player's idle status } @Override diff --git a/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java b/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java index 205323419..cc8e79300 100644 --- a/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java +++ b/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java @@ -1,7 +1,9 @@ package us.myles.ViaVersion.util; import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.MessageToByteEncoder; @@ -57,4 +59,16 @@ public class PipelineUtil { } return false; } + + public static ChannelHandlerContext getContextBefore(String name, ChannelPipeline pipeline) { + boolean mark = false; + for (String s : pipeline.names()) { + if (mark) { + return pipeline.context(pipeline.get(s)); + } + if (s.equalsIgnoreCase(name)) + mark = true; + } + return null; + } }