diff --git a/src/main/java/com/technicjelle/bluemapofflineplayermarkers/common/Config.java b/src/main/java/com/technicjelle/bluemapofflineplayermarkers/common/Config.java index ac5cacd..b56cd0a 100644 --- a/src/main/java/com/technicjelle/bluemapofflineplayermarkers/common/Config.java +++ b/src/main/java/com/technicjelle/bluemapofflineplayermarkers/common/Config.java @@ -29,6 +29,8 @@ default boolean isGameModeHidden(GameMode gameMode) { return getHiddenGameModes().contains(gameMode); } + boolean hideBannedPlayers(); + /** * @param playerUUID The player to check. * @return true if the player should be hidden diff --git a/src/main/java/com/technicjelle/bluemapofflineplayermarkers/common/Server.java b/src/main/java/com/technicjelle/bluemapofflineplayermarkers/common/Server.java index 46a761f..fdca7c6 100644 --- a/src/main/java/com/technicjelle/bluemapofflineplayermarkers/common/Server.java +++ b/src/main/java/com/technicjelle/bluemapofflineplayermarkers/common/Server.java @@ -6,7 +6,12 @@ import com.google.gson.reflect.TypeToken; import com.technicjelle.bluemapofflineplayermarkers.core.Singletons; -import java.io.*; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Writer; import java.net.URL; import java.net.URLConnection; import java.nio.file.Path; @@ -88,4 +93,6 @@ static String nameFromMojangAPI(UUID playerUUID) throws IOException { } Optional guessWorldUUID(Object object); + + boolean isPlayerBanned(UUID playerUUID); } diff --git a/src/main/java/com/technicjelle/bluemapofflineplayermarkers/core/markerhandler/BlueMapMarkerHandler.java b/src/main/java/com/technicjelle/bluemapofflineplayermarkers/core/markerhandler/BlueMapMarkerHandler.java index 5850fcf..6a7caad 100644 --- a/src/main/java/com/technicjelle/bluemapofflineplayermarkers/core/markerhandler/BlueMapMarkerHandler.java +++ b/src/main/java/com/technicjelle/bluemapofflineplayermarkers/core/markerhandler/BlueMapMarkerHandler.java @@ -3,6 +3,7 @@ import com.flowpowered.math.vector.Vector3d; import com.technicjelle.BMUtils; import com.technicjelle.bluemapofflineplayermarkers.common.Config; +import com.technicjelle.bluemapofflineplayermarkers.common.Server; import com.technicjelle.bluemapofflineplayermarkers.core.Player; import com.technicjelle.bluemapofflineplayermarkers.core.Singletons; import de.bluecolored.bluemap.api.BlueMapAPI; @@ -20,8 +21,13 @@ public void add(Player player, BlueMapAPI api) { //If this player's visibility is disabled on the map, don't add the marker. if (!api.getWebApp().getPlayerVisibility(player.getPlayerUUID())) return; + Config config = Singletons.getConfig(); //If this player's game mode is disabled on the map, don't add the marker. - if (Singletons.getConfig().isGameModeHidden(player.getPlayerData().getGameMode())) return; + if (config.isGameModeHidden(player.getPlayerData().getGameMode())) return; + + Server server = Singletons.getServer(); + //If this player is banned and the config is set to hide banned players, don't add the marker. + if (config.hideBannedPlayers() && server.isPlayerBanned(player.getPlayerUUID())) return; // Get BlueMapWorld for the position Optional worldUUID = player.getPlayerData().getWorldUUID(); @@ -50,9 +56,9 @@ public void add(Player player, BlueMapAPI api) { // get marker-set (or create new marker set if none found) MarkerSet markerSet = map.getMarkerSets().computeIfAbsent(Config.MARKER_SET_ID, id -> MarkerSet.builder() - .label(Singletons.getConfig().getMarkerSetName()) - .toggleable(Singletons.getConfig().isToggleable()) - .defaultHidden(Singletons.getConfig().isDefaultHidden()) + .label(config.getMarkerSetName()) + .toggleable(config.isToggleable()) + .defaultHidden(config.isDefaultHidden()) .build()); // add marker diff --git a/src/main/java/com/technicjelle/bluemapofflineplayermarkers/impl/paper/PaperConfig.java b/src/main/java/com/technicjelle/bluemapofflineplayermarkers/impl/paper/PaperConfig.java index 7c20ca5..98266c6 100644 --- a/src/main/java/com/technicjelle/bluemapofflineplayermarkers/impl/paper/PaperConfig.java +++ b/src/main/java/com/technicjelle/bluemapofflineplayermarkers/impl/paper/PaperConfig.java @@ -15,6 +15,7 @@ public class PaperConfig implements Config { private boolean defaultHidden; private long expireTimeInHours; private List hiddenGameModes; + private boolean hideBannedPlayers; public PaperConfig(JavaPlugin plugin) { loadFromPlugin(plugin); @@ -36,6 +37,7 @@ public void loadFromPlugin(JavaPlugin plugin) { defaultHidden = plugin.getConfig().getBoolean("DefaultHidden", false); expireTimeInHours = plugin.getConfig().getLong("ExpireTimeInHours", 0); hiddenGameModes = Config.parseGameModes(getStringList(plugin, "HiddenGameModes", List.of("spectator"))); + hideBannedPlayers = plugin.getConfig().getBoolean("HideBannedPlayers", true); } //Copied/Adapted from org.bukkit.configuration.MemorySection.java @@ -90,4 +92,9 @@ public long getExpireTimeInHours() { public List getHiddenGameModes() { return hiddenGameModes; } + + @Override + public boolean hideBannedPlayers() { + return hideBannedPlayers; + } } diff --git a/src/main/java/com/technicjelle/bluemapofflineplayermarkers/impl/paper/PaperServer.java b/src/main/java/com/technicjelle/bluemapofflineplayermarkers/impl/paper/PaperServer.java index c26c906..62644a3 100644 --- a/src/main/java/com/technicjelle/bluemapofflineplayermarkers/impl/paper/PaperServer.java +++ b/src/main/java/com/technicjelle/bluemapofflineplayermarkers/impl/paper/PaperServer.java @@ -103,4 +103,10 @@ public Optional guessWorldUUID(Object object) { return Optional.empty(); } + + @Override + public boolean isPlayerBanned(UUID playerUUID) { + OfflinePlayer op = server.getOfflinePlayer(playerUUID); + return op.isBanned(); + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 5aafc92..197c43f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -13,3 +13,6 @@ ExpireTimeInHours: 0 # If you want to hide players in certain game modes, add them here. HiddenGameModes: - spectator + +# If you want to show players who are banned, set this to false. +HideBannedPlayers: true diff --git a/src/test/java/mockery/MockConfig.java b/src/test/java/mockery/MockConfig.java index 3d48abe..51e894d 100644 --- a/src/test/java/mockery/MockConfig.java +++ b/src/test/java/mockery/MockConfig.java @@ -30,4 +30,9 @@ public long getExpireTimeInHours() { public List getHiddenGameModes() { return List.of(); } + + @Override + public boolean hideBannedPlayers() { + return false; + } } diff --git a/src/test/java/mockery/MockMarkerHandler.java b/src/test/java/mockery/MockMarkerHandler.java index 58dbf62..84524e0 100644 --- a/src/test/java/mockery/MockMarkerHandler.java +++ b/src/test/java/mockery/MockMarkerHandler.java @@ -16,6 +16,7 @@ public void add(Player player, BlueMapAPI __) { Singletons.getLogger().finer("Last Played: " + player.getLastPlayed().toEpochMilli()); Singletons.getLogger().finer("GameMode: " + player.getPlayerData().getGameMode()); Singletons.getLogger().finer("Position: " + player.getPlayerData().getPosition()); + Singletons.getLogger().finer("Banned: " + Singletons.getServer().isPlayerBanned(player.getPlayerUUID())); Optional worldUUID = player.getPlayerData().getWorldUUID(); if (worldUUID.isEmpty()) diff --git a/src/test/java/mockery/MockServer.java b/src/test/java/mockery/MockServer.java index 82acc3a..c680d99 100644 --- a/src/test/java/mockery/MockServer.java +++ b/src/test/java/mockery/MockServer.java @@ -52,4 +52,9 @@ public String getPlayerName(UUID playerUUID) { public Optional guessWorldUUID(Object object) { return Optional.empty(); } + + @Override + public boolean isPlayerBanned(UUID playerUUID) { + return false; + } }