Skip to content

Commit

Permalink
- Fix showing spawn hovers in the nation and town list, when the
Browse files Browse the repository at this point in the history
config is set to prevent all spawning.
  • Loading branch information
LlmDl committed Jan 11, 2025
1 parent 8aafcb9 commit 36e5cb0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getDisallowedTownSpawnZones() {
return getStrArr(ConfigNodes.SPAWNING_PREVENT_TOWN_SPAWN_IN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1200,20 +1200,25 @@ public void listTowns(CommandSender sender, String[] split) throws TownyExceptio
List<Pair<UUID, Component>> output = new ArrayList<>();
List<Town> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ private static List<Pair<UUID, Component>> gatherTownLines(ComparatorType compTy
List<Pair<UUID, Component>> output = new ArrayList<>();
List<Town> towns = TownyUniverse.getInstance().getTowns().stream().filter(Town::isVisibleOnTopLists).collect(Collectors.toList());
towns.sort((Comparator<? super Town>) 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) {
Expand Down Expand Up @@ -118,11 +120,14 @@ private static List<Pair<UUID, Component>> 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));
}

Expand All @@ -146,9 +151,11 @@ private static List<Pair<UUID, Component>> 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) {
Expand Down Expand Up @@ -193,11 +200,14 @@ private static List<Pair<UUID, Component>> 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;
Expand Down
3 changes: 2 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*.
- 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.

0 comments on commit 36e5cb0

Please sign in to comment.