Fix new player entity data getting lost while loading skin

This commit is contained in:
AJ Ferguson 2020-02-13 17:04:22 -09:00
parent fa7324e1f5
commit 35bf1b455e
6 changed files with 23 additions and 10 deletions

View file

@ -154,6 +154,8 @@ public class Entity {
} }
public void updateBedrockAttributes(GeyserSession session) { public void updateBedrockAttributes(GeyserSession session) {
if (!valid) return;
List<com.nukkitx.protocol.bedrock.data.Attribute> attributes = new ArrayList<>(); List<com.nukkitx.protocol.bedrock.data.Attribute> attributes = new ArrayList<>();
for (Map.Entry<AttributeType, Attribute> entry : this.attributes.entrySet()) { for (Map.Entry<AttributeType, Attribute> entry : this.attributes.entrySet()) {
if (!entry.getValue().getType().isBedrockAttribute()) if (!entry.getValue().getType().isBedrockAttribute())
@ -191,6 +193,7 @@ public class Entity {
metadata.put(EntityData.NAMETAG, MessageUtils.getBedrockMessage(name)); metadata.put(EntityData.NAMETAG, MessageUtils.getBedrockMessage(name));
break; break;
case 3: // is custom name visible case 3: // is custom name visible
if (!this.is(PlayerEntity.class))
metadata.put(EntityData.ALWAYS_SHOW_NAMETAG, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0)); metadata.put(EntityData.ALWAYS_SHOW_NAMETAG, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
break; break;
case 4: // silent case 4: // silent
@ -201,6 +204,12 @@ public class Entity {
break; break;
} }
updateBedrockMetadata(session);
}
public void updateBedrockMetadata(GeyserSession session) {
if (!valid) return;
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
entityDataPacket.setRuntimeEntityId(geyserId); entityDataPacket.setRuntimeEntityId(geyserId);
entityDataPacket.getMetadata().putAll(metadata); entityDataPacket.getMetadata().putAll(metadata);

View file

@ -81,10 +81,13 @@ public class PlayerEntity extends LivingEntity {
addPlayerPacket.setCustomFlags(0); addPlayerPacket.setCustomFlags(0);
addPlayerPacket.setDeviceId(""); addPlayerPacket.setDeviceId("");
addPlayerPacket.setPlatformChatId(""); addPlayerPacket.setPlatformChatId("");
addPlayerPacket.getMetadata().putAll(getMetadata()); addPlayerPacket.getMetadata().putAll(metadata);
valid = true; valid = true;
session.getUpstream().sendPacket(addPlayerPacket); session.getUpstream().sendPacket(addPlayerPacket);
updateEquipment(session);
updateBedrockAttributes(session);
} }
public void sendPlayer(GeyserSession session) { public void sendPlayer(GeyserSession session) {

View file

@ -56,9 +56,13 @@ public class EntityCache {
public void spawnEntity(Entity entity) { public void spawnEntity(Entity entity) {
entity.moveAbsolute(entity.getPosition(), entity.getRotation().getX(), entity.getRotation().getY()); entity.moveAbsolute(entity.getPosition(), entity.getRotation().getX(), entity.getRotation().getY());
cacheEntity(entity);
entity.spawnEntity(session);
}
public void cacheEntity(Entity entity) {
entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId()); entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId());
entities.put(entity.getGeyserId(), entity); entities.put(entity.getGeyserId(), entity);
entity.spawnEntity(session);
} }
public boolean removeEntity(Entity entity, boolean force) { public boolean removeEntity(Entity entity, boolean force) {

View file

@ -41,12 +41,8 @@ public class JavaEntityMetadataTranslator extends PacketTranslator<ServerEntityM
} }
if (entity == null) return; if (entity == null) return;
if (entity.isValid()) {
for (EntityMetadata metadata : packet.getMetadata()) { for (EntityMetadata metadata : packet.getMetadata()) {
entity.updateBedrockMetadata(metadata, session); entity.updateBedrockMetadata(metadata, session);
} }
} else {
entity.spawnEntity(session);
}
} }
} }

View file

@ -41,7 +41,7 @@ public class JavaEntityPropertiesTranslator extends PacketTranslator<ServerEntit
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) { if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity(); entity = session.getPlayerEntity();
} }
if (entity == null || !entity.isValid()) return; if (entity == null) return;
for (Attribute attribute : packet.getAttributes()) { for (Attribute attribute : packet.getAttributes()) {
switch (attribute.getType()) { switch (attribute.getType()) {

View file

@ -50,6 +50,7 @@ public class JavaSpawnPlayerTranslator extends PacketTranslator<ServerSpawnPlaye
entity.setEntityId(packet.getEntityId()); entity.setEntityId(packet.getEntityId());
entity.setPosition(position); entity.setPosition(position);
entity.setRotation(rotation); entity.setRotation(rotation);
session.getEntityCache().cacheEntity(entity);
// async skin loading // async skin loading
if (session.getUpstream().isInitialized()) { if (session.getUpstream().isInitialized()) {