using common interface instead of individual methods in displayname appliance

This commit is contained in:
Elias Müller 2025-03-15 21:54:18 +01:00
parent ceca038b27
commit 49eeb646ea

View File

@ -19,6 +19,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
import java.util.logging.Level;
@ -30,21 +31,21 @@ public class DisplayName extends Appliance {
public void update(Player player) {
TextColor playerColor = this.queryAppliance(AdminMarker.class).getPlayerColor(player);
List<Supplier<Component>> prefixes = List.of(
() -> this.queryAppliance(Outlawed.class).getNamePrefix(player),
() -> this.queryAppliance(YearRank.class).getNamePrefix(player),
() -> this.queryAppliance(AfkTag.class).getNamePrefix(player),
() -> this.queryAppliance(SleepTag.class).getNamePrefix(player)
List<Supplier<Prefixed>> prefixes = List.of(
() -> this.queryAppliance(Outlawed.class),
() -> this.queryAppliance(YearRank.class),
() -> this.queryAppliance(AfkTag.class),
() -> this.queryAppliance(SleepTag.class)
);
ComponentBuilder<TextComponent, TextComponent.Builder> playerName = Component.text();
prefixes.forEach(supplier -> {
Component prefix = supplier.get();
if(prefix == null) return;
playerName
prefixes.stream()
.map(prefixed -> prefixed.get().getNamePrefix(player))
.filter(Objects::nonNull)
.forEach(prefix -> playerName
.append(prefix)
.append(ComponentUtil.clearedSpace());
});
.append(ComponentUtil.clearedSpace())
);
if(Floodgate.isBedrock(player)) {
playerName