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 d15b749980c..ea9e61a6d16 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java @@ -1927,25 +1927,41 @@ public static long getNewHourTime() { } public static SpawnLevel isAllowingTownSpawn() { - return getSpawnLevel(ConfigNodes.SPAWNING_ALLOW_TOWN_SPAWN); } public static SpawnLevel isAllowingPublicTownSpawnTravel() { - return getSpawnLevel(ConfigNodes.SPAWNING_ALLOW_TOWN_SPAWN_TRAVEL); } - public static boolean isConfigAllowingPublicTownSpawnTravel() { + public static boolean isConfigAllowingTownSpawn() { + return getBoolean(ConfigNodes.SPAWNING_ALLOW_TOWN_SPAWN); + } + public static boolean isConfigAllowingPublicTownSpawnTravel() { return getBoolean(ConfigNodes.SPAWNING_ALLOW_TOWN_SPAWN_TRAVEL); } - - public static boolean isConfigAllowingPublicNationSpawnTravel() { + public static boolean isConfigAllowingTownSpawnNationTravel() { + return getBoolean(ConfigNodes.SPAWNING_ALLOW_TOWN_SPAWN_TRAVEL_NATION); + } + + public static boolean isConfigAllowingTownSpawnNationAllyTravel() { + return getBoolean(ConfigNodes.SPAWNING_ALLOW_TOWN_SPAWN_TRAVEL_ALLY); + } + + public static boolean isConfigAllowingNationSpawn() { + return getBoolean(ConfigNodes.SPAWNING_ALLOW_NATION_SPAWN); + } + + public static boolean isConfigAllowingPublicNationSpawnTravel() { return getBoolean(ConfigNodes.SPAWNING_ALLOW_NATION_SPAWN_TRAVEL); } + public static boolean isConfigAllowingNationSpawnAllyTravel() { + return getBoolean(ConfigNodes.SPAWNING_ALLOW_NATION_SPAWN_TRAVEL_ALLY); + } + public static List getDisallowedTownSpawnZones() { return getStrArr(ConfigNodes.SPAWNING_PREVENT_TOWN_SPAWN_IN); } diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/command/TownCommand.java b/Towny/src/main/java/com/palmergames/bukkit/towny/command/TownCommand.java index 3c362b25366..602d59ec7e8 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/command/TownCommand.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/command/TownCommand.java @@ -1200,20 +1200,25 @@ public void listTowns(CommandSender sender, String[] split) throws TownyExceptio List> output = new ArrayList<>(); List towns = new ArrayList<>(TownyUniverse.getInstance().getTowns()); Collections.shuffle(towns); - + + boolean spawningFullyDisabled = !TownySettings.isConfigAllowingTownSpawn() && !TownySettings.isConfigAllowingPublicTownSpawnTravel() + && !TownySettings.isConfigAllowingTownSpawnNationTravel() && !TownySettings.isConfigAllowingTownSpawnNationAllyTravel(); + for (Town town : towns) { - TextComponent townName = Component.text(StringMgmt.remUnderscore(town.getName()), NamedTextColor.AQUA) - .clickEvent(ClickEvent.runCommand("/towny:town spawn " + town + " -ignore")); + TextComponent townName = Component.text(StringMgmt.remUnderscore(town.getName()), NamedTextColor.AQUA); townName = townName.append(Component.text(" - ", NamedTextColor.DARK_GRAY).append(Component.text("(" + town.getResidents().size() + ")", NamedTextColor.AQUA))); if (town.isOpen()) townName = townName.append(Component.space()).append(Translatable.of("status_title_open").locale(sender).component()); - Translatable spawnCost = Translatable.of("msg_spawn_cost_free"); - if (TownyEconomyHandler.isActive()) - spawnCost = Translatable.of("msg_spawn_cost", prettyMoney(town.getSpawnCost())); - - townName = townName.hoverEvent(HoverEvent.showText(Translatable.of("msg_click_spawn", town).append("\n").append(spawnCost).locale(sender).component())); + if (!spawningFullyDisabled) { + Translatable spawnCost = Translatable.of("msg_spawn_cost_free"); + if (TownyEconomyHandler.isActive()) + spawnCost = Translatable.of("msg_spawn_cost", prettyMoney(town.getSpawnCost())); + + townName = townName.clickEvent(ClickEvent.runCommand("/towny:town spawn " + town + " -ignore")); + townName = townName.hoverEvent(HoverEvent.showText(Translatable.of("msg_click_spawn", town).append("\n").append(spawnCost).locale(sender).component())); + } output.add(Pair.pair(town.getUUID(), townName)); } TownyMessaging.sendTownList(sender, output, finalType, pageNumber, totalNumber); diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/listeners/TownyCustomListener.java b/Towny/src/main/java/com/palmergames/bukkit/towny/listeners/TownyCustomListener.java index 5241314bda6..bbbe7887f95 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/listeners/TownyCustomListener.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/listeners/TownyCustomListener.java @@ -1,6 +1,5 @@ package com.palmergames.bukkit.towny.listeners; -import com.palmergames.bukkit.config.ConfigNodes; import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.TownyAPI; import com.palmergames.bukkit.towny.TownyEconomyHandler; @@ -312,7 +311,7 @@ public void onResidentPreJoinTown(TownPreAddResidentEvent event) { @EventHandler(ignoreCancelled = true) public void onResidentJoinTown(TownAddResidentEvent event) { - if (!TownySettings.isPromptingNewResidentsToTownSpawn() || !TownySettings.getBoolean(ConfigNodes.SPAWNING_ALLOW_TOWN_SPAWN)) + if (!TownySettings.isPromptingNewResidentsToTownSpawn() || !TownySettings.isConfigAllowingTownSpawn()) return; Town town = event.getTown(); diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/comparators/ComparatorCaches.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/comparators/ComparatorCaches.java index 7537eb19385..c387f8da9bd 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/comparators/ComparatorCaches.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/comparators/ComparatorCaches.java @@ -79,10 +79,12 @@ private static List> gatherTownLines(ComparatorType compTy List> output = new ArrayList<>(); List towns = TownyUniverse.getInstance().getTowns().stream().filter(Town::isVisibleOnTopLists).collect(Collectors.toList()); towns.sort((Comparator) compType.getComparator()); - + + boolean spawningFullyDisabled = !TownySettings.isConfigAllowingTownSpawn() && !TownySettings.isConfigAllowingPublicTownSpawnTravel() + && !TownySettings.isConfigAllowingTownSpawnNationTravel() && !TownySettings.isConfigAllowingTownSpawnNationAllyTravel(); + for (Town town : towns) { - Component townName = Component.text(StringMgmt.remUnderscore(town.getName()), NamedTextColor.AQUA) - .clickEvent(ClickEvent.runCommand("/towny:town spawn " + town + " -ignore")); + Component townName = Component.text(StringMgmt.remUnderscore(town.getName()), NamedTextColor.AQUA); String slug = ""; switch (compType) { @@ -118,11 +120,14 @@ private static List> gatherTownLines(ComparatorType compTy if (town.isOpen()) townName = townName.append(Component.space()).append(Translatable.of("status_title_open").component()); - Translatable spawnCost = Translatable.of("msg_spawn_cost_free"); - if (TownyEconomyHandler.isActive()) - spawnCost = Translatable.of("msg_spawn_cost", TownyEconomyHandler.getFormattedBalance(town.getSpawnCost())); + if (!spawningFullyDisabled) { + Translatable spawnCost = Translatable.of("msg_spawn_cost_free"); + if (TownyEconomyHandler.isActive()) + spawnCost = Translatable.of("msg_spawn_cost", TownyEconomyHandler.getFormattedBalance(town.getSpawnCost())); - townName = townName.hoverEvent(HoverEvent.showText(Translatable.of("msg_click_spawn", town).append("\n").append(spawnCost).component())); + townName = townName.clickEvent(ClickEvent.runCommand("/towny:town spawn " + town + " -ignore")); + townName = townName.hoverEvent(HoverEvent.showText(Translatable.of("msg_click_spawn", town).append("\n").append(spawnCost).component())); + } output.add(Pair.pair(town.getUUID(), townName)); } @@ -146,9 +151,11 @@ private static List> gatherNationLines(ComparatorType comp BukkitTools.fireEvent(nationListSortEvent); nations = nationListSortEvent.getNations(); + boolean spawningFullyDisabled = !TownySettings.isConfigAllowingNationSpawn() && !TownySettings.isConfigAllowingPublicNationSpawnTravel() + && !TownySettings.isConfigAllowingNationSpawnAllyTravel(); + for (Nation nation : nations) { - Component nationName = Component.text(StringMgmt.remUnderscore(nation.getName()), NamedTextColor.AQUA) - .clickEvent(ClickEvent.runCommand("/towny:nation spawn " + nation + " -ignore")); + Component nationName = Component.text(StringMgmt.remUnderscore(nation.getName()), NamedTextColor.AQUA); String slug = ""; switch (compType) { @@ -193,11 +200,14 @@ private static List> gatherNationLines(ComparatorType comp if (nation.isOpen()) nationName = nationName.append(Component.space()).append(Translatable.of("status_title_open").component()); - Translatable spawnCost = Translatable.of("msg_spawn_cost_free"); - if (TownyEconomyHandler.isActive()) - spawnCost = Translatable.of("msg_spawn_cost", TownyEconomyHandler.getFormattedBalance(nation.getSpawnCost())); - - nationName = nationName.hoverEvent(HoverEvent.showText(Translatable.of("msg_click_spawn", nation).append("\n").append(spawnCost).component())); + if (!spawningFullyDisabled) { + Translatable spawnCost = Translatable.of("msg_spawn_cost_free"); + if (TownyEconomyHandler.isActive()) + spawnCost = Translatable.of("msg_spawn_cost", TownyEconomyHandler.getFormattedBalance(nation.getSpawnCost())); + + nationName = nationName.clickEvent(ClickEvent.runCommand("/towny:nation spawn " + nation + " -ignore")); + nationName = nationName.hoverEvent(HoverEvent.showText(Translatable.of("msg_click_spawn", nation).append("\n").append(spawnCost).component())); + } output.add(Pair.pair(nation.getUUID(), nationName)); } return output; diff --git a/Towny/src/main/resources/ChangeLog.txt b/Towny/src/main/resources/ChangeLog.txt index 8da07c14d52..600530e60ce 100644 --- a/Towny/src/main/resources/ChangeLog.txt +++ b/Towny/src/main/resources/ChangeLog.txt @@ -10203,4 +10203,5 @@ v0.92.0.11: 0.101.1.0: - Bump version for release. 0.101.1.1: - - Replace a couple of deprecations required when we supported MC 1.16.*. \ No newline at end of file + - Replace a couple of deprecations required when we supported MC 1.16.*. + - Fix showing spawn hovers in the nation and town list, when the config is set to prevent all spawning. \ No newline at end of file