diff --git a/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java b/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java index ac94146ec8..7299848890 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java +++ b/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java @@ -1528,6 +1528,13 @@ public enum ConfigNodes { "", "# If enabled, players will be prompted to open a url when clicking on coordinates in towny status screens." ), + PLUGIN_WEB_MAP_WORLD_NAME_USES_KEY( + "plugin.interfacing.web_map.world_name_uses_world_key", + "false", + "", + "# If enabled, the world name placeholder will be replaced with the world key instead of the Bukkit name.", + "# This should be enabled if you use SquareMap." + ), PLUGIN_WEB_MAP_URL( "plugin.interfacing.web_map.url", diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java index 33d5cda865..abeb8cab9a 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java @@ -24,6 +24,7 @@ import com.palmergames.bukkit.towny.object.statusscreens.StatusScreen; import com.palmergames.bukkit.towny.permissions.TownyPerms; import com.palmergames.bukkit.towny.utils.CombatUtil; +import com.palmergames.bukkit.towny.utils.MinecraftVersion; import com.palmergames.bukkit.towny.utils.MoneyUtil; import com.palmergames.bukkit.towny.utils.NationUtil; import com.palmergames.bukkit.towny.utils.OutpostUtil; @@ -34,11 +35,14 @@ import com.palmergames.bukkit.util.ChatTools; import com.palmergames.bukkit.util.Colors; import com.palmergames.util.StringMgmt; + +import io.papermc.lib.PaperLib; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; @@ -1048,11 +1052,16 @@ private static String formatWebUrl(SpawnLocation spawnLocation) { String webUrl = ""; if (TownySettings.isUsingWebMapStatusScreens() && spawnLocation.hasSpawn() && !TownySettings.getWebMapUrl().isEmpty()) webUrl = TownySettings.getWebMapUrl() - .replaceAll("\\{world}", spawnLocation.getSpawnOrNull().getWorld().getName()) + .replaceAll("\\{world}", getWorldSlugForMapURL(spawnLocation.getSpawnOrNull().getWorld())) .replaceAll("\\{x}", "" + spawnLocation.getSpawnOrNull().getBlockX()) .replaceAll("\\{z}", "" + spawnLocation.getSpawnOrNull().getBlockZ()); return webUrl; } + private static String getWorldSlugForMapURL(World world) { + return TownySettings.isUsingWorldKeyForWorldName() && (PaperLib.isPaper() || MinecraftVersion.CURRENT_VERSION.isNewerThanOrEquals(MinecraftVersion.MINECRAFT_1_18_2)) + ? world.getKey().toString() + : world.getName(); + } } diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java b/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java index c328cbd10d..b97904d11e 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java @@ -3608,6 +3608,10 @@ public static boolean isUsingWebMapStatusScreens() { return getBoolean(ConfigNodes.PLUGIN_WEB_MAP_USING_STATUSSCREEN); } + public static boolean isUsingWorldKeyForWorldName() { + return getBoolean(ConfigNodes.PLUGIN_WEB_MAP_WORLD_NAME_USES_KEY); + } + public static String getWebMapUrl() { return getString(ConfigNodes.PLUGIN_WEB_MAP_URL); } diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/utils/MinecraftVersion.java b/Towny/src/main/java/com/palmergames/bukkit/towny/utils/MinecraftVersion.java index 863ccca57c..0039f39b81 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/utils/MinecraftVersion.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/utils/MinecraftVersion.java @@ -8,6 +8,7 @@ private MinecraftVersion() {} public static final Version MINECRAFT_1_16 = Version.fromString("1.16"); public static final Version MINECRAFT_1_17 = Version.fromString("1.17"); + public static final Version MINECRAFT_1_18_2 = Version.fromString("1.18.2"); public static final Version MINECRAFT_1_19_1 = Version.fromString("1.19.1"); public static final Version MINECRAFT_1_19_3 = Version.fromString("1.19.3"); public static final Version MINECRAFT_1_20 = Version.fromString("1.20");