Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 0.100.0.12 #2

Merged
merged 9 commits into from
Dec 22, 2023
8 changes: 4 additions & 4 deletions Towny/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<artifactId>towny</artifactId>
<packaging>jar</packaging>
<version>0.100.0.11</version>
<version>0.100.0.14</version>

<licenses>
<license>
Expand Down Expand Up @@ -167,7 +167,7 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.1</version>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
Expand Down Expand Up @@ -256,7 +256,7 @@
<dependency>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.20</artifactId>
<version>3.56.0</version>
<version>3.58.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -472,7 +472,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
<version>3.2.3</version>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ public static boolean setBalance(String accountName, double amount, World world)
* @return string containing the formatted balance
*/
public static String getFormattedBalance(double balance) {
if (!isActive())
return String.valueOf(balance);

String formattedBalance = economy.getFormattedBalance(balance);
if (formattedBalance != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.palmergames.bukkit.towny.command;

import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownyEconomyHandler;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.exceptions.NoPermissionException;
import com.palmergames.bukkit.towny.exceptions.ResidentNPCException;
Expand Down Expand Up @@ -390,4 +391,8 @@ public static void catchNPCResident(Resident resident) throws ResidentNPCExcepti
if (resident.isNPC())
throw new ResidentNPCException();
}

public static String prettyMoney(double cost) {
return TownyEconomyHandler.getFormattedBalance(cost);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,17 @@ protected MenuBuilder load() {
}
},

NATION_SANCTIONTOWN {
@Override
protected MenuBuilder load() {
return new MenuBuilder("nation sanctiontown")
.add("add [town]", Translatable.of("nation_sanction_help_1"))
.add("remove [town]", Translatable.of("nation_sanction_help_2"))
.add("list", Translatable.of("nation_sanction_help_3"))
.add("list [nation]", Translatable.of("nation_sanction_help_4"));
}
},

ALLIES_STRING {
@Override
protected MenuBuilder load() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.palmergames.bukkit.towny.event.NationPreRemoveEnemyEvent;
import com.palmergames.bukkit.towny.event.nation.NationRankAddEvent;
import com.palmergames.bukkit.towny.event.nation.NationRankRemoveEvent;
import com.palmergames.bukkit.towny.event.nation.NationSanctionTownAddEvent;
import com.palmergames.bukkit.towny.event.nation.NationSanctionTownRemoveEvent;
import com.palmergames.bukkit.towny.event.nation.NationSetSpawnEvent;
import com.palmergames.bukkit.towny.event.nation.NationTownLeaveEvent;
import com.palmergames.bukkit.towny.event.NationRemoveEnemyEvent;
Expand Down Expand Up @@ -125,6 +127,7 @@ public class NationCommand extends BaseCommand implements CommandExecutor {
"enemylist",
"ally",
"spawn",
"sanctiontown",
"king",
"leader",
"bankhistory",
Expand Down Expand Up @@ -235,6 +238,18 @@ else if (args.length == 3)
if (args.length == 3) {
return Collections.singletonList("-ignore");
}
case "sanctiontown":
if (args.length == 2)
return NameUtil.filterByStart(Arrays.asList("add", "remove", "list"), args[1]);
if (args.length == 3 && args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove"))
return NameUtil.filterByStart(TownyUniverse.getInstance().getTowns()
.stream()
.filter(t -> !nation.hasTown(t))
.map(Town::getName)
.collect(Collectors.toList()), args[2]);
if (args.length == 3 && args[1].equalsIgnoreCase("list"))
return getTownyStartingWith(args[2], "n");
break;
case "add":
return getTownyStartingWith(args[args.length - 1], "t");
case "kick":
Expand Down Expand Up @@ -528,6 +543,9 @@ public void parseNationCommand(final Player player, String[] split) throws Towny
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_NATION_KICK.getNode());
nationKick(player, StringMgmt.remFirstArg(split));
break;
case "sanctiontown":
nationSanctionTown(player, null, StringMgmt.remFirstArg(split));
break;
case "set":
/* Permission test is internal*/
nationSet(player, StringMgmt.remFirstArg(split), false, null);
Expand Down Expand Up @@ -666,7 +684,11 @@ private void parseNationJoin(Player player, String[] args) {
// Check if town is town is free to join.
if (!nation.isOpen())
throw new TownyException(Translatable.of("msg_err_nation_not_open", nation.getFormattedName()));


// Check if the town is sanctioned and not allowed to join.
if (nation.hasSanctionedTown(town))
throw new TownyException(Translatable.of("msg_err_cannot_join_nation_sanctioned_town", nation.getName()));

if (!testTownHasEnoughResidents(town))
throw new TownyException(Translatable.of("msg_err_not_enough_residents_join_nation", town.getName()));

Expand Down Expand Up @@ -945,8 +967,9 @@ public static void newNation(CommandSender sender, String name, Town capitalTown
// If it isn't free to make a nation, send a confirmation.
if (!noCharge && TownyEconomyHandler.isActive()) {
// Test if they can pay.
if (!capitalTown.getAccount().canPayFromHoldings(TownySettings.getNewNationPrice()))
throw new TownyException(Translatable.of("msg_no_funds_new_nation2", TownySettings.getNewNationPrice()));
double cost = TownySettings.getNewNationPrice();
if (!capitalTown.getAccount().canPayFromHoldings(cost))
throw new TownyException(Translatable.of("msg_no_funds_new_nation2", cost));

final String finalName = filteredName;
Confirmation.runOnAccept(() -> {
Expand All @@ -959,9 +982,9 @@ public static void newNation(CommandSender sender, String name, Town capitalTown
TownyMessaging.sendGlobalMessage(Translatable.of("msg_new_nation", sender.getName(), StringMgmt.remUnderscore(finalName)));

})
.setCost(new ConfirmationTransaction(TownySettings::getNewNationPrice, capitalTown.getAccount(), "New Nation Cost",
Translatable.of("msg_no_funds_new_nation2", TownySettings.getNewNationPrice())))
.setTitle(Translatable.of("msg_confirm_purchase", TownyEconomyHandler.getFormattedBalance(TownySettings.getNewNationPrice())))
.setCost(new ConfirmationTransaction(TownySettings::getNewNationPrice, capitalTown, "New Nation Cost",
Translatable.of("msg_no_funds_new_nation2", cost)))
.setTitle(Translatable.of("msg_confirm_purchase", prettyMoney(cost)))
.sendTo(sender);

// Or, it is free, so just make the nation.
Expand Down Expand Up @@ -1179,6 +1202,13 @@ public void nationAdd(Player player, String[] names) throws TownyException {
continue;
}

if (nation.hasSanctionedTown(town)) {
// Town is sanctioned and cannot join.
removeinvites.add(townname);
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_cannot_add_sanctioned_town", townname));
continue;
}

if (!testNationMaxResidents(nation, town)) {
// Town has too many residents to join the nation
removeinvites.add(townname);
Expand Down Expand Up @@ -1397,6 +1427,73 @@ public static void nationKick(CommandSender sender, Nation nation, List<Town> ki
TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_invalid_name"));
}

public static void nationSanctionTown(CommandSender sender, Nation nation, String[] args) throws TownyException {
if (args.length == 0 || args[0].equals("?")) {
HelpMenu.NATION_SANCTIONTOWN.send(sender);
return;
}

if (nation == null && sender instanceof Player player)
nation = getNationFromPlayerOrThrow(player);

if (nation == null)
throw new TownyException(Translatable.of("msg_err_no_nation_cannot_do"));

if (args[0].toLowerCase(Locale.ROOT).equals("list")) {
if (args.length == 2)
nation = getNationOrThrow(args[1]);
nationSanctionTownList(sender, nation);
return;
}

if (args.length != 2) {
HelpMenu.NATION_SANCTIONTOWN.send(sender);
return;
}
checkPermOrThrow(sender, PermissionNodes.TOWNY_COMMAND_NATION_SANCTIONTOWN.getNode());
Town town = getTownOrThrow(args[1]);
switch(args[0].toLowerCase(Locale.ROOT)) {
case "add" -> nationSanctionTownAdd(sender, nation, town);
case "remove" -> nationSactionTownRemove(sender, nation, town);
default -> HelpMenu.NATION_SANCTIONTOWN.send(sender);
}
}

private static void nationSanctionTownList(CommandSender sender, Nation nation) {
if (nation.getSanctionedTowns().isEmpty()) {
TownyMessaging.sendMsg(sender, Translatable.of("msg_err_nation_has_no_sanctioned_towns"));
return;
}
Translator translator = Translator.locale(sender);
TownyMessaging.sendMessage(sender, ChatTools.formatTitle(nation.getName() + " " + translator.of("title_nation_sanctioned_towns")));
TownyMessaging.sendMessage(sender, TownyFormatter.getFormattedTownyObjects(translator.of("title_nation_sanctioned_towns"), new ArrayList<>(nation.getSanctionedTowns())));
}

private static void nationSanctionTownAdd(CommandSender sender, Nation nation, Town town) throws TownyException {
if (nation.hasTown(town))
throw new TownyException(Translatable.of("msg_err_nation_cannot_sanction_own_town"));

if (nation.hasSanctionedTown(town))
throw new TownyException(Translatable.of("msg_err_nation_town_already_sanctioned"));

BukkitTools.ifCancelledThenThrow(new NationSanctionTownAddEvent(nation, town));

nation.addSanctionedTown(town);
nation.save();
TownyMessaging.sendMsg(sender, Translatable.of("msg_err_nation_town_sanctioned", town.getName()));
}

private static void nationSactionTownRemove(CommandSender sender, Nation nation, Town town) throws TownyException {
if (!nation.hasSanctionedTown(town))
throw new TownyException(Translatable.of("msg_err_nation_town_isnt_sanctioned"));

BukkitTools.ifCancelledThenThrow(new NationSanctionTownRemoveEvent(nation, town));

nation.removeSanctionedTown(town);
nation.save();
TownyMessaging.sendMsg(sender, Translatable.of("msg_err_nation_town_unsanctioned", town.getName()));
}

private void nationAlly(Player player, String[] split) throws TownyException {
if (split.length == 0) {
HelpMenu.ALLIES_STRING.send(player);
Expand Down Expand Up @@ -1973,11 +2070,12 @@ private static void nationSetMapColor(CommandSender sender, Nation nation, Strin
if (!TownySettings.getNationColorsMap().containsKey(color))
throw new TownyException(Translatable.of("msg_err_invalid_nation_map_color", TownySettings.getNationColorsMap().keySet().toString()));

if (TownySettings.getNationSetMapColourCost() > 0)
double cost = TownySettings.getNationSetMapColourCost();
if (cost > 0)
Confirmation
.runOnAccept(() -> setNationMapColor(nation, color, admin, sender))
.setTitle(Translatable.of("msg_confirm_purchase", TownySettings.getNationSetMapColourCost()))
.setCost(new ConfirmationTransaction(()-> TownySettings.getNationSetMapColourCost(), nation.getAccount(), "Cost of setting nation map color."))
.setTitle(Translatable.of("msg_confirm_purchase", prettyMoney(cost)))
.setCost(new ConfirmationTransaction(() -> cost, nation, "Cost of setting nation map color."))
.sendTo(sender);
else
setNationMapColor(nation, color, admin, sender);
Expand Down
Loading