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

View file

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

View file

@ -56,9 +56,13 @@ public class EntityCache {
public void spawnEntity(Entity entity) {
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());
entities.put(entity.getGeyserId(), entity);
entity.spawnEntity(session);
}
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.isValid()) {
for (EntityMetadata metadata : packet.getMetadata()) {
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()) {
entity = session.getPlayerEntity();
}
if (entity == null || !entity.isValid()) return;
if (entity == null) return;
for (Attribute attribute : packet.getAttributes()) {
switch (attribute.getType()) {

View file

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