From efedde7d97cd8a785628c2df65c63ab976a9ea9f Mon Sep 17 00:00:00 2001 From: gecko10000 Date: Sat, 27 Apr 2024 17:42:19 -0700 Subject: [PATCH 1/5] Add option to use world key instead of world name --- .../palmergames/bukkit/config/ConfigNodes.java | 8 +++++++- .../bukkit/towny/TownyFormatter.java | 17 ++++++++++------- .../palmergames/bukkit/towny/TownySettings.java | 7 +++++-- 3 files changed, 22 insertions(+), 10 deletions(-) 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..d89ff27dce 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,12 @@ 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." + ), PLUGIN_WEB_MAP_URL( "plugin.interfacing.web_map.url", @@ -3253,4 +3259,4 @@ public String[] getComments() { comments[0] = ""; return comments; } -} +} \ No newline at end of file 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..5974580eef 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java @@ -39,6 +39,7 @@ 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; @@ -1046,13 +1047,15 @@ public static String getTime() { 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("\\{x}", "" + spawnLocation.getSpawnOrNull().getBlockX()) - .replaceAll("\\{z}", "" + spawnLocation.getSpawnOrNull().getBlockZ()); - + if (TownySettings.isUsingWebMapStatusScreens() && spawnLocation.hasSpawn() && !TownySettings.getWebMapUrl().isEmpty()) { + World world = spawnLocation.getSpawnOrNull().getWorld(); + String worldName = TownySettings.isUsingWorldKeyForWorldName() ? world.getKey().toString() : world.getName(); + webUrl = TownySettings.getWebMapUrl() + .replaceAll("\\{world}", worldName) + .replaceAll("\\{x}", "" + spawnLocation.getSpawnOrNull().getBlockX()) + .replaceAll("\\{z}", "" + spawnLocation.getSpawnOrNull().getBlockZ()); + } return webUrl; } -} +} \ No newline at end of file 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..f1c38ce0be 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); } @@ -3780,5 +3784,4 @@ public static String getDefaultResidentAbout() { public static double maxBuyTownPrice() { return getDouble(ConfigNodes.GTOWN_SETTINGS_MAX_BUYTOWN_PRICE); } -} - +} \ No newline at end of file From 60e0920cfdcc7a08543e9e362967488f950c5806 Mon Sep 17 00:00:00 2001 From: gecko10000 Date: Sat, 27 Apr 2024 17:46:31 -0700 Subject: [PATCH 2/5] Re-add newlines at end of files --- .../main/java/com/palmergames/bukkit/config/ConfigNodes.java | 2 +- .../main/java/com/palmergames/bukkit/towny/TownyFormatter.java | 2 +- .../main/java/com/palmergames/bukkit/towny/TownySettings.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 d89ff27dce..662b311e74 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java +++ b/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java @@ -3259,4 +3259,4 @@ public String[] getComments() { comments[0] = ""; return comments; } -} \ No newline at end of file +} 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 5974580eef..abdd2483d8 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java @@ -1058,4 +1058,4 @@ private static String formatWebUrl(SpawnLocation spawnLocation) { return webUrl; } -} \ No newline at end of file +} 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 f1c38ce0be..4859dfd8eb 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java @@ -3784,4 +3784,4 @@ public static String getDefaultResidentAbout() { public static double maxBuyTownPrice() { return getDouble(ConfigNodes.GTOWN_SETTINGS_MAX_BUYTOWN_PRICE); } -} \ No newline at end of file +} From 418a40a6c216194c7eae16a6cc566501bb2e1d12 Mon Sep 17 00:00:00 2001 From: gecko10000 Date: Sat, 27 Apr 2024 17:48:46 -0700 Subject: [PATCH 3/5] Fix indentation of webUrl assignment --- .../java/com/palmergames/bukkit/towny/TownyFormatter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 abdd2483d8..a9f2e680c6 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java @@ -1050,10 +1050,10 @@ private static String formatWebUrl(SpawnLocation spawnLocation) { if (TownySettings.isUsingWebMapStatusScreens() && spawnLocation.hasSpawn() && !TownySettings.getWebMapUrl().isEmpty()) { World world = spawnLocation.getSpawnOrNull().getWorld(); String worldName = TownySettings.isUsingWorldKeyForWorldName() ? world.getKey().toString() : world.getName(); - webUrl = TownySettings.getWebMapUrl() - .replaceAll("\\{world}", worldName) - .replaceAll("\\{x}", "" + spawnLocation.getSpawnOrNull().getBlockX()) - .replaceAll("\\{z}", "" + spawnLocation.getSpawnOrNull().getBlockZ()); + webUrl = TownySettings.getWebMapUrl() + .replaceAll("\\{world}", worldName) + .replaceAll("\\{x}", "" + spawnLocation.getSpawnOrNull().getBlockX()) + .replaceAll("\\{z}", "" + spawnLocation.getSpawnOrNull().getBlockZ()); } return webUrl; } From f5e6daf7018272d8f12d25c4646249927871b021 Mon Sep 17 00:00:00 2001 From: gecko10000 <60494179+gecko10000@users.noreply.github.com> Date: Tue, 30 Apr 2024 01:01:08 -0700 Subject: [PATCH 4/5] Add >= 1.18.2 safeguard Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com> --- .../main/java/com/palmergames/bukkit/towny/TownyFormatter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 a9f2e680c6..7190e7dac0 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyFormatter.java @@ -1049,7 +1049,8 @@ private static String formatWebUrl(SpawnLocation spawnLocation) { String webUrl = ""; if (TownySettings.isUsingWebMapStatusScreens() && spawnLocation.hasSpawn() && !TownySettings.getWebMapUrl().isEmpty()) { World world = spawnLocation.getSpawnOrNull().getWorld(); - String worldName = TownySettings.isUsingWorldKeyForWorldName() ? world.getKey().toString() : world.getName(); + String worldName = TownySettings.isUsingWorldKeyForWorldName() && (PaperLib.isPaper() || MinecraftVersion.isNewerThanOrEquals(MinecraftVersion.1_18_2)) ? world.getKey().toString() : world.getName(); + webUrl = TownySettings.getWebMapUrl() .replaceAll("\\{world}", worldName) .replaceAll("\\{x}", "" + spawnLocation.getSpawnOrNull().getBlockX()) From 9a0e84f9929a8d417ba5d31a912d5b0f432e950d Mon Sep 17 00:00:00 2001 From: LlmDl Date: Tue, 30 Apr 2024 10:04:34 -0500 Subject: [PATCH 5/5] Fix build, imports and add missing MinecraftVersion. Extracts world slug to a method. --- .../palmergames/bukkit/config/ConfigNodes.java | 3 ++- .../bukkit/towny/TownyFormatter.java | 17 +++++++++++------ .../palmergames/bukkit/towny/TownySettings.java | 1 + .../bukkit/towny/utils/MinecraftVersion.java | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) 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 662b311e74..7299848890 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java +++ b/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java @@ -1532,7 +1532,8 @@ public enum ConfigNodes { "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." + "# 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( 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 7190e7dac0..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,6 +35,8 @@ 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; @@ -1047,16 +1050,18 @@ public static String getTime() { private static String formatWebUrl(SpawnLocation spawnLocation) { String webUrl = ""; - if (TownySettings.isUsingWebMapStatusScreens() && spawnLocation.hasSpawn() && !TownySettings.getWebMapUrl().isEmpty()) { - World world = spawnLocation.getSpawnOrNull().getWorld(); - String worldName = TownySettings.isUsingWorldKeyForWorldName() && (PaperLib.isPaper() || MinecraftVersion.isNewerThanOrEquals(MinecraftVersion.1_18_2)) ? world.getKey().toString() : world.getName(); - + if (TownySettings.isUsingWebMapStatusScreens() && spawnLocation.hasSpawn() && !TownySettings.getWebMapUrl().isEmpty()) webUrl = TownySettings.getWebMapUrl() - .replaceAll("\\{world}", worldName) + .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 4859dfd8eb..b97904d11e 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java @@ -3785,3 +3785,4 @@ public static double maxBuyTownPrice() { return getDouble(ConfigNodes.GTOWN_SETTINGS_MAX_BUYTOWN_PRICE); } } + 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");