mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-12-22 04:21:06 +01:00
feat(currency-money): add config
This commit is contained in:
parent
ec573d8357
commit
f0fda5bcbf
8 changed files with 100 additions and 13 deletions
|
@ -5,6 +5,7 @@ plugins {
|
|||
repositories {
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://jitpack.io")
|
||||
maven("https://storehouse.okaeri.eu/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -14,9 +15,19 @@ dependencies {
|
|||
|
||||
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
|
||||
|
||||
// This can be compileOnly because it's included in common (lighteco-platform)
|
||||
// Reduce duplication and size
|
||||
compileOnly("eu.okaeri:okaeri-configs-yaml-snakeyaml:5.0.0-beta.5")
|
||||
compileOnly("eu.okaeri:okaeri-configs-validator-okaeri:5.0.0-beta.5")
|
||||
|
||||
compileOnly("org.projectlombok:lombok:1.18.28")
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.28")
|
||||
|
||||
compileOnly("org.checkerframework:checker-qual:3.8.0")
|
||||
compileOnly("org.jetbrains:annotations:20.1.0")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
relocate("eu.okaeri.configs", "dev.xhyrom.lighteco.libraries.okaeri.configs")
|
||||
relocate("eu.okaeri.validator", "dev.xhyrom.lighteco.libraries.okaeri.validator")
|
||||
}
|
|
@ -6,13 +6,25 @@ import dev.xhyrom.lighteco.api.manager.CommandManager;
|
|||
import dev.xhyrom.lighteco.api.manager.CurrencyManager;
|
||||
import dev.xhyrom.lighteco.api.model.currency.Currency;
|
||||
import dev.xhyrom.lighteco.currency.money.bukkit.hooks.vault.VaultFactory;
|
||||
import dev.xhyrom.lighteco.currency.money.common.MoneyCurrency;
|
||||
import dev.xhyrom.lighteco.currency.money.common.AbstractPlugin;
|
||||
import dev.xhyrom.lighteco.currency.money.common.Plugin;
|
||||
import dev.xhyrom.lighteco.currency.money.common.currency.MoneyCurrency;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitMCLoader extends JavaPlugin {
|
||||
private VaultFactory vaultFactory;
|
||||
@Getter
|
||||
private final Plugin plugin;
|
||||
|
||||
public BukkitMCLoader() {
|
||||
this.plugin = new AbstractPlugin(this.getDataFolder().toPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
this.plugin.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
|
|
@ -4,19 +4,25 @@ import dev.xhyrom.lighteco.api.LightEco;
|
|||
import dev.xhyrom.lighteco.api.LightEcoProvider;
|
||||
import dev.xhyrom.lighteco.api.model.currency.Currency;
|
||||
import dev.xhyrom.lighteco.api.model.user.User;
|
||||
import dev.xhyrom.lighteco.currency.money.bukkit.BukkitMCLoader;
|
||||
import dev.xhyrom.lighteco.currency.money.common.Plugin;
|
||||
import net.milkbowl.vault.economy.AbstractEconomy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Vault extends AbstractEconomy {
|
||||
private final Plugin plugin;
|
||||
private final LightEco provider;
|
||||
private final Currency currency;
|
||||
|
||||
public Vault() {
|
||||
public Vault(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.provider = LightEcoProvider.get();
|
||||
this.currency = this.provider.getCurrencyManager().getCurrency("money");
|
||||
}
|
||||
|
@ -43,17 +49,20 @@ public class Vault extends AbstractEconomy {
|
|||
|
||||
@Override
|
||||
public String format(double amount) {
|
||||
return null;
|
||||
NumberFormat format = NumberFormat.getInstance();
|
||||
format.setCurrency(java.util.Currency.getInstance(this.plugin.getConfig().currencyCode));
|
||||
|
||||
return format.format(BigDecimal.valueOf(amount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String currencyNamePlural() {
|
||||
return null;
|
||||
return this.plugin.getConfig().currencyNamePlural;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String currencyNameSingular() {
|
||||
return null;
|
||||
return this.plugin.getConfig().currencyNameSingular;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,19 +7,19 @@ import org.bukkit.plugin.ServicePriority;
|
|||
import org.bukkit.plugin.ServicesManager;
|
||||
|
||||
public class VaultFactory {
|
||||
private final BukkitMCLoader plugin;
|
||||
private final BukkitMCLoader loader;
|
||||
private Vault vault;
|
||||
|
||||
public VaultFactory(BukkitMCLoader plugin) {
|
||||
this.plugin = plugin;
|
||||
public VaultFactory(BukkitMCLoader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public void hook() {
|
||||
if (this.vault == null)
|
||||
vault = new Vault();
|
||||
vault = new Vault(this.loader.getPlugin());
|
||||
|
||||
ServicesManager manager = Bukkit.getServicesManager();
|
||||
manager.register(Economy.class, vault, this.plugin, ServicePriority.Highest);
|
||||
manager.register(Economy.class, vault, this.loader, ServicePriority.Highest);
|
||||
}
|
||||
|
||||
public void unhook() {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package dev.xhyrom.lighteco.currency.money.common;
|
||||
|
||||
import dev.xhyrom.lighteco.currency.money.common.config.Config;
|
||||
import eu.okaeri.configs.ConfigManager;
|
||||
import eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class AbstractPlugin implements Plugin {
|
||||
@Getter
|
||||
private Config config;
|
||||
private Path dataDirectory;
|
||||
|
||||
public AbstractPlugin(Path dataDirectory) {
|
||||
this.dataDirectory = dataDirectory;
|
||||
}
|
||||
|
||||
public final void load() {
|
||||
this.config = ConfigManager.create(Config.class, it -> {
|
||||
it.withConfigurer(new YamlSnakeYamlConfigurer());
|
||||
it.withBindFile(dataDirectory.resolve("config.yml"));
|
||||
it.withRemoveOrphans(true);
|
||||
it.saveDefaults();
|
||||
it.load(true);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package dev.xhyrom.lighteco.currency.money.common;
|
||||
|
||||
import dev.xhyrom.lighteco.currency.money.common.config.Config;
|
||||
|
||||
public interface Plugin {
|
||||
void load();
|
||||
|
||||
Config getConfig();
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package dev.xhyrom.lighteco.currency.money.common.config;
|
||||
|
||||
import eu.okaeri.configs.OkaeriConfig;
|
||||
import eu.okaeri.configs.annotation.Comment;
|
||||
|
||||
public class Config extends OkaeriConfig {
|
||||
@Comment("Currency name")
|
||||
|
||||
@Comment("In singular form")
|
||||
public String currencyNameSingular = "Dollar";
|
||||
@Comment("In plural form")
|
||||
public String currencyNamePlural = "Dollars";
|
||||
|
||||
@Comment("Currency code (ISO 4217 code of currency)")
|
||||
@Comment("Used for formatting currency")
|
||||
@Comment("See https://en.wikipedia.org/wiki/ISO_4217 for more information")
|
||||
public String currencyCode = "USD";
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package dev.xhyrom.lighteco.currency.money.common;
|
||||
package dev.xhyrom.lighteco.currency.money.common.currency;
|
||||
|
||||
import dev.xhyrom.lighteco.api.model.currency.Currency;
|
||||
|
Loading…
Reference in a new issue