mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-08 09:40:07 +01:00
Better ViaApi implementation
This commit is contained in:
parent
9393d805ec
commit
f4a0b53a6d
@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.exception.CancelException;
|
import us.myles.ViaVersion.exception.CancelException;
|
||||||
@ -66,10 +67,17 @@ public class VRInHandler extends ByteToMessageDecoder {
|
|||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
|
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
|
||||||
super.exceptionCaught(ctx, cause);
|
super.exceptionCaught(ctx, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
ProtocolInfo info = user.get(ProtocolInfo.class);
|
||||||
|
if (info.getUuid() != null) {
|
||||||
|
Via.getManager().removePortedClient(info.getUuid());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,14 +29,14 @@ public class VRUserConnection extends UserConnection {
|
|||||||
final Channel channel = this.getChannel();
|
final Channel channel = this.getChannel();
|
||||||
if (currentThread) {
|
if (currentThread) {
|
||||||
try {
|
try {
|
||||||
PipelineUtil.getContextBefore("decoder", channel.pipeline()).fireChannelRead(copy);
|
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
channel.eventLoop().submit(() -> {
|
channel.eventLoop().submit(() -> {
|
||||||
try {
|
try {
|
||||||
PipelineUtil.getContextBefore("decoder", channel.pipeline()).fireChannelRead(copy);
|
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ public class VRUserConnection extends UserConnection {
|
|||||||
packet.release();
|
packet.release();
|
||||||
final Channel channel = this.getChannel();
|
final Channel channel = this.getChannel();
|
||||||
try {
|
try {
|
||||||
PipelineUtil.getContextBefore("decoder", channel.pipeline()).fireChannelRead(copy);
|
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||||
return channel.newSucceededFuture();
|
return channel.newSucceededFuture();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -6,24 +6,35 @@ import us.myles.ViaVersion.api.ViaAPI;
|
|||||||
import us.myles.ViaVersion.api.boss.BossBar;
|
import us.myles.ViaVersion.api.boss.BossBar;
|
||||||
import us.myles.ViaVersion.api.boss.BossColor;
|
import us.myles.ViaVersion.api.boss.BossColor;
|
||||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
|
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class VRViaAPI implements ViaAPI {
|
public class VRViaAPI implements ViaAPI<Void> {
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(Object o) {
|
public int getPlayerVersion(Void o) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException("WHAT??? A INSTANCE OF VOID???");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(UUID uuid) {
|
public int getPlayerVersion(UUID uuid) {
|
||||||
throw new UnsupportedOperationException();
|
if (!isPorted(uuid)) {
|
||||||
|
try {
|
||||||
|
return Via.getManager().getInjector().getServerProtocolVersion();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Via.getManager().getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPorted(UUID uuid) {
|
public boolean isPorted(UUID uuid) {
|
||||||
throw new UnsupportedOperationException();
|
return Via.getManager().getPortedPlayers().containsKey(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -32,13 +43,14 @@ public class VRViaAPI implements ViaAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendRawPacket(Object o, ByteBuf byteBuf) throws IllegalArgumentException {
|
public void sendRawPacket(Void o, ByteBuf byteBuf) throws IllegalArgumentException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException("WHAT??? A INSTANCE OF VOID???");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendRawPacket(UUID uuid, ByteBuf byteBuf) throws IllegalArgumentException {
|
public void sendRawPacket(UUID uuid, ByteBuf byteBuf) throws IllegalArgumentException {
|
||||||
throw new UnsupportedOperationException();
|
UserConnection ci = Via.getManager().getPortedPlayers().get(uuid);
|
||||||
|
ci.sendRawPacket(byteBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,6 +65,9 @@ public class VRViaAPI implements ViaAPI {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<Integer> getSupportedVersions() {
|
public SortedSet<Integer> getSupportedVersions() {
|
||||||
throw new UnsupportedOperationException();
|
SortedSet<Integer> outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions());
|
||||||
|
outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols());
|
||||||
|
|
||||||
|
return outputSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,8 @@ public class VRMovementTransmitter extends MovementTransmitterProvider {
|
|||||||
ByteBuf buf = userConnection.getChannel().alloc().buffer();
|
ByteBuf buf = userConnection.getChannel().alloc().buffer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//Type.VAR_INT.write(buf, PacketWrapper.PASSTHROUGH_ID);
|
|
||||||
packet.writeToBuffer(buf);
|
packet.writeToBuffer(buf);
|
||||||
//PipelineUtil.getContextAfter("encoder", userConnection.getChannel().pipeline()).writeAndFlush(buf);
|
|
||||||
userConnection.getChannel().pipeline().context("encoder").writeAndFlush(buf);
|
userConnection.getChannel().pipeline().context("encoder").writeAndFlush(buf);
|
||||||
//PipelineUtil.getContextBefore("encoder", userConnection.getChannel().pipeline()).writeAndFlush(buf);
|
|
||||||
userConnection.get(MovementTracker.class).incrementIdlePacket();
|
userConnection.get(MovementTracker.class).incrementIdlePacket();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -4,7 +4,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
|
|
||||||
public class PipelineUtil {
|
public class PipelineUtil {
|
||||||
public static ChannelHandlerContext getContextBefore(String name, ChannelPipeline pipe) {
|
public static ChannelHandlerContext getPreviousContext(String name, ChannelPipeline pipe) {
|
||||||
String previous = null;
|
String previous = null;
|
||||||
for (String current : pipe.names()) {
|
for (String current : pipe.names()) {
|
||||||
if (name.equals(current))
|
if (name.equals(current))
|
||||||
|
Loading…
Reference in New Issue
Block a user