Support new packet constructor

This commit is contained in:
filoghost 2019-06-05 11:48:44 +02:00
parent 484b4c8a9f
commit 644d58c80e

View File

@ -25,6 +25,7 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PacketConstructor; import com.comphenix.protocol.injector.PacketConstructor;
import com.comphenix.protocol.reflect.IntEnum; import com.comphenix.protocol.reflect.IntEnum;
import com.gmail.filoghost.holographicdisplays.util.NMSVersion;
public class WrapperPlayServerSpawnEntity extends AbstractPacket { public class WrapperPlayServerSpawnEntity extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY; public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY;
@ -90,10 +91,20 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
// Useful constructor // Useful constructor
private static PacketContainer fromEntity(Entity entity, int type, int objectData) { private static PacketContainer fromEntity(Entity entity, int type, int objectData) {
if (entityConstructor == null) if (entityConstructor == null) {
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_14_R1)) {
entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, entity, objectData);
} else {
entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, entity, type, objectData); entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, entity, type, objectData);
}
}
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_14_R1)) {
return entityConstructor.createPacket(entity, objectData);
} else {
return entityConstructor.createPacket(entity, type, objectData); return entityConstructor.createPacket(entity, type, objectData);
} }
}
/** /**
* Retrieve entity ID of the Object. * Retrieve entity ID of the Object.