mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-12-21 16:17:37 +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.handler.codec.ByteToMessageDecoder;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.exception.CancelException;
|
||||
@ -66,10 +67,17 @@ public class VRInHandler extends ByteToMessageDecoder {
|
||||
buf.release();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
|
||||
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();
|
||||
if (currentThread) {
|
||||
try {
|
||||
PipelineUtil.getContextBefore("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
channel.eventLoop().submit(() -> {
|
||||
try {
|
||||
PipelineUtil.getContextBefore("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -56,7 +56,7 @@ public class VRUserConnection extends UserConnection {
|
||||
packet.release();
|
||||
final Channel channel = this.getChannel();
|
||||
try {
|
||||
PipelineUtil.getContextBefore("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||
PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy);
|
||||
return channel.newSucceededFuture();
|
||||
} catch (Exception e) {
|
||||
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.BossColor;
|
||||
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.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VRViaAPI implements ViaAPI {
|
||||
public class VRViaAPI implements ViaAPI<Void> {
|
||||
@Override
|
||||
public int getPlayerVersion(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
public int getPlayerVersion(Void o) {
|
||||
throw new UnsupportedOperationException("WHAT??? A INSTANCE OF VOID???");
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
public boolean isPorted(UUID uuid) {
|
||||
throw new UnsupportedOperationException();
|
||||
return Via.getManager().getPortedPlayers().containsKey(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -32,13 +43,14 @@ public class VRViaAPI implements ViaAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(Object o, ByteBuf byteBuf) throws IllegalArgumentException {
|
||||
throw new UnsupportedOperationException();
|
||||
public void sendRawPacket(Void o, ByteBuf byteBuf) throws IllegalArgumentException {
|
||||
throw new UnsupportedOperationException("WHAT??? A INSTANCE OF VOID???");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(UUID uuid, ByteBuf byteBuf) throws IllegalArgumentException {
|
||||
throw new UnsupportedOperationException();
|
||||
UserConnection ci = Via.getManager().getPortedPlayers().get(uuid);
|
||||
ci.sendRawPacket(byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,6 +65,9 @@ public class VRViaAPI implements ViaAPI {
|
||||
|
||||
@Override
|
||||
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();
|
||||
|
||||
try {
|
||||
//Type.VAR_INT.write(buf, PacketWrapper.PASSTHROUGH_ID);
|
||||
packet.writeToBuffer(buf);
|
||||
//PipelineUtil.getContextAfter("encoder", userConnection.getChannel().pipeline()).writeAndFlush(buf);
|
||||
userConnection.getChannel().pipeline().context("encoder").writeAndFlush(buf);
|
||||
//PipelineUtil.getContextBefore("encoder", userConnection.getChannel().pipeline()).writeAndFlush(buf);
|
||||
userConnection.get(MovementTracker.class).incrementIdlePacket();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -4,7 +4,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
|
||||
public class PipelineUtil {
|
||||
public static ChannelHandlerContext getContextBefore(String name, ChannelPipeline pipe) {
|
||||
public static ChannelHandlerContext getPreviousContext(String name, ChannelPipeline pipe) {
|
||||
String previous = null;
|
||||
for (String current : pipe.names()) {
|
||||
if (name.equals(current))
|
||||
|
Loading…
Reference in New Issue
Block a user