From 20c3a6ba1bb16026c35da71e248f8bc5a46a097a Mon Sep 17 00:00:00 2001 From: HydrolienF Date: Tue, 17 Feb 2026 14:51:56 +0100 Subject: [PATCH] Add a global player visibility that can override player choice. It's map.player-visibility and it can be set to "FORCED_HIDDEN", "FORCED_SHOWN", "PLAYER_SETTING". Player can still do `/map hide` or `/map show`, but if the player visibility is set to FORCED_HIDDEN, no player will be visible or if it is set to FORCED_SHOWN, all player will be visible. It does not make spectator or NPC visible, it only affect player that would be visible if `/map show` was executed. --- .gitignore | 1 + .../jpenilla/squaremap/common/config/PlayerVisibility.java | 5 +++++ .../xyz/jpenilla/squaremap/common/config/WorldConfig.java | 4 ++++ .../xyz/jpenilla/squaremap/common/task/UpdatePlayers.java | 6 +++++- 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/xyz/jpenilla/squaremap/common/config/PlayerVisibility.java diff --git a/.gitignore b/.gitignore index 84932c9a..13b38826 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ out/ .settings/ plugin/bin/ api/bin/ +.eclipse/ # Compiled class file *.class diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/config/PlayerVisibility.java b/common/src/main/java/xyz/jpenilla/squaremap/common/config/PlayerVisibility.java new file mode 100644 index 00000000..65b88089 --- /dev/null +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/config/PlayerVisibility.java @@ -0,0 +1,5 @@ +package xyz.jpenilla.squaremap.common.config; + +public enum PlayerVisibility { + FORCED_HIDDEN, FORCED_SHOWN, PLAYER_SETTING +} diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldConfig.java b/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldConfig.java index 7f10228b..53dc2400 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldConfig.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldConfig.java @@ -20,6 +20,7 @@ public final class WorldConfig extends AbstractWorldConfig { public int MAX_RENDER_THREADS = -1; public boolean MAP_ITERATE_UP = false; public int MAP_MAX_HEIGHT = -1; + public PlayerVisibility MAP_PLAYER_VISIBILITY = PlayerVisibility.PLAYER_SETTING; private void worldSettings() { this.MAP_ENABLED = this.getBoolean("map.enabled", this.MAP_ENABLED); @@ -29,6 +30,9 @@ private void worldSettings() { this.MAX_RENDER_THREADS = this.getInt("map.max-render-threads", this.MAX_RENDER_THREADS); this.MAP_ITERATE_UP = this.getBoolean("map.iterate-up", this.MAP_ITERATE_UP); this.MAP_MAX_HEIGHT = this.getInt("map.max-height", this.MAP_MAX_HEIGHT); + try { + this.MAP_PLAYER_VISIBILITY = PlayerVisibility.valueOf(this.getString("map.player-visibility", this.MAP_PLAYER_VISIBILITY.name())); + } catch (IllegalArgumentException ignored) {} } public boolean MAP_BIOMES = true; diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/task/UpdatePlayers.java b/common/src/main/java/xyz/jpenilla/squaremap/common/task/UpdatePlayers.java index d29e1102..90904b0e 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/task/UpdatePlayers.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/task/UpdatePlayers.java @@ -24,6 +24,7 @@ import xyz.jpenilla.squaremap.common.AbstractPlayerManager; import xyz.jpenilla.squaremap.common.ServerAccess; import xyz.jpenilla.squaremap.common.config.ConfigManager; +import xyz.jpenilla.squaremap.common.config.PlayerVisibility; import xyz.jpenilla.squaremap.common.config.WorldConfig; import xyz.jpenilla.squaremap.common.httpd.JsonCache; import xyz.jpenilla.squaremap.common.util.Util; @@ -86,7 +87,10 @@ private Map collectData() { if (worldConfig.PLAYER_TRACKER_HIDE_MAP_INVISIBILITY_EQUIPMENT && hasMapInvisibilityItemEquipped(player)) { return; } - if (this.playerManager.hidden(player) || this.playerManager.otherwiseHidden(player)) { + if (worldConfig.MAP_PLAYER_VISIBILITY == PlayerVisibility.FORCED_HIDDEN) { + return; + } + if ((worldConfig.MAP_PLAYER_VISIBILITY == PlayerVisibility.PLAYER_SETTING && this.playerManager.hidden(player)) || this.playerManager.otherwiseHidden(player)) { return; } final Map playerEntry = new HashMap<>();