Skip to content

Commit 6b85515

Browse files
committed
1.1.0 - baltop, balance command can display in chat now, 1.19 support
Took 28 minutes
1 parent 4c0d857 commit 6b85515

File tree

11 files changed

+178
-18
lines changed

11 files changed

+178
-18
lines changed

buildNumber.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#maven.buildNumber.plugin properties file
2-
#Wed Apr 27 10:47:55 EDT 2022
3-
buildNumber=292
2+
#Wed Jul 06 12:25:27 EDT 2022
3+
buildNumber=301

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
<name>Funds</name>
1010
<description>The ultimate custom currency plugin</description>
11-
<version>1.0.2</version>
11+
<version>1.1.0</version>
1212
<packaging>jar</packaging>
1313

1414
<properties>
1515
<author>Kiran Hart</author>
1616
<jarName>${project.name}</jarName>
1717
<main.class>${project.groupId}.${project.artifactId}.${project.name}</main.class>
1818
<java.version>16</java.version>
19-
<rose.version>1.2.2</rose.version>
19+
<rose.version>1.3.2</rose.version>
2020
<rose.path>ca.tweetzy</rose.path>
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2222
</properties>

src/main/java/ca/tweetzy/funds/Funds.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package ca.tweetzy.funds;
22

3-
import ca.tweetzy.funds.api.interfaces.Account;
43
import ca.tweetzy.funds.commands.*;
54
import ca.tweetzy.funds.database.DataManager;
65
import ca.tweetzy.funds.database.migrations._1_CurrencyTableMigration;
76
import ca.tweetzy.funds.database.migrations._2_AccountTableMigration;
87
import ca.tweetzy.funds.database.migrations._3_VaultCurrencyMigration;
98
import ca.tweetzy.funds.database.migrations._4_AccountLanguageMigration;
109
import ca.tweetzy.funds.hooks.HookManager;
11-
import ca.tweetzy.funds.hooks.PlaceholderAPIHook;
1210
import ca.tweetzy.funds.listeners.AccessListeners;
1311
import ca.tweetzy.funds.listeners.FundsListeners;
1412
import ca.tweetzy.funds.listeners.HookListeners;
@@ -26,9 +24,6 @@
2624
import ca.tweetzy.rose.gui.GuiManager;
2725
import ca.tweetzy.rose.utils.Common;
2826
import lombok.SneakyThrows;
29-
import org.bukkit.Bukkit;
30-
import org.bukkit.event.EventHandler;
31-
import org.bukkit.event.player.AsyncPlayerChatEvent;
3227

