1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-09-19 12:53:17 +02:00

feat: currency identifier aliases

This commit is contained in:
Jozef Steinhübl 2023-09-29 15:05:03 +02:00
parent af3e64063f
commit f4d4bbe856
No known key found for this signature in database
GPG key ID: E944BC293F5FF7E7
4 changed files with 49 additions and 20 deletions

View file

@ -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}
*

View file

@ -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();
}
}

View file

@ -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();
}

View file

@ -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;