Skip to content

Commit ed4335a

Browse files
committed
create config /invoice help messages
1 parent 73ad14c commit ed4335a

File tree

3 files changed

+74
-10
lines changed

3 files changed

+74
-10
lines changed

src/main/java/pro/cloudnode/smp/bankaccounts/BankConfig.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,31 @@ public int invoiceNotifyInterval() {
487487
return Optional.of(MiniMessage.miniMessage().deserialize(message));
488488
}
489489

490+
// messages.help.invoice.header
491+
public @NotNull Optional<@NotNull Component> messagesHelpInvoiceHeader() {
492+
final @Nullable String message = config.getString("messages.help.invoice.header");
493+
if (message == null || message.isEmpty()) return Optional.empty();
494+
return Optional.of(MiniMessage.miniMessage().deserialize(message));
495+
}
496+
497+
// messages.help.invoice.commands.
498+
public @NotNull Optional<@NotNull Component> messagesHelpInvoiceCommands(final @NotNull HelpCommandsInvoice key, final @NotNull String command, final @NotNull String arguments) {
499+
final @Nullable String message = config.getString("messages.help.invoice.commands." + key.path);
500+
if (message == null || message.isEmpty()) return Optional.empty();
501+
return Optional.of(MiniMessage.miniMessage().deserialize(
502+
message
503+
.replace("<command>", command),
504+
Placeholder.unparsed("arguments", arguments)
505+
));
506+
}
507+
508+
// messages.help.invoice.footer
509+
public @NotNull Optional<@NotNull Component> messagesHelpInvoiceFooter() {
510+
final @Nullable String message = config.getString("messages.help.invoice.footer");
511+
if (message == null || message.isEmpty()) return Optional.empty();
512+
return Optional.of(MiniMessage.miniMessage().deserialize(message));
513+
}
514+
490515
// messages.errors.no-accounts
491516
public @NotNull Component messagesErrorsNoAccounts() {
492517
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("messages.errors.no-accounts")));
@@ -1459,4 +1484,21 @@ public enum HelpCommandsBank {
14591484
this.path = path;
14601485
}
14611486
}
1487+
1488+
public enum HelpCommandsInvoice {
1489+
CREATE("create"),
1490+
CREATE_PLAYER("create-player"),
1491+
VIEW("view"),
1492+
PAY("pay"),
1493+
SEND("send"),
1494+
LIST("list"),
1495+
LIST_OTHER("list-other"),
1496+
;
1497+
1498+
public final @NotNull String path;
1499+
1500+
HelpCommandsInvoice(final @NotNull String path) {
1501+
this.path = path;
1502+
}
1503+
}
14621504
}

