Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


import de.bluecolored.bluemap.api.plugin.PlayerIconFactory;
import de.bluecolored.bluemap.api.plugin.PlayerDisplayNameProvider;
import de.bluecolored.bluemap.api.plugin.SkinProvider;
import de.bluecolored.bluemap.common.plugin.Plugin;
import lombok.NonNull;
Expand Down Expand Up @@ -58,6 +59,16 @@ public void setPlayerMarkerIconFactory(PlayerIconFactory playerMarkerIconFactory
plugin.getSkinUpdater().setPlayerMarkerIconFactory(playerMarkerIconFactory);
}

@Override
public PlayerDisplayNameProvider getPlayerDisplayNameProvider() {
return plugin.getPlayerDisplayNameProvider();
}

@Override
public void setPlayerDisplayNameProvider(PlayerDisplayNameProvider playerNameProvider) {
plugin.setPlayerDisplayNameProvider(playerNameProvider);
}

public Plugin getPlugin() {
return plugin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.google.gson.stream.JsonWriter;
import de.bluecolored.bluemap.common.config.PluginConfig;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.serverinterface.Player;
import de.bluecolored.bluemap.common.serverinterface.Server;
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
Expand All @@ -41,14 +42,16 @@

public class LivePlayersDataSupplier implements Supplier<String> {

private final Plugin plugin;
private final Server server;
private final PluginConfig config;
private final World world;
private final Predicate<UUID> playerFilter;

private transient @Nullable ServerWorld serverWorld;

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;
this.server = server;
this.config = config;
this.world = world;
Expand Down Expand Up @@ -83,7 +86,7 @@ public String get() {

json.beginObject();
json.name("uuid").value(player.getUuid().toString());
json.name("name").value(player.getName().toPlainString());
json.name("name").value(this.plugin.getPlayerDisplayNameProvider().get(player.getUuid()));
json.name("foreign").value(!isCorrectWorld);

json.name("position").beginObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package de.bluecolored.bluemap.common.plugin;

import de.bluecolored.bluemap.api.plugin.PlayerDisplayNameProvider;
import de.bluecolored.bluemap.common.BlueMapConfiguration;
import de.bluecolored.bluemap.common.BlueMapService;
import de.bluecolored.bluemap.common.InterruptableReentrantLock;
Expand Down Expand Up @@ -101,6 +102,7 @@ public class Plugin implements ServerEventListener {
private Timer daemonTimer;
private Map<String, MapUpdateService> mapUpdateServices;
private PlayerSkinUpdater skinUpdater;
private PlayerDisplayNameProvider playerDisplayNameProvider;

private boolean loaded = false;

Expand Down Expand Up @@ -206,7 +208,7 @@ private void load(@Nullable ResourcePack preloadedResourcePack) throws IOExcepti
MapRequestHandler mapRequestHandler;
BmMap map = maps.get(id);
if (map != null) {
mapRequestHandler = new MapRequestHandler(map, serverInterface, pluginConfig, Predicate.not(pluginState::isPlayerHidden));
mapRequestHandler = new MapRequestHandler(this, map, serverInterface, pluginConfig, Predicate.not(pluginState::isPlayerHidden));
} else {
Storage storage = blueMap.getOrLoadStorage(mapConfig.getStorage());
mapRequestHandler = new MapRequestHandler(storage.map(id));
Expand Down Expand Up @@ -279,6 +281,8 @@ private void load(@Nullable ResourcePack preloadedResourcePack) throws IOExcepti
serverInterface.registerListener(skinUpdater);
}

this.playerDisplayNameProvider = new ServerPlayerDisplayNameProvider(this.serverInterface);

//init timer
daemonTimer = new Timer("BlueMap-Plugin-DaemonTimer", true);

Expand Down Expand Up @@ -549,6 +553,7 @@ public void savePlayerStates() {
var maps = blueMap.getMaps();
for (BmMap map : maps.values()) {
var dataSupplier = new LivePlayersDataSupplier(
this,
serverInterface,
getBlueMap().getConfig().getPluginConfig(),
map.getWorld(),
Expand Down Expand Up @@ -657,4 +662,7 @@ public boolean isLoading() {
return loadingLock.isLocked();
}

public void setPlayerDisplayNameProvider(PlayerDisplayNameProvider playerDisplayNameProvider) {
this.playerDisplayNameProvider = Objects.requireNonNull(playerDisplayNameProvider, "playerDisplayNameProvider can not be null");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.common.plugin;

import de.bluecolored.bluemap.api.plugin.PlayerDisplayNameProvider;
import de.bluecolored.bluemap.common.serverinterface.Player;
import de.bluecolored.bluemap.common.serverinterface.Server;

import java.util.UUID;

public class ServerPlayerDisplayNameProvider implements PlayerDisplayNameProvider {
private final Server server;

public ServerPlayerDisplayNameProvider(Server server) {
this.server = server;
}

@Override
public String get(UUID playerUUID) {
// 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()) {
if (onlinePlayer.getUuid().equals(playerUUID)) {
return onlinePlayer.getName().toPlainString();
}
}

return playerUUID.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import de.bluecolored.bluemap.common.config.PluginConfig;
import de.bluecolored.bluemap.common.live.LiveMarkersDataSupplier;
import de.bluecolored.bluemap.common.live.LivePlayersDataSupplier;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.serverinterface.Server;
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
import de.bluecolored.bluemap.core.map.BmMap;
Expand All @@ -40,9 +41,9 @@

public class MapRequestHandler extends RoutingRequestHandler {

public MapRequestHandler(BmMap map, Server serverInterface, PluginConfig pluginConfig, Predicate<UUID> playerFilter) {
public MapRequestHandler(Plugin plugin, BmMap map, Server serverInterface, PluginConfig pluginConfig, Predicate<UUID> playerFilter) {
this(map.getStorage(),
new LivePlayersDataSupplier(serverInterface, pluginConfig, map.getWorld(), playerFilter),
new LivePlayersDataSupplier(plugin, serverInterface, pluginConfig, map.getWorld(), playerFilter),
new LiveMarkersDataSupplier(map.getMarkerSets()));
}

Expand Down
Loading