3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +01:00

Ignore all entity metadata for player names

The Java client ignores this; only the GameProfile of the player can set this.

Fixes #2563
Dieser Commit ist enthalten in:
Camotoy 2021-10-10 14:54:06 -04:00
Ursprung bf1359cf0c
Commit 265c42fe09
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
3 geänderte Dateien mit 23 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -41,7 +41,6 @@ import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import lombok.Getter;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import org.geysermc.connector.entity.player.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
@ -51,7 +50,7 @@ import org.geysermc.connector.utils.MathUtils;
@Setter
public class Entity {
protected long entityId;
protected long geyserId;
protected final long geyserId;
protected Vector3f position;
protected Vector3f motion;
@ -258,8 +257,7 @@ public class Entity {
setDisplayName(session, (Component) entityMetadata.getValue());
break;
case 3: // is custom name visible
if (!this.is(PlayerEntity.class))
metadata.put(EntityData.NAMETAG_ALWAYS_SHOW, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
setDisplayNameVisible(entityMetadata);
break;
case 4: // silent
metadata.getFlags().setFlag(EntityFlag.SILENT, (boolean) entityMetadata.getValue());
@ -306,19 +304,18 @@ public class Entity {
return false;
}
/**
* @return the translated string display
*/
protected String setDisplayName(GeyserSession session, Component name) {
protected void setDisplayName(GeyserSession session, Component name) {
if (name != null) {
String displayName = MessageTranslator.convertMessage(name, session.getLocale());
metadata.put(EntityData.NAMETAG, displayName);
return displayName;
} else if (!metadata.getString(EntityData.NAMETAG).isEmpty()) {
// Clear nametag
metadata.put(EntityData.NAMETAG, "");
}
return null;
}
protected void setDisplayNameVisible(EntityMetadata entityMetadata) {
metadata.put(EntityData.NAMETAG_ALWAYS_SHOW, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
}
/**
@ -326,6 +323,7 @@ public class Entity {
*/
protected void setDimensions(Pose pose) {
// No flexibility options for basic entities
//TODO don't even set this for basic entities since we already set it on entity initialization
metadata.put(EntityData.BOUNDING_BOX_WIDTH, entityType.getWidth());
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, entityType.getHeight());
}

Datei anzeigen

@ -40,7 +40,6 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.data.entity.EntityLinkData;
import com.nukkitx.protocol.bedrock.packet.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import net.kyori.adventure.text.Component;
@ -68,9 +67,6 @@ public class PlayerEntity extends LivingEntity {
private String username;
private boolean playerList = true; // Player is in the player list
@Getter(AccessLevel.NONE)
private String displayName;
/**
* Saves the parrot currently on the player's left shoulder; otherwise null
*/
@ -86,7 +82,6 @@ public class PlayerEntity extends LivingEntity {
profile = gameProfile;
uuid = gameProfile.getId();
username = gameProfile.getName();
displayName = username;
// For the OptionalPack, set all bits as invisible by default as this matches Java Edition behavior
metadata.put(EntityData.MARK_VARIANT, 0xff);
@ -100,6 +95,9 @@ public class PlayerEntity extends LivingEntity {
setBelowNameText(session, objective);
}
// The name can't be updated later (the entity metadata for it is ignored), so we need to check for this now
updateDisplayName(session, null, false);
AddPlayerPacket addPlayerPacket = new AddPlayerPacket();
addPlayerPacket.setUuid(uuid);
addPlayerPacket.setUsername(username);
@ -311,13 +309,8 @@ public class PlayerEntity extends LivingEntity {
}
@Override
protected String setDisplayName(GeyserSession session, Component name) {
String displayName = super.setDisplayName(session, name);
this.displayName = displayName != null ? displayName : username;
// Update if we know this player has a team
updateDisplayName(session, null, false);
return this.displayName;
protected void setDisplayName(GeyserSession session, Component name) {
// Doesn't do anything for players
}
//todo this will become common entity logic once UUID support is implemented for them
@ -332,7 +325,7 @@ public class PlayerEntity extends LivingEntity {
}
boolean needsUpdate;
String newDisplayName = this.displayName;
String newDisplayName = this.username;
if (team != null) {
if (team.isVisibleFor(session.getPlayerEntity().getUsername())) {
TeamColor color = team.getColor();
@ -345,7 +338,7 @@ public class PlayerEntity extends LivingEntity {
// We have to emulate what modern Java text already does for us and add the color to each section
String prefix = team.getCurrentData().getPrefix();
String suffix = team.getCurrentData().getSuffix();
newDisplayName = chatColor + prefix + chatColor + this.displayName + chatColor + suffix;
newDisplayName = chatColor + prefix + chatColor + this.username + chatColor + suffix;
} else {
// The name is not visible to the session player; clear name
newDisplayName = "";
@ -355,7 +348,7 @@ public class PlayerEntity extends LivingEntity {
} else if (useGivenTeam) {
// The name has reset, if it was previously something else
needsUpdate = !newDisplayName.equals(metadata.getString(EntityData.NAMETAG));
metadata.put(EntityData.NAMETAG, this.displayName);
metadata.put(EntityData.NAMETAG, this.username);
} else {
needsUpdate = false;
}
@ -369,6 +362,11 @@ public class PlayerEntity extends LivingEntity {
}
}
@Override
protected void setDisplayNameVisible(EntityMetadata entityMetadata) {
// Doesn't do anything for players
}
@Override
protected void setDimensions(Pose pose) {
float height;

Datei anzeigen

@ -25,13 +25,12 @@
package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket;
import org.geysermc.connector.utils.InteractiveTagManager;
import org.geysermc.connector.utils.LanguageUtils;