From a99fb995e47eb2d469ebcf8b3cb9f1893949b99b Mon Sep 17 00:00:00 2001 From: xHyroM Date: Sun, 27 Aug 2023 13:59:35 +0200 Subject: [PATCH] feat: add currency-money addon --- .../lighteco/api/manager/CommandManager.java | 1 + .../kotlin/lighteco.addon-logic.gradle.kts | 13 ++++++ .../bukkit/manager/BukkitCommandManager.java | 20 +++++++-- bukkit/src/main/resources/plugin.yml | 5 +-- .../common/plugin/AbstractLightEcoPlugin.java | 4 +- currency-money/build.gradle.kts | 19 +++++++++ .../currency/money/bukkit/BukkitMCLoader.java | 24 +++++++++++ .../currency/money/bukkit/hooks/Vault.java | 4 ++ .../currency/money/common/MoneyCurrency.java | 32 ++++++++++++++ currency-money/src/main/resources/plugin.yml | 10 +++++ settings.gradle.kts | 4 +- velocity/.gitignore | 42 ------------------- velocity/build.gradle.kts | 3 -- velocity/src/main/java/dev/xhyrom/Main.java | 7 ---- 14 files changed, 123 insertions(+), 65 deletions(-) create mode 100644 buildSrc/src/main/kotlin/lighteco.addon-logic.gradle.kts create mode 100644 currency-money/build.gradle.kts create mode 100644 currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/BukkitMCLoader.java create mode 100644 currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/hooks/Vault.java create mode 100644 currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/common/MoneyCurrency.java create mode 100644 currency-money/src/main/resources/plugin.yml delete mode 100644 velocity/.gitignore delete mode 100644 velocity/build.gradle.kts delete mode 100644 velocity/src/main/java/dev/xhyrom/Main.java diff --git a/api/src/main/java/dev/xhyrom/lighteco/api/manager/CommandManager.java b/api/src/main/java/dev/xhyrom/lighteco/api/manager/CommandManager.java index ef3524a..34c0550 100644 --- a/api/src/main/java/dev/xhyrom/lighteco/api/manager/CommandManager.java +++ b/api/src/main/java/dev/xhyrom/lighteco/api/manager/CommandManager.java @@ -4,6 +4,7 @@ import dev.xhyrom.lighteco.api.model.currency.Currency; import org.checkerframework.checker.nullness.qual.NonNull; public interface CommandManager { + // Make more transparent and freedom way to do this (more abstract) void registerCurrencyCommand(@NonNull Currency currency); void registerCurrencyCommand(@NonNull Currency currency, boolean main); } diff --git a/buildSrc/src/main/kotlin/lighteco.addon-logic.gradle.kts b/buildSrc/src/main/kotlin/lighteco.addon-logic.gradle.kts new file mode 100644 index 0000000..600f2ff --- /dev/null +++ b/buildSrc/src/main/kotlin/lighteco.addon-logic.gradle.kts @@ -0,0 +1,13 @@ +plugins { + id("lighteco.shadow-logic") +} + +val Project.addon: String + get() = project.name.split("-").drop(1).joinToString("-") + +tasks { + shadowJar { + archiveFileName.set("lighteco-${project.addon}-${project.version}.jar") + destinationDirectory.set(rootProject.layout.buildDirectory.dir("libs/addons")) + } +} \ No newline at end of file diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/manager/BukkitCommandManager.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/manager/BukkitCommandManager.java index ec3d88d..6bd9651 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/manager/BukkitCommandManager.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/manager/BukkitCommandManager.java @@ -50,10 +50,22 @@ public class BukkitCommandManager extends AbstractCommandManager { String permissionBase = "lighteco.currency." + currency.getIdentifier() + ".command."; - new SetCommand(this, currency, permissionBase).build().register(); - new GiveCommand(this, currency, permissionBase).build().register(); - new TakeCommand(this, currency, permissionBase).build().register(); + // Dont expose set, give, take directly - only through main command + 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()); + new PayCommand(this, currency, permissionBase).build().register(); - new BalanceCommand(this, "balance", currency, permissionBase).build().register(); + + for (CommandAPICommand cmd : new BalanceCommand( + this, + "balance", + currency, + permissionBase + ).multipleBuild()) { + cmd.register(); + } + } } diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index e27365b..6a70396 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -4,7 +4,4 @@ version: ${version} main: dev.xhyrom.lighteco.bukkit.BukkitLightEcoLoader author: ${author} api-version: 1.20 -load: STARTUP - -softdepend: - - Vault \ No newline at end of file +load: STARTUP \ No newline at end of file diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/plugin/AbstractLightEcoPlugin.java b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/AbstractLightEcoPlugin.java index f449dc7..4c826d4 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/plugin/AbstractLightEcoPlugin.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/AbstractLightEcoPlugin.java @@ -20,7 +20,7 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin { private Config config; public final void load() { - Config config = ConfigManager.create(Config.class, (it) -> { + this.config = ConfigManager.create(Config.class, (it) -> { File path = new File(this.getBootstrap().getDataFolder(), "config.yml"); path.mkdir(); @@ -30,8 +30,6 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin { it.saveDefaults(); it.load(true); }); - - this.config = config; } public final void enable() { diff --git a/currency-money/build.gradle.kts b/currency-money/build.gradle.kts new file mode 100644 index 0000000..e03d77b --- /dev/null +++ b/currency-money/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("lighteco.addon-logic") +} + +repositories { + maven("https://repo.papermc.io/repository/maven-public/") +} + +dependencies { + compileOnly(project(":lighteco-api")) + + compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") + + 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") +} \ No newline at end of file diff --git a/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/BukkitMCLoader.java b/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/BukkitMCLoader.java new file mode 100644 index 0000000..f79f8c9 --- /dev/null +++ b/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/BukkitMCLoader.java @@ -0,0 +1,24 @@ +package dev.xhyrom.lighteco.currency.money.bukkit; + +import dev.xhyrom.lighteco.api.LightEco; +import dev.xhyrom.lighteco.api.LightEcoProvider; +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.common.MoneyCurrency; +import org.bukkit.plugin.java.JavaPlugin; + +public class BukkitMCLoader extends JavaPlugin { + @Override + public void onEnable() { + LightEco provider = LightEcoProvider.get(); + CurrencyManager currencyManager = provider.getCurrencyManager(); + CommandManager commandManager = provider.getCommandManager(); + + Currency currency = new MoneyCurrency(); + + currencyManager.registerCurrency(currency); + commandManager.registerCurrencyCommand(currency, true); + } +} + diff --git a/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/hooks/Vault.java b/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/hooks/Vault.java new file mode 100644 index 0000000..8dbf28c --- /dev/null +++ b/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/bukkit/hooks/Vault.java @@ -0,0 +1,4 @@ +package dev.xhyrom.lighteco.currency.money.bukkit.hooks; + +public class Vault { +} diff --git a/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/common/MoneyCurrency.java b/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/common/MoneyCurrency.java new file mode 100644 index 0000000..061ecbf --- /dev/null +++ b/currency-money/src/main/java/dev/xhyrom/lighteco/currency/money/common/MoneyCurrency.java @@ -0,0 +1,32 @@ +package dev.xhyrom.lighteco.currency.money.common; + +import dev.xhyrom.lighteco.api.model.currency.Currency; + +import java.math.BigDecimal; + +public class MoneyCurrency extends Currency { + @Override + public String getIdentifier() { + return "money"; + } + + @Override + public Type getType() { + return Type.LOCAL; + } + + @Override + public boolean isPayable() { + return true; + } + + @Override + public BigDecimal getDefaultBalance() { + return BigDecimal.ZERO; + } + + @Override + public int getDecimalPlaces() { + return 2; + } +} diff --git a/currency-money/src/main/resources/plugin.yml b/currency-money/src/main/resources/plugin.yml new file mode 100644 index 0000000..b5bdfbb --- /dev/null +++ b/currency-money/src/main/resources/plugin.yml @@ -0,0 +1,10 @@ +name: ${name} +description: ${description} +version: ${version} +main: dev.xhyrom.lighteco.currency.money.bukkit.BukkitMCLoader +author: ${author} +api-version: 1.20 + +softdepend: + - Vault + - lighteco-bukkit diff --git a/settings.gradle.kts b/settings.gradle.kts index b209b5a..2b839d4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,7 +5,7 @@ sequenceOf( "common", "bukkit", "bukkittest", - "velocity" + "currency-money" ).forEach { include("lighteco-$it") project(":lighteco-$it").projectDir = file(it) @@ -17,4 +17,4 @@ pluginManagement { mavenCentral() gradlePluginPortal() } -} \ No newline at end of file +} diff --git a/velocity/.gitignore b/velocity/.gitignore deleted file mode 100644 index b63da45..0000000 --- a/velocity/.gitignore +++ /dev/null @@ -1,42 +0,0 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/velocity/build.gradle.kts b/velocity/build.gradle.kts deleted file mode 100644 index 97e2d4e..0000000 --- a/velocity/build.gradle.kts +++ /dev/null @@ -1,3 +0,0 @@ -plugins { - id("lighteco.platform-logic") -} \ No newline at end of file diff --git a/velocity/src/main/java/dev/xhyrom/Main.java b/velocity/src/main/java/dev/xhyrom/Main.java deleted file mode 100644 index aec9966..0000000 --- a/velocity/src/main/java/dev/xhyrom/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.xhyrom; - -public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} \ No newline at end of file