3328
/**
3429
* Date Created: April 08 2022
@@ -83,8 +78,12 @@ protected void onFlight() {
8378
this.guiManager.init();
8479

8580
// register main command
86-
this.commandManager.registerCommandDynamically("funds").addCommand(new FundsCommand()).addSubCommands(new SupportCommand(), new LanguageCommand(), new BalanceCommand(), new PayCommand());
81+
this.commandManager.registerCommandDynamically("funds").addCommand(new FundsCommand()).addSubCommands(
82+
new SupportCommand(), new LanguageCommand(), new BalanceCommand(), new PayCommand()
83+
);
84+
8785
this.commandManager.registerCommandDynamically("balance").addCommand(new BalanceCommand());
86+
this.commandManager.registerCommandDynamically("baltop").addCommand(new BalanceTopCommand());
8887
this.commandManager.registerCommandDynamically("pay").addCommand(new PayCommand());
8988

9089
// events / listeners

src/main/java/ca/tweetzy/funds/commands/BalanceCommand.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import ca.tweetzy.funds.Funds;
44
import ca.tweetzy.funds.api.interfaces.Account;
55
import ca.tweetzy.funds.guis.player.BalanceGUI;
6+
import ca.tweetzy.funds.settings.Locale;
7+
import ca.tweetzy.funds.settings.Settings;
8+
import ca.tweetzy.funds.settings.Translation;
69
import ca.tweetzy.rose.command.AllowedExecutor;
710
import ca.tweetzy.rose.command.Command;
811
import ca.tweetzy.rose.command.ReturnType;
@@ -31,6 +34,19 @@ protected ReturnType execute(CommandSender sender, String... args) {
3134
// for whatever reason if the payer account is not found, stop entirely
3235
if (account == null) return ReturnType.FAIL;
3336

37+
if (Settings.USE_CHAT_BALANCE.getBoolean()) {
38+
39+
Locale.tell(player, Translation.CURRENCY_BALANCE_CHAT_HEADER.getKey());
40+
41+
account.getCurrencies().keySet().forEach(currency -> Translation.CURRENCY_BALANCE_CHAT_CURRENCY.getList(account,
42+
"currency_name", currency.getName(),
43+
"currency_balance", String.format("%,.2f", account.getCurrencies().getOrDefault(currency, 0D))
44+
).forEach(player::sendMessage));
45+
46+
Locale.tell(player, Translation.CURRENCY_BALANCE_CHAT_FOOTER.getKey());
47+
return ReturnType.SUCCESS;
48+
}
49+
3450
Funds.getGuiManager().showGUI(player, new BalanceGUI(null, account));
3551
return ReturnType.SUCCESS;
3652
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package ca.tweetzy.funds.commands;
2+
3+
import ca.tweetzy.funds.Funds;
4+
import ca.tweetzy.funds.api.interfaces.Account;
5+
import ca.tweetzy.funds.guis.player.BalanceGUI;
6+
import ca.tweetzy.funds.guis.player.BalanceTopGUI;
7+
import ca.tweetzy.funds.settings.Locale;
8+
import ca.tweetzy.funds.settings.Settings;
9+
import ca.tweetzy.funds.settings.Translation;
10+
import ca.tweetzy.rose.command.AllowedExecutor;
11+
import ca.tweetzy.rose.command.Command;
12+
import ca.tweetzy.rose.command.ReturnType;
13+
import org.bukkit.command.CommandSender;
14+
import org.bukkit.entity.Player;
15+
16+
import java.util.List;
17+
18+
/**
19+
* Date Created: April 12 2022
20+
* Time Created: 10:42 p.m.
21+
*
22+
* @author Kiran Hart
23+
*/
24+
public final class BalanceTopCommand extends Command {
25+
26+
public BalanceTopCommand() {
27+
super(AllowedExecutor.PLAYER, "baltop");
28+
}
29+
30+
@Override
31+
protected ReturnType execute(CommandSender sender, String... args) {
32+
final Player player = (Player) sender;
33+
final Account account = Funds.getAccountManager().getAccount(player);
34+
35+
// for whatever reason if the payer account is not found, stop entirely
36+
if (account == null) return ReturnType.FAIL;
37+
38+
Funds.getGuiManager().showGUI(player, new BalanceTopGUI(account, Funds.getCurrencyManager().getVaultOrFirst()));
39+
return ReturnType.SUCCESS;
40+
}
41+
42+
@Override
43+
protected List<String> tab(CommandSender sender, String... args) {
44+
return null;
45+
}
46+
47+
@Override
48+
public String getPermissionNode() {
49+
return "funds.cmd.baltop";
50+
}
51+
52+
@Override
53+
public String getSyntax() {
54+
return null;
55+
}
56+
57+
@Override
58+
public String getDescription() {
59+
return "Check the highest balances";
60+
}
61+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package ca.tweetzy.funds.guis.player;
2+
3+
import ca.tweetzy.funds.Funds;
4+
import ca.tweetzy.funds.api.interfaces.Account;
5+
import ca.tweetzy.funds.api.interfaces.Currency;
6+
import ca.tweetzy.funds.impl.TopBalanceRecord;
7+
import ca.tweetzy.funds.settings.Translation;
8+
import ca.tweetzy.rose.gui.events.GuiClickEvent;
9+
import ca.tweetzy.rose.gui.helper.InventoryBorder;
10+
import ca.tweetzy.rose.gui.template.PagedGUI;
11+
import ca.tweetzy.rose.utils.QuickItem;
12+
import lombok.NonNull;
13+
import org.bukkit.Bukkit;
14+
import org.bukkit.OfflinePlayer;
15+
import org.bukkit.inventory.ItemStack;
16+
17+
import java.util.List;
18+
19+
public final class BalanceTopGUI extends PagedGUI<TopBalanceRecord> {
20+
21+
private final Account player;
22+
private final Currency currency;
23+
24+
public BalanceTopGUI(@NonNull final Account player, @NonNull final Currency currency) {
25+
super(null, Translation.GUI_TOP_BALANCE_TITLE.getString(player), 6, Funds.getAccountManager().getHighestBalances(currency));
26+
this.player = player;
27+
this.currency = currency;
28+
draw();
29+
}
30+
31+
32+
@Override
33+
protected ItemStack makeDisplayItem(TopBalanceRecord topBalanceRecord) {
34+
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(topBalanceRecord.account().getOwner());
35+
36+
return QuickItem
37+
.of(offlinePlayer)
38+
.name(Translation.GUI_TOP_BALANCE_ITEMS_ACCOUNT_NAME.getString(player, "account_name", offlinePlayer.getName()))
39+
.lore(Translation.GUI_TOP_BALANCE_ITEMS_ACCOUNT_LORE.getList(player,
40+
"currency_balance", String.format("%,.2f", topBalanceRecord.amount()),
41+
"currency_name", this.currency.getName()
42+
))
43+
.make();
44+
}
45+
46+
@Override
47+
protected void onClick(TopBalanceRecord object, GuiClickEvent clickEvent) {
48+
}
49+
50+
@Override
51+
protected List<Integer> fillSlots() {
52+
return InventoryBorder.getInsideBorders(5);
53+
}
54+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package ca.tweetzy.funds.impl;
2+
3+
import ca.tweetzy.funds.api.interfaces.Account;
4+
5+
public record TopBalanceRecord(Account account, double amount) {
6+
}

src/main/java/ca/tweetzy/funds/model/AccountManager.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
import ca.tweetzy.funds.Funds;
44
import ca.tweetzy.funds.api.interfaces.Account;
5+
import ca.tweetzy.funds.api.interfaces.Currency;
6+
import ca.tweetzy.funds.impl.TopBalanceRecord;
57
import ca.tweetzy.rose.utils.Common;
68
import lombok.NonNull;
79
import org.bukkit.Bukkit;
810
import org.bukkit.OfflinePlayer;
911

10-
import java.util.ArrayList;
11-
import java.util.Collections;
12-
import java.util.List;
13-
import java.util.UUID;
12+
import java.util.*;
1413
import java.util.concurrent.CompletableFuture;
1514
import java.util.function.BiConsumer;
1615
import java.util.function.Consumer;
16+
import java.util.stream.Collectors;
1717

1818
/**
1919
* Date Created: April 11 2022
@@ -61,6 +61,19 @@ public List<Account> getAccounts() {
6161
}
6262
}
6363

64+
public List<TopBalanceRecord> getHighestBalances(@NonNull Currency currency) {
65+
synchronized (this.accounts) {
66+
final List<TopBalanceRecord> map = new ArrayList<>();
67+
68+
this.accounts.forEach(account -> {
69+
if (!account.getCurrencies().containsKey(currency)) return;
70+
map.add(new TopBalanceRecord(account, account.getCurrencies().get(currency)));
71+
});
72+
73+
return map.stream().sorted(Comparator.comparing(TopBalanceRecord::amount).reversed()).collect(Collectors.toList());
74+
}
75+
}
76+
6477
public void resetPlayerAccountsBalances() {
6578
Common.runAsync(() -> {
6679
synchronized (this.accounts) {

src/main/java/ca/tweetzy/funds/settings/Settings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public final class Settings {
2020
public static final ConfigSetting METRICS = new ConfigSetting(config, "metrics", true, "Allows me to see how many servers are using Funds");
2121

2222
public static final ConfigSetting AUTO_DEPOSIT_PICKED_UP_CURRENCY = new ConfigSetting(config, "settings.auto deposit picked up currency", true, "If true, if a player picks up a currency item, it will be automatically deposited");
23+
public static final ConfigSetting USE_CHAT_BALANCE = new ConfigSetting(config, "settings.use chat balance", false, "If true, currency balances will show up in chat after /balance instead of a gui.");
2324

2425
@SneakyThrows
2526
public static void setup() {

src/main/java/ca/tweetzy/funds/settings/Translation.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public enum Translation {
4848
PHYSICAL_CURRENCY_NAME("physical currency.name", "&F%total% %currency_auto_format%"),
4949
PHYSICAL_CURRENCY_LORE("physical currency.lore", Collections.singletonList("&e&lClick &8» &7To deposit currency")),
5050

51+
CURRENCY_BALANCE_CHAT_HEADER("currency balance chat format.header", Collections.singletonList("&8&m-----------------------------------------------------")),
52+
CURRENCY_BALANCE_CHAT_CURRENCY("currency balance chat format.currency", Collections.singletonList("%currency_name% &f/ &a%currency_balance%")),
53+
CURRENCY_BALANCE_CHAT_FOOTER("currency balance chat format.footer", Collections.singletonList("&8&m-----------------------------------------------------")),
54+
5155
/*
5256
============= Titles / Input =============
5357
*/
@@ -166,6 +170,15 @@ public enum Translation {
166170
"&e&lClick &8» &7To pay user"
167171
)),
168172

173+
GUI_TOP_BALANCE_TITLE("gui.top balance.title", "&eFunds &8> &7Top Balances"),
174+
GUI_TOP_BALANCE_ITEMS_ACCOUNT_NAME("gui.top balance.items.account.name", "&B&L%account_name%"),
175+
GUI_TOP_BALANCE_ITEMS_ACCOUNT_LORE("gui.top balance.items.account.lore", Arrays.asList(
176+
"",
177+
"&7Currency&F: &e%currency_name%",
178+
"&7Current Balance&F: &e%currency_balance%",
179+
""
180+
)),
181+
169182
/*
170183
============= ACCOUNT LIST MENU =============
171184
*/

0 commit comments

Comments
 (0)