Skip to content

Commit

Permalink
Hide banned players + config to show them anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed Mar 18, 2024
1 parent 0ae78d4 commit 6a240d8
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,4 +93,6 @@ static String nameFromMojangAPI(UUID playerUUID) throws IOException {
}

Optional<UUID> guessWorldUUID(Object object);

boolean isPlayerBanned(UUID playerUUID);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<UUID> worldUUID = player.getPlayerData().getWorldUUID();
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class PaperConfig implements Config {
private boolean defaultHidden;
private long expireTimeInHours;
private List<GameMode> hiddenGameModes;
private boolean hideBannedPlayers;

public PaperConfig(JavaPlugin plugin) {
loadFromPlugin(plugin);
Expand All @@ -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
Expand Down Expand Up @@ -90,4 +92,9 @@ public long getExpireTimeInHours() {
public List<GameMode> getHiddenGameModes() {
return hiddenGameModes;
}

@Override
public boolean hideBannedPlayers() {
return hideBannedPlayers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ public Optional<UUID> guessWorldUUID(Object object) {

return Optional.empty();
}

@Override
public boolean isPlayerBanned(UUID playerUUID) {
OfflinePlayer op = server.getOfflinePlayer(playerUUID);
return op.isBanned();
}
}
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/test/java/mockery/MockConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public long getExpireTimeInHours() {
public List<GameMode> getHiddenGameModes() {
return List.of();
}

@Override
public boolean hideBannedPlayers() {
return false;
}
}
1 change: 1 addition & 0 deletions src/test/java/mockery/MockMarkerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID> worldUUID = player.getPlayerData().getWorldUUID();
if (worldUUID.isEmpty())
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/mockery/MockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public String getPlayerName(UUID playerUUID) {
public Optional<UUID> guessWorldUUID(Object object) {
return Optional.empty();
}

@Override
public boolean isPlayerBanned(UUID playerUUID) {
return false;
}
}

0 comments on commit 6a240d8

Please sign in to comment.