src/main/java/pro/cloudnode/smp/bankaccounts/commands/InvoiceCommand.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.jetbrains.annotations.Nullable;
1010
import pro.cloudnode.smp.bankaccounts.Account;
1111
import pro.cloudnode.smp.bankaccounts.BankAccounts;
12+
import pro.cloudnode.smp.bankaccounts.BankConfig;
1213
import pro.cloudnode.smp.bankaccounts.Command;
1314
import pro.cloudnode.smp.bankaccounts.Invoice;
1415
import pro.cloudnode.smp.bankaccounts.Permissions;
@@ -125,23 +126,21 @@ else if (args.length == 3) {
125126
* <p>{@code /invoice help}</p>
126127
*/
127128
public static @NotNull CommandResult help(final @NotNull CommandSender sender, final @NotNull String label) {
128-
sender.sendMessage(MiniMessage.miniMessage().deserialize("<dark_gray>---</dark_gray>"));
129-
sender.sendMessage(MiniMessage.miniMessage().deserialize("<green>Available commands:"));
130-
sender.sendMessage(Component.empty());
129+
BankAccounts.getInstance().config().messagesHelpInvoiceHeader().ifPresent(sender::sendMessage);
131130
if (sender.hasPermission(Permissions.INVOICE_CREATE)) {
132-
sender.sendMessage(MiniMessage.miniMessage().deserialize("<click:suggest_command:/" + label + " create ><green>/" + label + " create <gray><account> <amount> [description]</gray></green> <white>- Create an invoice</white></click>"));
133-
sender.sendMessage(MiniMessage.miniMessage().deserialize("<click:suggest_command:/" + label + " create ><green>/" + label + " create <gray><account> <amount> [description] --player <player></gray></green> <white>- Create and send invoice to player</white></click>"));
131+
BankAccounts.getInstance().config().messagesHelpInvoiceCommands(BankConfig.HelpCommandsInvoice.CREATE, label + " create", "<account> <amount> [description]").ifPresent(sender::sendMessage);
132+
BankAccounts.getInstance().config().messagesHelpInvoiceCommands(BankConfig.HelpCommandsInvoice.CREATE_PLAYER, label + " create", "<player> <amount> [description] --player <player>").ifPresent(sender::sendMessage);
134133
}
135134
if (sender.hasPermission(Permissions.INVOICE_VIEW))
136-
sender.sendMessage(MiniMessage.miniMessage().deserialize("<click:suggest_command:/" + label + " view ><green>/" + label + " view <gray><invoice></gray></green> <white>- View invoice details</white></click>"));
135+
BankAccounts.getInstance().config().messagesHelpInvoiceCommands(BankConfig.HelpCommandsInvoice.VIEW, label + " view", "<invoice>").ifPresent(sender::sendMessage);
137136
if (sender.hasPermission(Permissions.TRANSFER_SELF) || sender.hasPermission(Permissions.TRANSFER_OTHER))
138-
sender.sendMessage(MiniMessage.miniMessage().deserialize("<click:suggest_command:/" + label + " pay ><green>/" + label + " pay <gray><invoice> <account></gray></green> <white>- Pay an invoice</white></click>"));
137+
BankAccounts.getInstance().config().messagesHelpInvoiceCommands(BankConfig.HelpCommandsInvoice.PAY, label + " pay", "<invoice> <account>").ifPresent(sender::sendMessage);
139138
if (sender.hasPermission(Permissions.INVOICE_SEND))
140-
sender.sendMessage(MiniMessage.miniMessage().deserialize("<click:suggest_command:/" + label + " send ><green>/" + label + " send <gray><invoice> <player></gray></green> <white>- Send an invoice to a player</white></click>"));
139+
BankAccounts.getInstance().config().messagesHelpInvoiceCommands(BankConfig.HelpCommandsInvoice.SEND, label + " send", "<invoice> <player>").ifPresent(sender::sendMessage);
141140
if (sender.hasPermission(Permissions.INVOICE_VIEW)) {
142-
sender.sendMessage(MiniMessage.miniMessage().deserialize("<click:suggest_command:/" + label + " list ><green>/" + label + " list <gray>[all|sent|received] [page]</gray></green> <white>- List invoices</white></click>"));
141+
BankAccounts.getInstance().config().messagesHelpInvoiceCommands(BankConfig.HelpCommandsInvoice.LIST, label + " list", "[all|sent|received] [page]").ifPresent(sender::sendMessage);
143142
if (sender.hasPermission(Permissions.INVOICE_VIEW_OTHER))
144-
sender.sendMessage(MiniMessage.miniMessage().deserialize("<click:suggest_command:/" + label + " list ><green>/" + label + " list <gray>[all|sent|received] [page] --player <player></gray></green> <white>- List invoices of player</white></click>"));
143+
BankAccounts.getInstance().config().messagesHelpInvoiceCommands(BankConfig.HelpCommandsInvoice.LIST_OTHER, label + " list", "[all|sent|received] [page] --player <player>").ifPresent(sender::sendMessage);
145144
}
146145
return new Message(sender, "<dark_gray>---</dark_gray>");
147146
}

src/main/resources/config.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,29 @@ messages:
332332
# Shown after all commands
333333
# Set to nothing, e.g. "footer:" (without quotes) to disable
334334
footer: <dark_gray>---</dark_gray>
335+
# Messages in /invoice help
336+
invoice:
337+
# Shown before any commands
338+
# Set to nothing, e.g. "header:" (without quotes) to disable
339+
header: |
340+
<dark_gray>---</dark_gray>
341+
<green>Available commands:</green>
342+
# Each command is only shown if the player has permission to use it.
343+
# Set to nothing, e.g. "create:" (without quotes) to disable a command
344+
# Placeholders:
345+
# - <command> - The base command name (e.g. "invoice create").
346+
# - <arguments> - The command usage arguments (e.g. "<account> <amount> [description]").
347+
commands:
348+
create: <click:suggest_command:/<command> ><green>/<command></green> <gray><arguments></gray> <white>- Create an invoice that anyone can pay.</white></click>
349+
create-player: <click:suggest_command:/<command> ><green>/<command></green> <gray><arguments></gray> <white>- Create and send an invoice for a specific player.</white></click>
350+
view: <click:suggest_command:/<command> ><green>/<command></green> <gray><arguments></gray> <white>- View an invoice.</white></click>
351+
pay: <click:suggest_command:/<command> ><green>/<command></green> <gray><arguments></gray> <white>- Pay an invoice.</white></click>
352+
send: <click:suggest_command:/<command> ><green>/<command></green> <gray><arguments></gray> <white>- Send an invoice to a player.</white></click>
353+
list: <click:suggest_command:/<command> ><green>/<command></green> <gray><arguments></gray> <white>- List your invoices.</white></click>
354+
list-other: <click:suggest_command:/<command> ><green>/<command></green> <gray><arguments></gray> <white>- List another invoices of player.</white></click>
355+
# Shown after all commands
356+
# Set to nothing, e.g. "footer:" (without quotes) to disable
357+
footer: <dark_gray>---</dark_gray>
335358
# Errors
336359
errors:
337360
# You have no accounts

0 commit comments

Comments
 (0)