Skip to content

Implement default PlayerDisplayNameProvider API#803

Draft
TechnicJelle wants to merge 1 commit into
BlueMap-Minecraft:masterfrom
TechnicJelle:master
Draft

Implement default PlayerDisplayNameProvider API#803
TechnicJelle wants to merge 1 commit into
BlueMap-Minecraft:masterfrom
TechnicJelle:master

Conversation

@TechnicJelle
Copy link
Copy Markdown
Member

@TechnicJelle TechnicJelle commented May 12, 2026

Implemented a default for the API added in BlueMap-Minecraft/BlueMapAPI#9

I'm not all too happy about it all yet, especially the locations of some things and what I had to pass into other places.
Also, the default implementation currently kind of sucks.

I'd be happy to get feedback on this!

Screenshots of this working image image image
Addon plugin code
package com.TechnicJelle.blueMapCustomPlayerNames;

import de.bluecolored.bluemap.api.BlueMapAPI;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.function.Consumer;

public final class BlueMapCustomPlayerNames extends JavaPlugin {

    @Override
    public void onEnable() {
        BlueMapAPI.onEnable(bluemapOnEnable);
    }

    Consumer<BlueMapAPI> bluemapOnEnable = (BlueMapAPI api) -> {
        api.getPlugin().setPlayerNameProvider(playerUUID -> {
            Player player = getServer().getPlayer(playerUUID);
            if (player == null) return playerUUID.toString();

            Component displayName = player.displayName();
            if (displayName instanceof TextComponent textComponent)
                return "<span style=\"color: blue;\">" + textComponent.content() + "</span>";

            return playerUUID.toString();
        });
    };
}

Comment on lines +42 to +45
// TODO: I am not happy with needing to do this here.
// The place that calls this function already loops over the online players, so this loops double!
// I can't really think of a better way to do this right now, though.
for (Player onlinePlayer : this.server.getOnlinePlayers()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be fine with changing the Server#getOnlinePLayer() method into a Map<UUID, Player> .. this would then also need to be implemented in all implementations though ofc..

Comment on lines -51 to +54
public LivePlayersDataSupplier(Server server, PluginConfig config, World world, Predicate<UUID> playerFilter) {
public LivePlayersDataSupplier(Plugin plugin, Server server, PluginConfig config, World world, Predicate<UUID> playerFilter) {
this.plugin = plugin;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already don't like passing the PluginConfig here, now also passing the Plugin screams that this needs to be refactored somehow that this is not needed.
For now, passing the PlayerDisplayNameProvider directly would be the most passable i think ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants