diff --git a/build.gradle b/build.gradle index 10bff0b..958f766 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ configurations { } dependencies { - shade ('us.myles:viaversion:1.5.1-SNAPSHOT') { + shade ('us.myles:viaversion:1.5.1') { transitive = false changing = true } diff --git a/src/main/java/com/github/creeper123123321/viarift/platform/VRLoader.java b/src/main/java/com/github/creeper123123321/viarift/platform/VRLoader.java index 25b1f99..b3f2877 100644 --- a/src/main/java/com/github/creeper123123321/viarift/platform/VRLoader.java +++ b/src/main/java/com/github/creeper123123321/viarift/platform/VRLoader.java @@ -24,10 +24,10 @@ package com.github.creeper123123321.viarift.platform; -import com.github.creeper123123321.viarift.provider.VRMovementTransmitter; import com.github.creeper123123321.viarift.provider.VRVersionProvider; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.platform.ViaPlatformLoader; +import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter; import us.myles.ViaVersion.protocols.base.VersionProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; @@ -35,7 +35,7 @@ public class VRLoader implements ViaPlatformLoader { @Override public void load() { Via.getManager().getProviders().use(VersionProvider.class, new VRVersionProvider()); - Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VRMovementTransmitter()); + Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter()); } @Override diff --git a/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java b/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java index fc3d28b..41b9f09 100644 --- a/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java +++ b/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java @@ -24,18 +24,17 @@ package com.github.creeper123123321.viarift.platform; -import com.github.creeper123123321.viarift.util.PipelineUtil; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; -import io.netty.channel.socket.SocketChannel; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.util.PipelineUtil; public class VRUserConnection extends UserConnection { - public VRUserConnection(SocketChannel socketChannel) { + public VRUserConnection(Channel socketChannel) { super(socketChannel); } // Based on https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/reflection/Injector.java @@ -74,4 +73,15 @@ public class VRUserConnection extends UserConnection { PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy); return channel.newSucceededFuture(); } + + @Override + public void sendRawPacketToServer(ByteBuf packet, boolean currentThread) { + if (currentThread) { + getChannel().pipeline().context("encoder").writeAndFlush(packet); + } else { + getChannel().eventLoop().submit(() -> { + getChannel().pipeline().context("encoder").writeAndFlush(packet); + }); + } + } } diff --git a/src/main/java/com/github/creeper123123321/viarift/provider/VRMovementTransmitter.java b/src/main/java/com/github/creeper123123321/viarift/provider/VRMovementTransmitter.java deleted file mode 100644 index 719c75f..0000000 --- a/src/main/java/com/github/creeper123123321/viarift/provider/VRMovementTransmitter.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2018 creeper123123321 and contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.github.creeper123123321.viarift.provider; - -import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker; - -public class VRMovementTransmitter extends MovementTransmitterProvider { - @Override - public Object getFlyingPacket() { - return null; - } - - @Override - public Object getGroundPacket() { - return null; - } - - @Override - public void sendPlayer(UserConnection userConnection) { - // Based on https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/providers/ClientMovementTransmitterProvider.java - if (userConnection.get(ProtocolInfo.class).getState() != State.PLAY) return; - - PacketWrapper packet = new PacketWrapper(0x03, null, userConnection); - packet.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); - - ByteBuf buf = userConnection.getChannel().alloc().buffer(); - - try { - packet.writeToBuffer(buf); - userConnection.getChannel().pipeline().context("encoder").writeAndFlush(buf); - userConnection.get(MovementTracker.class).incrementIdlePacket(); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/com/github/creeper123123321/viarift/util/PipelineUtil.java b/src/main/java/com/github/creeper123123321/viarift/util/PipelineUtil.java deleted file mode 100644 index 2127884..0000000 --- a/src/main/java/com/github/creeper123123321/viarift/util/PipelineUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2018 creeper123123321 and contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.github.creeper123123321.viarift.util; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; - -public class PipelineUtil { - public static ChannelHandlerContext getPreviousContext(String name, ChannelPipeline pipe) { - String previous = null; - for (String current : pipe.names()) { - if (name.equals(current)) - break; - previous = current; - } - return pipe.context(previous); - } -}