mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-21 22:41:06 +01:00
feat: currency identifier aliases
This commit is contained in:
parent
af3e64063f
commit
f4d4bbe856
4 changed files with 49 additions and 20 deletions
|
@ -13,6 +13,19 @@ public interface Currency {
|
|||
*/
|
||||
String getIdentifier();
|
||||
|
||||
/**
|
||||
* Returns the identifier aliases of the currency.
|
||||
* <p>
|
||||
* Useful if you want multiple commands for the same currency.
|
||||
* For example, you can have a command `/hyrocoins` but also `/hc`.
|
||||
* </p>
|
||||
*
|
||||
* @return the aliases
|
||||
*/
|
||||
default String[] getIdentifierAliases() {
|
||||
return new String[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the type of the currency, either {@link Type#LOCAL} or {@link Type#GLOBAL}
|
||||
*
|
||||
|
|
|
@ -20,28 +20,11 @@ public class BukkitCommandManager extends AbstractCommandManager {
|
|||
|
||||
@Override
|
||||
public void registerCurrencyCommand(@NonNull Currency currency) {
|
||||
String permissionBase = "lighteco.currency." + currency.getIdentifier() + ".command.";
|
||||
registerCommands(currency.getIdentifier(), currency);
|
||||
|
||||
// Balance
|
||||
for (CommandAPICommand cmd : new BalanceCommand(
|
||||
this,
|
||||
currency.getIdentifier(),
|
||||
currency,
|
||||
permissionBase
|
||||
).multipleBuild()) {
|
||||
cmd.register();
|
||||
for (String alias : currency.getIdentifierAliases()) {
|
||||
registerCommands(alias, currency);
|
||||
}
|
||||
|
||||
CommandAPICommand cmd = new CommandAPICommand(currency.getIdentifier())
|
||||
.withSubcommand(new SetCommand(this, currency, permissionBase).build())
|
||||
.withSubcommand(new GiveCommand(this, currency, permissionBase).build())
|
||||
.withSubcommand(new TakeCommand(this, currency, permissionBase).build())
|
||||
.withSubcommands(new BalanceCommand(this, "balance", currency, permissionBase).multipleBuild());
|
||||
|
||||
if (currency.isPayable())
|
||||
cmd = cmd.withSubcommand(new PayCommand(this, currency, permissionBase).build());
|
||||
|
||||
cmd.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,6 +52,30 @@ public class BukkitCommandManager extends AbstractCommandManager {
|
|||
).multipleBuild()) {
|
||||
cmd.register();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommands(@NonNull String name, @NonNull Currency currency) {
|
||||
String permissionBase = "lighteco.currency." + currency.getIdentifier() + ".command.";
|
||||
|
||||
// Balance
|
||||
for (CommandAPICommand cmd : new BalanceCommand(
|
||||
this,
|
||||
name,
|
||||
currency,
|
||||
permissionBase
|
||||
).multipleBuild()) {
|
||||
cmd.register();
|
||||
}
|
||||
|
||||
CommandAPICommand cmd = new CommandAPICommand(name)
|
||||
.withSubcommand(new SetCommand(this, currency, permissionBase).build())
|
||||
.withSubcommand(new GiveCommand(this, currency, permissionBase).build())
|
||||
.withSubcommand(new TakeCommand(this, currency, permissionBase).build())
|
||||
.withSubcommands(new BalanceCommand(this, "balance", currency, permissionBase).multipleBuild());
|
||||
|
||||
if (currency.isPayable())
|
||||
cmd = cmd.withSubcommand(new PayCommand(this, currency, permissionBase).build());
|
||||
|
||||
cmd.register();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@ public class Currency {
|
|||
return proxy.getIdentifier();
|
||||
}
|
||||
|
||||
public String[] getIdentifierAliases() {
|
||||
return proxy.getIdentifierAliases();
|
||||
}
|
||||
|
||||
public dev.xhyrom.lighteco.api.model.currency.Currency.Type getType() {
|
||||
return proxy.getType();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,11 @@ public class MoneyCurrency implements Currency {
|
|||
return "money";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getIdentifierAliases() {
|
||||
return new String[]{"eco"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return Type.LOCAL;
|
||||
|
|
Loading…
Reference in a new issue