Fix nameTagVisibility nullability

This commit is contained in:
Camotoy 2023-03-14 07:44:52 -04:00
parent 2436b2b1be
commit 720c901535
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 12 additions and 2 deletions

View file

@ -858,7 +858,6 @@ public final class EntityDefinitions {
{ {
EntityDefinition<AbstractHorseEntity> abstractHorseEntityBase = EntityDefinition.inherited(AbstractHorseEntity::new, ageableEntityBase) EntityDefinition<AbstractHorseEntity> abstractHorseEntityBase = EntityDefinition.inherited(AbstractHorseEntity::new, ageableEntityBase)
.addTranslator(MetadataType.BYTE, AbstractHorseEntity::setHorseFlags) .addTranslator(MetadataType.BYTE, AbstractHorseEntity::setHorseFlags)
.addTranslator(null) // UUID of owner
.build(); .build();
CAMEL = EntityDefinition.inherited(CamelEntity::new, abstractHorseEntityBase) CAMEL = EntityDefinition.inherited(CamelEntity::new, abstractHorseEntityBase)
.type(EntityType.CAMEL) .type(EntityType.CAMEL)

View file

@ -33,7 +33,9 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import javax.annotation.Nullable;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
@Getter @Getter
@ -44,7 +46,7 @@ public final class Team {
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private final Set<String> entities; private final Set<String> entities;
@Setter private NameTagVisibility nameTagVisibility; @Setter @Nullable private NameTagVisibility nameTagVisibility;
@Setter private TeamColor color; @Setter private TeamColor color;
private final TeamData currentData; private final TeamData currentData;
@ -187,6 +189,11 @@ public final class Team {
} }
public boolean isVisibleFor(String entity) { public boolean isVisibleFor(String entity) {
if (nameTagVisibility == null) {
// Null - normal behavior
return true;
}
return switch (nameTagVisibility) { return switch (nameTagVisibility) {
case HIDE_FOR_OTHER_TEAMS -> { case HIDE_FOR_OTHER_TEAMS -> {
// Player must be in a team in order for HIDE_FOR_OTHER_TEAMS to be triggered // Player must be in a team in order for HIDE_FOR_OTHER_TEAMS to be triggered
@ -199,6 +206,10 @@ public final class Team {
}; };
} }
public NameTagVisibility getNameTagVisibility() {
return Objects.requireNonNullElse(this.nameTagVisibility, NameTagVisibility.ALWAYS);
}
@Override @Override
public int hashCode() { public int hashCode() {
return id.hashCode(); return id.hashCode();