mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
fix EntityMetaData NullPointerException (1.7.10 - 1.8)
This commit is contained in:
parent
2583b43b31
commit
ada7f23ae5
@ -39,6 +39,83 @@ public class EntityMetaData {
|
|||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object getData(EntityMetaData.Types type, InByteBuffer buffer) {
|
||||||
|
Object data = null;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case BYTE:
|
||||||
|
data = buffer.readByte();
|
||||||
|
break;
|
||||||
|
case VAR_INT:
|
||||||
|
data = buffer.readVarInt();
|
||||||
|
break;
|
||||||
|
case SHORT:
|
||||||
|
data = buffer.readShort();
|
||||||
|
break;
|
||||||
|
case INT:
|
||||||
|
data = buffer.readInteger();
|
||||||
|
break;
|
||||||
|
case FLOAT:
|
||||||
|
data = buffer.readFloat();
|
||||||
|
break;
|
||||||
|
case STRING:
|
||||||
|
data = buffer.readString();
|
||||||
|
break;
|
||||||
|
case CHAT:
|
||||||
|
data = buffer.readTextComponent();
|
||||||
|
break;
|
||||||
|
case BOOLEAN:
|
||||||
|
data = buffer.readBoolean();
|
||||||
|
break;
|
||||||
|
case VECTOR:
|
||||||
|
data = new Vector(buffer.readInteger(), buffer.readInteger(), buffer.readInteger());
|
||||||
|
break;
|
||||||
|
case SLOT:
|
||||||
|
data = buffer.readSlot();
|
||||||
|
break;
|
||||||
|
case ROTATION:
|
||||||
|
data = new EntityRotation(buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
|
||||||
|
break;
|
||||||
|
case POSITION:
|
||||||
|
data = buffer.readPosition();
|
||||||
|
break;
|
||||||
|
case OPT_CHAT:
|
||||||
|
if (buffer.readBoolean()) {
|
||||||
|
data = buffer.readTextComponent();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OPT_POSITION:
|
||||||
|
if (buffer.readBoolean()) {
|
||||||
|
data = buffer.readPosition();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DIRECTION:
|
||||||
|
data = buffer.readDirection();
|
||||||
|
break;
|
||||||
|
case OPT_UUID:
|
||||||
|
if (buffer.readBoolean()) {
|
||||||
|
data = buffer.readUUID();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NBT:
|
||||||
|
data = buffer.readNBT();
|
||||||
|
break;
|
||||||
|
case PARTICLE:
|
||||||
|
data = buffer.readParticle();
|
||||||
|
break;
|
||||||
|
case POSE:
|
||||||
|
data = buffer.readPose();
|
||||||
|
break;
|
||||||
|
case BLOCK_ID:
|
||||||
|
int blockId = buffer.readVarInt();
|
||||||
|
data = Blocks.byId(blockId >> 4, blockId & 0xF);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unexpected value: " + type);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
public HashMap<Integer, MetaDataSet> getSets() {
|
public HashMap<Integer, MetaDataSet> getSets() {
|
||||||
return sets;
|
return sets;
|
||||||
}
|
}
|
||||||
@ -138,101 +215,6 @@ public class EntityMetaData {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object getData(EntityMetaData.Types type, InByteBuffer buffer) {
|
|
||||||
Object data = null;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case BYTE:
|
|
||||||
data = buffer.readByte();
|
|
||||||
break;
|
|
||||||
case VAR_INT:
|
|
||||||
data = buffer.readVarInt();
|
|
||||||
break;
|
|
||||||
case SHORT:
|
|
||||||
data = buffer.readShort();
|
|
||||||
break;
|
|
||||||
case INT:
|
|
||||||
data = buffer.readInteger();
|
|
||||||
break;
|
|
||||||
case FLOAT:
|
|
||||||
data = buffer.readFloat();
|
|
||||||
break;
|
|
||||||
case STRING:
|
|
||||||
data = buffer.readString();
|
|
||||||
break;
|
|
||||||
case CHAT:
|
|
||||||
data = buffer.readTextComponent();
|
|
||||||
break;
|
|
||||||
case BOOLEAN:
|
|
||||||
data = buffer.readBoolean();
|
|
||||||
break;
|
|
||||||
case VECTOR:
|
|
||||||
data = new Vector(buffer.readInteger(), buffer.readInteger(), buffer.readInteger());
|
|
||||||
break;
|
|
||||||
case SLOT:
|
|
||||||
data = buffer.readSlot();
|
|
||||||
break;
|
|
||||||
case ROTATION:
|
|
||||||
data = new EntityRotation(buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
|
|
||||||
break;
|
|
||||||
case POSITION:
|
|
||||||
data = buffer.readPosition();
|
|
||||||
break;
|
|
||||||
case OPT_CHAT:
|
|
||||||
if (buffer.readBoolean()) {
|
|
||||||
data = buffer.readTextComponent();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case OPT_POSITION:
|
|
||||||
if (buffer.readBoolean()) {
|
|
||||||
data = buffer.readPosition();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DIRECTION:
|
|
||||||
data = buffer.readDirection();
|
|
||||||
break;
|
|
||||||
case OPT_UUID:
|
|
||||||
if (buffer.readBoolean()) {
|
|
||||||
data = buffer.readUUID();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NBT:
|
|
||||||
data = buffer.readNBT();
|
|
||||||
break;
|
|
||||||
case PARTICLE:
|
|
||||||
data = buffer.readParticle();
|
|
||||||
break;
|
|
||||||
case POSE:
|
|
||||||
data = buffer.readPose();
|
|
||||||
break;
|
|
||||||
case BLOCK_ID:
|
|
||||||
int blockId = buffer.readVarInt();
|
|
||||||
data = Blocks.byId(blockId >> 4, blockId & 0xF);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unexpected value: " + type);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class MetaDataSet {
|
|
||||||
final int index;
|
|
||||||
final Object data;
|
|
||||||
|
|
||||||
public MetaDataSet(int index, Object data) {
|
|
||||||
this.index = index;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIndex() {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Types {
|
public enum Types {
|
||||||
BYTE(0),
|
BYTE(0),
|
||||||
SHORT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 1), new MapSet<>(ProtocolVersion.VERSION_1_9_4, 1000)}), // got removed in 1.9
|
SHORT(new MapSet[]{new MapSet<>(ProtocolVersion.VERSION_1_7_10, 1), new MapSet<>(ProtocolVersion.VERSION_1_9_4, 1000)}), // got removed in 1.9
|
||||||
@ -280,7 +262,29 @@ public class EntityMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getId(ProtocolVersion version) {
|
public int getId(ProtocolVersion version) {
|
||||||
return valueMap.get(version);
|
Integer ret = valueMap.get(version);
|
||||||
|
if (ret == null) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MetaDataSet {
|
||||||
|
final int index;
|
||||||
|
final Object data;
|
||||||
|
|
||||||
|
public MetaDataSet(int index, Object data) {
|
||||||
|
this.index = index;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex() {
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,7 @@ public class OtherPlayer extends Mob implements MobInterface {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxHealth() {
|
public int getMaxHealth() {
|
||||||
return 40;
|
return (int) (40 + metaData.getAbsorptionHearts());
|
||||||
//ToDo: absorption
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -27,6 +27,8 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket {
|
|||||||
boolean onGround;
|
boolean onGround;
|
||||||
byte flags;
|
byte flags;
|
||||||
|
|
||||||
|
int teleportId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean read(InPacketBuffer buffer) {
|
public boolean read(InPacketBuffer buffer) {
|
||||||
switch (buffer.getVersion()) {
|
switch (buffer.getVersion()) {
|
||||||
@ -37,12 +39,17 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket {
|
|||||||
onGround = buffer.readBoolean();
|
onGround = buffer.readBoolean();
|
||||||
return true;
|
return true;
|
||||||
case VERSION_1_8:
|
case VERSION_1_8:
|
||||||
|
location = buffer.readLocation();
|
||||||
|
yaw = buffer.readFloat();
|
||||||
|
pitch = buffer.readFloat();
|
||||||
|
flags = buffer.readByte();
|
||||||
|
return true;
|
||||||
case VERSION_1_9_4:
|
case VERSION_1_9_4:
|
||||||
location = buffer.readLocation();
|
location = buffer.readLocation();
|
||||||
yaw = buffer.readFloat();
|
yaw = buffer.readFloat();
|
||||||
pitch = buffer.readFloat();
|
pitch = buffer.readFloat();
|
||||||
flags = buffer.readByte();
|
flags = buffer.readByte();
|
||||||
onGround = buffer.readBoolean();
|
teleportId = buffer.readVarInt();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +77,10 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket {
|
|||||||
return onGround;
|
return onGround;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getTeleportId() {
|
||||||
|
return teleportId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketHandler h) {
|
public void handle(PacketHandler h) {
|
||||||
h.handle(this);
|
h.handle(this);
|
||||||
|
@ -50,6 +50,7 @@ public class PacketSpawnMob implements ClientboundPacket {
|
|||||||
return true;
|
return true;
|
||||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | NullPointerException e) {
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | NullPointerException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
//ToDo: on hypixel, here comes mob id 30 which could be an armor stand, but an armor stand is an object :?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case VERSION_1_9_4:
|
case VERSION_1_9_4:
|
||||||
|
@ -368,15 +368,16 @@ public class InByteBuffer {
|
|||||||
sets.put((int) index, new EntityMetaData.MetaDataSet(index, EntityMetaData.getData(type, this)));
|
sets.put((int) index, new EntityMetaData.MetaDataSet(index, EntityMetaData.getData(type, this)));
|
||||||
item = readByte();
|
item = readByte();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case VERSION_1_9_4:
|
case VERSION_1_9_4:
|
||||||
byte index = readByte();
|
byte index = readByte();
|
||||||
while (index != (byte) 0xFF) {
|
while (index != (byte) 0xFF) {
|
||||||
byte type2 = readByte();
|
EntityMetaData.Types type = EntityMetaData.Types.byId(readByte(), version);
|
||||||
EntityMetaData.Types type = EntityMetaData.Types.byId(type2, version);
|
|
||||||
sets.put((int) index, new EntityMetaData.MetaDataSet(index, EntityMetaData.getData(type, this)));
|
sets.put((int) index, new EntityMetaData.MetaDataSet(index, EntityMetaData.getData(type, this)));
|
||||||
index = readByte();
|
index = readByte();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return sets;
|
return sets;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user