Skip to content

Commit

Permalink
- Add the ability to use k, m and b in various money commands in
Browse files Browse the repository at this point in the history
Towny.
    - ex: /t deposit 1k, will deposit 1000 into the town bank.
    - Closes #7759.
  • Loading branch information
LlmDl committed Feb 15, 2025
1 parent 641ea8a commit 427660b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Towny/src/main/java/com/palmergames/util/MathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static double getDoubleOrThrow(String input) throws TownyException {
}

public static int getIntOrThrow(String input) throws TownyException {
input = parseAbbreviations(input);
int i;
try {
i = Integer.parseInt(input);
Expand All @@ -78,6 +79,24 @@ public static int getIntOrThrow(String input) throws TownyException {
return i;
}

private static String parseAbbreviations(String input) {
if (input.endsWith("k") || input.endsWith("K"))
return parseNumbers(input) + "000";
if (input.endsWith("m") || input.endsWith("M"))
return parseNumbers(input) + "000000";
if (input.endsWith("b") || input.endsWith("B"))
return parseNumbers(input) + "000000000";
return input;
}

private static String parseNumbers(String input) {
String output = "";
for (int i = 0; i < input.length(); i++)
if (Character.isDigit(input.charAt(i)))
output += input.charAt(i);
return output;
}

public static int getPositiveIntOrThrow(String input) throws TownyException {
int i = getIntOrThrow(input);
if (i < 0)
Expand Down
5 changes: 4 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10234,4 +10234,7 @@ v0.92.0.11:
- While true, conquered towns will be considered a member of good standing in the nation, and will be treated as normal nation members when plot perms are calculated.
- When set to false plot permission tests will treat conquered towns' residents as not members of their nations, preventing them from using their host nation's plots while the nation's towns have nation plot perms enabled.
- Add optional -ignore subcommand to /town leave.
- When used, the player will not have to confirm their leaving the town.
- When used, the player will not have to confirm their leaving the town.
- Add the ability to use k, m and b in various money commands in Towny.
- ex: /t deposit 1k, will deposit 1000 into the town bank.
- Closes #7759.

0 comments on commit 427660b

Please sign in to comment.