Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ enabling compatibility with third-party plugins that support Vault.

You can create a [Point of Sale](https://github.com/cloudnode-pro/BankAccounts/wiki/POS), which is a type of single-use chest shop. Players can pay using a bank card (`/bank card`).

### PlaceholderAPI Support

BankAccounts provides several *PlaceholderAPI* placeholders that you can use. See
the [Placeholders Wiki](https://github.com/cloudnode-pro/BankAccounts/wiki/Placeholders) for an exhaustive list.

### Extensive Configuration

All functionality is fully configurable. See [default config](https://github.com/cloudnode-pro/BankAccounts/blob/master/src/main/resources/config.yml).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import pro.cloudnode.smp.bankaccounts.Account;
import pro.cloudnode.smp.bankaccounts.BankAccounts;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.stream.Collectors;

public final class PAPIIntegration extends PlaceholderExpansion {
@Override
public @NotNull String getIdentifier() {
Expand All @@ -22,29 +26,60 @@ public final class PAPIIntegration extends PlaceholderExpansion {
return BankAccounts.getInstance().getPluginMeta().getVersion();
}

/**
* Adds the following placeholders:
* <ul>
* <li>%bankaccounts_balance_&lt;accountID&gt;% - returns balance of account with specified ID</li>
* <li>%bankaccounts_balance_formatted_&lt;accountID&gt;% - returns formatted balance of account with specified ID</li>
* <li>%bankaccounts_owner_&lt;accountID&gt;% - returns name of the owner of account with specified ID</li>
* <li>%bankaccounts_type_&lt;accountID&gt;% - returns type of account with specified ID</li>
* <li>%bankaccounts_name_&lt;accountID&gt;% - returns name of account with specified ID</li>
* </ul>
*/
@Override
public String onRequest(final @NotNull OfflinePlayer player, final @NotNull String params) {
final @NotNull String[] args = params.split("_");

if (args.length < 1) return null;
return switch (args[0]) {
case "balance" -> args.length < 2 ? null : switch (args[1]) {
case "formatted" -> args.length != 3 ? null : Account.get(Account.Tag.from(args[2])).map(value -> BankAccounts.formatCurrency(value.balance)).orElse(null);
default -> Account.get(Account.Tag.from(args[1])).map(value -> String.valueOf(value.balance)).orElse(null);
};
case "owner" -> args.length < 2 ? null : Account.get(Account.Tag.from(args[1])).map(value -> value.owner.getName()).orElse(null);
case "type" -> args.length < 2 ? null : Account.get(Account.Tag.from(args[1])).map(value -> value.type.getName()).orElse(null);
case "name" -> args.length < 2 ? null : Account.get(Account.Tag.from(args[1])).map(value -> value.name).orElse(null);
case "balance" -> {
if (args.length == 1)
yield String.valueOf(
Arrays.stream(Account.get(player))
.map(account -> account.balance)
.reduce(BigDecimal.ZERO, BigDecimal::add)
);
yield switch (args[1]) {
case "formatted" -> {
if (args.length == 3)
yield Account.get(Account.Tag.from(args[2])).map(value -> BankAccounts.formatCurrency(value.balance)).orElse(null);
if (args.length == 2)
yield BankAccounts.formatCurrency(
Arrays.stream(Account.get(player))
.map(account -> account.balance)
.reduce(BigDecimal.ZERO, BigDecimal::add)
);
yield null;
}
case "short" -> {
if (args.length == 3)
yield Account.get(Account.Tag.from(args[2])).map(value -> BankAccounts.formatCurrencyShort(value.balance)).orElse(null);
if (args.length == 2)
yield BankAccounts.formatCurrencyShort(
Arrays.stream(Account.get(player))
.map(account -> account.balance)
.reduce(BigDecimal.ZERO, BigDecimal::add)
);
yield null;
}
default -> Account.get(Account.Tag.from(args[1])).map(value -> String.valueOf(value.balance)).orElse(null);
};
}
case "owner" -> args.length != 2 ? null : Account.get(Account.Tag.from(args[1])).map(value -> value.owner.getName()).orElse(null);
case "type" -> args.length != 2 ? null : Account.get(Account.Tag.from(args[1])).map(value -> value.type.getName()).orElse(null);
case "name" -> args.length != 2 ? null : Account.get(Account.Tag.from(args[1])).map(Account::name).orElse(null);
case "account" -> {
if (args.length == 2) {
final @NotNull Account @NotNull [] accounts = Account.get(player);
yield switch (args[1]) {
case "list" -> Arrays.stream(accounts).map(account -> account.id).collect(Collectors.joining(", "));
case "names" -> Arrays.stream(accounts).map(Account::name).collect(Collectors.joining(", "));
case "count" -> String.valueOf(accounts.length);
default -> null;
};
}
yield null;
}
default -> null;
};
}
Expand Down
Loading