Skip to content

Commit d58786d

Browse files
committed
Added HiddenGameModes feature
Closes #14
1 parent 9c7c968 commit d58786d

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and ask your questions in [#3rd-party-support](https://discord.com/channels/6658
3131
[elsing](https://github.com/elsing), [LOOHP](https://github.com/LOOHP)
3232
and [Blue](https://github.com/TBlueF) for their contributions to the project!
3333

34-
[pop4959](https://github.com/pop4959/BlueMap-Essentials) and [JotaFaD](https://github.com/JotaFaD/CivsExtras) for their
34+
[pop4959](https://github.com/pop4959/BlueMap-Essentials), [JotaFaD](https://github.com/JotaFaD/CivsExtras)
35+
and [YouHaveTrouble](https://github.com/YouHaveTrouble/ServerBasics/blob/a61de3f4964df8764ca15b3562a3c9227f0459ea/src/main/java/me/youhavetrouble/serverbasics/NMSHandler.java#L63) for their
3536
open-source plugins that gave me great examples to learn from.\
3637
And [TBlueF](https://github.com/TBlueF) of course for his amazing plugin and fast support with my silly questions!

src/main/java/com/technicjelle/bluemapofflineplayermarkers/Config.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.technicjelle.bluemapofflineplayermarkers;
22

3+
import org.bukkit.GameMode;
34
import org.bukkit.configuration.file.FileConfiguration;
45
import org.jetbrains.annotations.NotNull;
56

67
import java.io.File;
78
import java.io.IOException;
89
import java.nio.file.Files;
10+
import java.util.ArrayList;
11+
import java.util.List;
912
import java.util.Objects;
1013

1114
import static com.technicjelle.bluemapofflineplayermarkers.Main.logger;
@@ -25,6 +28,7 @@ private FileConfiguration configFile() {
2528
public boolean toggleable;
2629
public boolean defaultHidden;
2730
public long expireTimeInHours;
31+
public List<GameMode> hiddenGameModes;
2832

2933
public Config(Main plugin) {
3034
this.plugin = plugin;
@@ -48,5 +52,18 @@ public Config(Main plugin) {
4852
toggleable = configFile().getBoolean("Toggleable");
4953
defaultHidden = configFile().getBoolean("DefaultHidden");
5054
expireTimeInHours = configFile().getLong("ExpireTimeInHours");
55+
hiddenGameModes = parseGameModes(configFile().getStringList("HiddenGameModes"));
56+
}
57+
58+
private List<GameMode> parseGameModes(List<String> hiddenGameModesStrings) {
59+
ArrayList<GameMode> gameModes = new ArrayList<>();
60+
for (String gm : hiddenGameModesStrings) {
61+
try {
62+
gameModes.add(GameMode.valueOf(gm.toUpperCase()));
63+
} catch (IllegalArgumentException e) {
64+
logger.warning("Invalid Game Mode: " + gm);
65+
}
66+
}
67+
return gameModes;
5168
}
5269
}

src/main/java/com/technicjelle/bluemapofflineplayermarkers/MarkerHandler.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import de.bluecolored.bluemap.api.markers.MarkerSet;
1111
import de.bluecolored.bluemap.api.markers.POIMarker;
1212
import org.bukkit.Bukkit;
13+
import org.bukkit.GameMode;
1314
import org.bukkit.Location;
1415
import org.bukkit.OfflinePlayer;
1516
import org.bukkit.World;
@@ -36,16 +37,17 @@ public class MarkerHandler {
3637
* @param player The player to add the marker for.
3738
*/
3839
public static void add(Player player) {
39-
add(player, player.getLocation());
40+
add(player, player.getLocation(), player.getGameMode());
4041
}
4142

4243
/**
4344
* Adds a player marker to the map.
4445
*
4546
* @param player The player to add the marker for.
4647
* @param location The location to put the marker at.
48+
* @param gameMode The game mode of the player.
4749
*/
48-
public static void add(OfflinePlayer player, Location location) {
50+
public static void add(OfflinePlayer player, Location location, GameMode gameMode) {
4951
Optional<BlueMapAPI> optionalApi = BlueMapAPI.getInstance();
5052
if (optionalApi.isEmpty()) {
5153
logger.warning("Tried to add a marker, but BlueMap wasn't loaded!");
@@ -56,6 +58,9 @@ public static void add(OfflinePlayer player, Location location) {
5658
//If this player's visibility is disabled on the map, don't add the marker.
5759
if (!api.getWebApp().getPlayerVisibility(player.getUniqueId())) return;
5860

61+
//If this player's game mode is disabled on the map, don't add the marker.
62+
if (config.hiddenGameModes.contains(gameMode)) return;
63+
5964
// Get BlueMapWorld for the location
6065
BlueMapWorld blueMapWorld = api.getWorld(location.getWorld()).orElse(null);
6166
if (blueMapWorld == null) return;
@@ -162,6 +167,7 @@ public static void loadOfflineMarkers() {
162167
}
163168

164169
//Collect data
170+
int gameModeInt = (int) nbtData.get("playerGameType").getValue();
165171
long worldUUIDLeast = (long) nbtData.get("WorldUUIDLeast").getValue();
166172
long worldUUIDMost = (long) nbtData.get("WorldUUIDMost").getValue();
167173
@SuppressWarnings("unchecked") //Apparently this is just how it should be https://discord.com/channels/665868367416131594/771451216499965953/917450319259115550
@@ -174,8 +180,12 @@ public static void loadOfflineMarkers() {
174180
if (w == null || position.size() != 3) continue;
175181
Location loc = new Location(w, position.get(0), position.get(1), position.get(2));
176182

183+
//Convert to game mode
184+
@SuppressWarnings("deprecation")
185+
GameMode gameMode = GameMode.getByValue(gameModeInt);
186+
177187
//Add marker
178-
add(op, loc);
188+
add(op, loc, gameMode);
179189
}
180190
}
181191
}

src/main/resources/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ DefaultHidden: false
99
# If you want to show all players, set this to 0.
1010
# Feel free to use a calculator to convert days to hours: https://www.google.com/search?q=days+to+hours+calculator
1111
ExpireTimeInHours: 0
12+
13+
# If you want to hide players in certain game modes, add them here.
14+
HiddenGameModes:
15+
- spectator

0 commit comments

Comments
 (0)