Allow sharing of protocol packet handler and be more verbose to do with metaindex data

This commit is contained in:
Myles 2016-02-29 22:43:53 +00:00
parent 6f605e8d6c
commit c0296f04a1
2 changed files with 31 additions and 17 deletions

View File

@ -1,15 +1,13 @@
package us.myles.ViaVersion.handlers; package us.myles.ViaVersion.handlers;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.*;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import us.myles.ViaVersion.ConnectionInfo; import us.myles.ViaVersion.ConnectionInfo;
import us.myles.ViaVersion.ReflectionUtil; import us.myles.ViaVersion.ReflectionUtil;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ChannelHandler.Sharable
public class ViaOutboundPacketHandler extends ChannelOutboundHandlerAdapter { public class ViaOutboundPacketHandler extends ChannelOutboundHandlerAdapter {
private final ConnectionInfo info; private final ConnectionInfo info;

View File

@ -327,12 +327,12 @@ public class OutgoingTransformer {
output.writeBytes(input); output.writeBytes(input);
return; return;
} }
if(packet == PacketType.PLAY_TEAM) { if (packet == PacketType.PLAY_TEAM) {
String teamName = PacketUtil.readString(input); String teamName = PacketUtil.readString(input);
PacketUtil.writeString(teamName, output); PacketUtil.writeString(teamName, output);
byte mode = input.readByte(); byte mode = input.readByte();
output.writeByte(mode); output.writeByte(mode);
if(mode == 0 || mode == 2){ if (mode == 0 || mode == 2) {
PacketUtil.writeString(PacketUtil.readString(input), output); PacketUtil.writeString(PacketUtil.readString(input), output);
PacketUtil.writeString(PacketUtil.readString(input), output); PacketUtil.writeString(PacketUtil.readString(input), output);
PacketUtil.writeString(PacketUtil.readString(input), output); PacketUtil.writeString(PacketUtil.readString(input), output);
@ -420,15 +420,24 @@ public class OutgoingTransformer {
} }
private void transformMetadata(Entity entity, List dw, ByteBuf output) { private void transformMetadata(Entity entity, List dw, ByteBuf output) {
try { if (dw != null) {
if (dw != null) { short id = -1;
short id = -1; int data = -1;
int data = -1;
Iterator iterator = dw.iterator(); Iterator iterator = dw.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Object watchableObj = iterator.next(); // Object watchableObj = iterator.next(); //
MetaIndex metaIndex = MetaIndex.getIndex(entity, (int) ReflectionUtil.invoke(watchableObj, "a")); MetaIndex metaIndex = null;
try {
metaIndex = MetaIndex.getIndex(entity, (int) ReflectionUtil.invoke(watchableObj, "a"));
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
try {
if (metaIndex.getNewType() != NewType.Discontinued) { if (metaIndex.getNewType() != NewType.Discontinued) {
if (metaIndex.getNewType() != NewType.BlockID || id != -1 && data == -1 || id == -1 && data != -1) { // block ID is only written if we have both parts if (metaIndex.getNewType() != NewType.BlockID || id != -1 && data == -1 || id == -1 && data != -1) { // block ID is only written if we have both parts
output.writeByte(metaIndex.getNewIndex()); output.writeByte(metaIndex.getNewIndex());
@ -507,13 +516,20 @@ public class OutgoingTransformer {
output.writeFloat((float) ReflectionUtil.invoke(value, "getY")); output.writeFloat((float) ReflectionUtil.invoke(value, "getY"));
output.writeFloat((float) ReflectionUtil.invoke(value, "getZ")); output.writeFloat((float) ReflectionUtil.invoke(value, "getZ"));
} }
} }
} catch (Exception e) {
if (entity != null) {
System.out.println("An error occurred with entity meta data for " + entity.getType());
System.out.println("Old ID: " + metaIndex.getIndex() + " New ID: " + metaIndex.getNewIndex());
System.out.println("Old Type: " + metaIndex.getOldType() + " New Type: " + metaIndex.getNewType());
}
e.printStackTrace();
} }
} }
output.writeByte(255);
}catch(Exception e){
e.printStackTrace();
} }
output.writeByte(255);
} }