Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-19 14:30:17 +01:00
Translate scoreboard nametag visibility (#1240)
This commit adds support for name tag visibility in teams. If a player is set to hide their nametag, it will be hidden from the Bedrock client. Notably, this fixes most NPC nametag hiding, including Citizens. This does not fix some NPC nametag hiding - there are several NPCs in Hypixel that still have a nametag show up, and they are not a part of any team.
Dieser Commit ist enthalten in:
Ursprung
b21f477366
Commit
4f761c5bde
@ -27,6 +27,7 @@ package org.geysermc.connector.entity;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility;
|
||||||
import com.github.steveice10.mc.protocol.data.message.TextMessage;
|
import com.github.steveice10.mc.protocol.data.message.TextMessage;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
@ -240,9 +241,20 @@ public class PlayerEntity extends LivingEntity {
|
|||||||
}
|
}
|
||||||
Team team = session.getWorldCache().getScoreboard().getTeamFor(username);
|
Team team = session.getWorldCache().getScoreboard().getTeamFor(username);
|
||||||
if (team != null) {
|
if (team != null) {
|
||||||
|
// Cover different visibility settings
|
||||||
|
if (team.getNameTagVisibility() == NameTagVisibility.NEVER) {
|
||||||
|
metadata.put(EntityData.NAMETAG, "");
|
||||||
|
} else if (team.getNameTagVisibility() == NameTagVisibility.HIDE_FOR_OTHER_TEAMS &&
|
||||||
|
!team.getEntities().contains(session.getPlayerEntity().getUsername())) {
|
||||||
|
metadata.put(EntityData.NAMETAG, "");
|
||||||
|
} else if (team.getNameTagVisibility() == NameTagVisibility.HIDE_FOR_OWN_TEAM &&
|
||||||
|
team.getEntities().contains(session.getPlayerEntity().getUsername())) {
|
||||||
|
metadata.put(EntityData.NAMETAG, "");
|
||||||
|
} else {
|
||||||
metadata.put(EntityData.NAMETAG, team.getPrefix() + MessageUtils.toChatColor(team.getColor()) + username + team.getSuffix());
|
metadata.put(EntityData.NAMETAG, team.getPrefix() + MessageUtils.toChatColor(team.getColor()) + username + team.getSuffix());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Extra hearts - is not metadata but an attribute on Bedrock
|
// Extra hearts - is not metadata but an attribute on Bedrock
|
||||||
if (entityMetadata.getId() == 14) {
|
if (entityMetadata.getId() == 14) {
|
||||||
|
@ -61,6 +61,7 @@ public class JavaTeamTranslator extends PacketTranslator<ServerTeamPacket> {
|
|||||||
scoreboard.registerNewTeam(packet.getTeamName(), toPlayerSet(packet.getPlayers()))
|
scoreboard.registerNewTeam(packet.getTeamName(), toPlayerSet(packet.getPlayers()))
|
||||||
.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
||||||
.setColor(packet.getColor())
|
.setColor(packet.getColor())
|
||||||
|
.setNameTagVisibility(packet.getNameTagVisibility())
|
||||||
.setPrefix(MessageUtils.getTranslatedBedrockMessage(packet.getPrefix(), session.getClientData().getLanguageCode()))
|
.setPrefix(MessageUtils.getTranslatedBedrockMessage(packet.getPrefix(), session.getClientData().getLanguageCode()))
|
||||||
.setSuffix(MessageUtils.getTranslatedBedrockMessage(packet.getSuffix(), session.getClientData().getLanguageCode()));
|
.setSuffix(MessageUtils.getTranslatedBedrockMessage(packet.getSuffix(), session.getClientData().getLanguageCode()));
|
||||||
break;
|
break;
|
||||||
@ -75,6 +76,7 @@ public class JavaTeamTranslator extends PacketTranslator<ServerTeamPacket> {
|
|||||||
|
|
||||||
team.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
team.setName(MessageUtils.getBedrockMessage(packet.getDisplayName()))
|
||||||
.setColor(packet.getColor())
|
.setColor(packet.getColor())
|
||||||
|
.setNameTagVisibility(packet.getNameTagVisibility())
|
||||||
.setPrefix(MessageUtils.getTranslatedBedrockMessage(packet.getPrefix(), session.getClientData().getLanguageCode()))
|
.setPrefix(MessageUtils.getTranslatedBedrockMessage(packet.getPrefix(), session.getClientData().getLanguageCode()))
|
||||||
.setSuffix(MessageUtils.getTranslatedBedrockMessage(packet.getSuffix(), session.getClientData().getLanguageCode()))
|
.setSuffix(MessageUtils.getTranslatedBedrockMessage(packet.getSuffix(), session.getClientData().getLanguageCode()))
|
||||||
.setUpdateType(UpdateType.UPDATE);
|
.setUpdateType(UpdateType.UPDATE);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.scoreboard;
|
package org.geysermc.connector.scoreboard;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility;
|
||||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
|
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -44,6 +45,7 @@ public class Team {
|
|||||||
private UpdateType updateType = UpdateType.ADD;
|
private UpdateType updateType = UpdateType.ADD;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
private NameTagVisibility nameTagVisibility;
|
||||||
private String prefix;
|
private String prefix;
|
||||||
private TeamColor color;
|
private TeamColor color;
|
||||||
private String suffix;
|
private String suffix;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren