mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-22 06:51:05 +01:00
feat: command manager [WIP]
must finish this
This commit is contained in:
parent
7a58f7fbea
commit
b9c7b9eb88
15 changed files with 125 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
package dev.xhyrom.lighteco.api;
|
package dev.xhyrom.lighteco.api;
|
||||||
|
|
||||||
|
import dev.xhyrom.lighteco.api.manager.CommandManager;
|
||||||
import dev.xhyrom.lighteco.api.manager.CurrencyManager;
|
import dev.xhyrom.lighteco.api.manager.CurrencyManager;
|
||||||
import dev.xhyrom.lighteco.api.manager.UserManager;
|
import dev.xhyrom.lighteco.api.manager.UserManager;
|
||||||
import dev.xhyrom.lighteco.api.platform.Platform;
|
import dev.xhyrom.lighteco.api.platform.Platform;
|
||||||
|
@ -18,6 +19,7 @@ public interface LightEco {
|
||||||
@NonNull UserManager getUserManager();
|
@NonNull UserManager getUserManager();
|
||||||
|
|
||||||
@NonNull CurrencyManager getCurrencyManager();
|
@NonNull CurrencyManager getCurrencyManager();
|
||||||
|
@NonNull CommandManager getCommandManager();
|
||||||
|
|
||||||
<T> @NonNull PlayerAdapter<T> getPlayerAdapter(@NonNull Class<T> playerClass);
|
<T> @NonNull PlayerAdapter<T> getPlayerAdapter(@NonNull Class<T> playerClass);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package dev.xhyrom.lighteco.api.manager;
|
||||||
|
|
||||||
|
import dev.xhyrom.lighteco.api.model.currency.Currency;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
public interface CommandManager {
|
||||||
|
void registerCurrencyCommand(@NonNull Currency currency);
|
||||||
|
}
|
|
@ -9,6 +9,8 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":lighteco-common"))
|
implementation(project(":lighteco-common"))
|
||||||
|
|
||||||
|
implementation("dev.jorel:commandapi-bukkit-shade:9.1.0")
|
||||||
|
|
||||||
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok:1.18.28")
|
compileOnly("org.projectlombok:lombok:1.18.28")
|
||||||
|
@ -17,3 +19,7 @@ dependencies {
|
||||||
compileOnly("org.checkerframework:checker-qual:3.8.0")
|
compileOnly("org.checkerframework:checker-qual:3.8.0")
|
||||||
compileOnly("org.jetbrains:annotations:20.1.0")
|
compileOnly("org.jetbrains:annotations:20.1.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.shadowJar {
|
||||||
|
relocate("dev.jorel.commandapi", "dev.xhyrom.lighteco.libraries.commandapi")
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package dev.xhyrom.lighteco.bukkit;
|
package dev.xhyrom.lighteco.bukkit;
|
||||||
|
|
||||||
|
import dev.jorel.commandapi.CommandAPI;
|
||||||
|
import dev.jorel.commandapi.CommandAPIBukkitConfig;
|
||||||
import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap;
|
import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
@ -12,16 +14,19 @@ public class BukkitLightEcoLoader extends JavaPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
|
CommandAPI.onLoad(new CommandAPIBukkitConfig(this).verboseOutput(true));
|
||||||
this.bootstrap.onLoad();
|
this.bootstrap.onLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
CommandAPI.onEnable();
|
||||||
this.bootstrap.onEnable();
|
this.bootstrap.onEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
CommandAPI.onDisable();
|
||||||
this.bootstrap.onDisable();
|
this.bootstrap.onDisable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import dev.xhyrom.lighteco.api.LightEco;
|
||||||
import dev.xhyrom.lighteco.api.manager.ContextManager;
|
import dev.xhyrom.lighteco.api.manager.ContextManager;
|
||||||
import dev.xhyrom.lighteco.api.platform.Platform;
|
import dev.xhyrom.lighteco.api.platform.Platform;
|
||||||
import dev.xhyrom.lighteco.bukkit.listeners.BukkitConnectionListener;
|
import dev.xhyrom.lighteco.bukkit.listeners.BukkitConnectionListener;
|
||||||
|
import dev.xhyrom.lighteco.bukkit.manager.BukkitCommandManager;
|
||||||
import dev.xhyrom.lighteco.bukkit.manager.BukkitContextManager;
|
import dev.xhyrom.lighteco.bukkit.manager.BukkitContextManager;
|
||||||
import dev.xhyrom.lighteco.common.manager.currency.StandardCurrencyManager;
|
import dev.xhyrom.lighteco.common.manager.currency.StandardCurrencyManager;
|
||||||
import dev.xhyrom.lighteco.common.plugin.AbstractLightEcoPlugin;
|
import dev.xhyrom.lighteco.common.plugin.AbstractLightEcoPlugin;
|
||||||
|
@ -22,6 +23,8 @@ public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin {
|
||||||
@Getter
|
@Getter
|
||||||
private StandardCurrencyManager currencyManager;
|
private StandardCurrencyManager currencyManager;
|
||||||
@Getter
|
@Getter
|
||||||
|
private BukkitCommandManager commandManager;
|
||||||
|
@Getter
|
||||||
private ContextManager<Player> contextManager;
|
private ContextManager<Player> contextManager;
|
||||||
|
|
||||||
public BukkitLightEcoPlugin(BukkitLightEcoBootstrap bootstrap) {
|
public BukkitLightEcoPlugin(BukkitLightEcoBootstrap bootstrap) {
|
||||||
|
@ -37,6 +40,7 @@ public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin {
|
||||||
public void setupManagers() {
|
public void setupManagers() {
|
||||||
this.userManager = new StandardUserManager(this);
|
this.userManager = new StandardUserManager(this);
|
||||||
this.currencyManager = new StandardCurrencyManager(this);
|
this.currencyManager = new StandardCurrencyManager(this);
|
||||||
|
this.commandManager = new BukkitCommandManager(this);
|
||||||
this.contextManager = new BukkitContextManager();
|
this.contextManager = new BukkitContextManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package dev.xhyrom.lighteco.bukkit.manager;
|
||||||
|
|
||||||
|
import dev.jorel.commandapi.CommandAPICommand;
|
||||||
|
import dev.xhyrom.lighteco.common.manager.command.AbstractCommandManager;
|
||||||
|
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||||
|
import dev.xhyrom.lighteco.common.model.user.User;
|
||||||
|
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
public class BukkitCommandManager extends AbstractCommandManager {
|
||||||
|
public BukkitCommandManager(LightEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerCurrencyCommand(@NonNull Currency currency) {
|
||||||
|
new CommandAPICommand(currency.getIdentifier())
|
||||||
|
.withPermission("lighteco.command.balance." + currency.getIdentifier())
|
||||||
|
.executesPlayer((sender, args) -> {
|
||||||
|
User user = this.plugin.getUserManager().getIfLoaded(sender.getUniqueId());
|
||||||
|
|
||||||
|
this.onBalance(user, currency);
|
||||||
|
})
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,6 +33,8 @@ public class TestPlugin extends JavaPlugin implements Listener {
|
||||||
currencyManager.getRegisteredCurrencies().forEach(currency -> {
|
currencyManager.getRegisteredCurrencies().forEach(currency -> {
|
||||||
getLogger().info("Currency: " + currency.getIdentifier() + " (" + currency.getType() + ", " + currency.getDecimalPlaces() + ", " + currency.isPayable() + ")");
|
getLogger().info("Currency: " + currency.getIdentifier() + " (" + currency.getType() + ", " + currency.getDecimalPlaces() + ", " + currency.isPayable() + ")");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
provider.getCommandManager().registerCurrencyCommand(currencyManager.getCurrency("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package dev.xhyrom.lighteco.common.api;
|
package dev.xhyrom.lighteco.common.api;
|
||||||
|
|
||||||
import dev.xhyrom.lighteco.api.LightEco;
|
import dev.xhyrom.lighteco.api.LightEco;
|
||||||
|
import dev.xhyrom.lighteco.api.manager.CommandManager;
|
||||||
import dev.xhyrom.lighteco.api.manager.CurrencyManager;
|
import dev.xhyrom.lighteco.api.manager.CurrencyManager;
|
||||||
import dev.xhyrom.lighteco.api.manager.UserManager;
|
import dev.xhyrom.lighteco.api.manager.UserManager;
|
||||||
import dev.xhyrom.lighteco.api.platform.Platform;
|
import dev.xhyrom.lighteco.api.platform.Platform;
|
||||||
import dev.xhyrom.lighteco.api.platform.PlayerAdapter;
|
import dev.xhyrom.lighteco.api.platform.PlayerAdapter;
|
||||||
import dev.xhyrom.lighteco.common.api.impl.ApiCurrencyManager;
|
import dev.xhyrom.lighteco.common.api.impl.*;
|
||||||
import dev.xhyrom.lighteco.common.api.impl.ApiUserManager;
|
|
||||||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||||
import dev.xhyrom.lighteco.common.api.impl.ApiPlatform;
|
|
||||||
import dev.xhyrom.lighteco.common.api.impl.ApiPlayerAdapter;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class LightEcoApi implements LightEco {
|
public class LightEcoApi implements LightEco {
|
||||||
|
@ -18,6 +16,7 @@ public class LightEcoApi implements LightEco {
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
private final UserManager userManager;
|
private final UserManager userManager;
|
||||||
private final CurrencyManager currencyManager;
|
private final CurrencyManager currencyManager;
|
||||||
|
private final CommandManager commandManager;
|
||||||
private final PlayerAdapter<?> playerAdapter;
|
private final PlayerAdapter<?> playerAdapter;
|
||||||
|
|
||||||
public LightEcoApi(LightEcoPlugin plugin) {
|
public LightEcoApi(LightEcoPlugin plugin) {
|
||||||
|
@ -26,6 +25,7 @@ public class LightEcoApi implements LightEco {
|
||||||
this.platform = new ApiPlatform(plugin);
|
this.platform = new ApiPlatform(plugin);
|
||||||
this.userManager = new ApiUserManager(plugin, plugin.getUserManager());
|
this.userManager = new ApiUserManager(plugin, plugin.getUserManager());
|
||||||
this.currencyManager = new ApiCurrencyManager(plugin, plugin.getCurrencyManager());
|
this.currencyManager = new ApiCurrencyManager(plugin, plugin.getCurrencyManager());
|
||||||
|
this.commandManager = new ApiCommandManager(plugin, plugin.getCommandManager());
|
||||||
this.playerAdapter = new ApiPlayerAdapter<>(userManager, plugin.getContextManager());
|
this.playerAdapter = new ApiPlayerAdapter<>(userManager, plugin.getContextManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,11 @@ public class LightEcoApi implements LightEco {
|
||||||
return this.currencyManager;
|
return this.currencyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull CommandManager getCommandManager() {
|
||||||
|
return this.commandManager;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull <T> PlayerAdapter<T> getPlayerAdapter(@NonNull Class<T> playerClass) {
|
public @NonNull <T> PlayerAdapter<T> getPlayerAdapter(@NonNull Class<T> playerClass) {
|
||||||
Class<?> expected = this.plugin.getContextManager().getPlayerClass();
|
Class<?> expected = this.plugin.getContextManager().getPlayerClass();
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package dev.xhyrom.lighteco.common.api.impl;
|
||||||
|
|
||||||
|
import dev.xhyrom.lighteco.api.manager.CommandManager;
|
||||||
|
import dev.xhyrom.lighteco.api.model.currency.Currency;
|
||||||
|
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
public class ApiCommandManager extends ApiAbstractManager<dev.xhyrom.lighteco.common.manager.command.CommandManager> implements CommandManager {
|
||||||
|
public ApiCommandManager(LightEcoPlugin plugin, dev.xhyrom.lighteco.common.manager.command.CommandManager handler) {
|
||||||
|
super(plugin, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerCurrencyCommand(@NonNull Currency currency) {
|
||||||
|
dev.xhyrom.lighteco.common.model.currency.Currency internal = this.plugin.getCurrencyManager().getIfLoaded(currency.getIdentifier());
|
||||||
|
|
||||||
|
this.handler.registerCurrencyCommand(internal);
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import eu.okaeri.configs.annotation.Comment;
|
||||||
import eu.okaeri.configs.annotation.Header;
|
import eu.okaeri.configs.annotation.Header;
|
||||||
|
|
||||||
@Header("LightEco configuration file.")
|
@Header("LightEco configuration file.")
|
||||||
|
@Header("")
|
||||||
public class Config extends OkaeriConfig {
|
public class Config extends OkaeriConfig {
|
||||||
@Comment("This property must be unique for each server.")
|
@Comment("This property must be unique for each server.")
|
||||||
@Comment("If you have multiple servers, you must set this property to a different value for each server.")
|
@Comment("If you have multiple servers, you must set this property to a different value for each server.")
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package dev.xhyrom.lighteco.common.manager.command;
|
||||||
|
|
||||||
|
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||||
|
import dev.xhyrom.lighteco.common.model.user.User;
|
||||||
|
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public abstract class AbstractCommandManager implements CommandManager {
|
||||||
|
protected final LightEcoPlugin plugin;
|
||||||
|
|
||||||
|
public AbstractCommandManager(LightEcoPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBalance(User sender, Currency currency) {
|
||||||
|
BigDecimal balance = sender.getBalance(currency);
|
||||||
|
|
||||||
|
System.out.println("Your balance: " + balance.toPlainString() + " " + currency.getIdentifier());
|
||||||
|
//sender.sendMessage("&aYour balance: &e" + balance.toPlainString() + " &a" + currency.getIdentifier() + "&r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package dev.xhyrom.lighteco.common.manager.command;
|
||||||
|
|
||||||
|
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||||
|
import dev.xhyrom.lighteco.common.model.user.User;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
public interface CommandManager {
|
||||||
|
void registerCurrencyCommand(@NonNull Currency currency);
|
||||||
|
|
||||||
|
void onBalance(User sender, Currency currency);
|
||||||
|
}
|
|
@ -9,8 +9,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class User {
|
public class User {
|
||||||
@Getter
|
|
||||||
private final LightEcoPlugin plugin;
|
private final LightEcoPlugin plugin;
|
||||||
@Getter
|
@Getter
|
||||||
private final ApiUser proxy = new ApiUser(this);
|
private final ApiUser proxy = new ApiUser(this);
|
||||||
|
|
|
@ -16,6 +16,8 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin {
|
||||||
@Getter
|
@Getter
|
||||||
private Storage storage;
|
private Storage storage;
|
||||||
private LightEcoApi api;
|
private LightEcoApi api;
|
||||||
|
@Getter
|
||||||
|
private Config config;
|
||||||
|
|
||||||
public final void load() {
|
public final void load() {
|
||||||
Config config = ConfigManager.create(Config.class, (it) -> {
|
Config config = ConfigManager.create(Config.class, (it) -> {
|
||||||
|
@ -28,6 +30,8 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin {
|
||||||
it.saveDefaults();
|
it.saveDefaults();
|
||||||
it.load(true);
|
it.load(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void enable() {
|
public final void enable() {
|
||||||
|
|
|
@ -2,6 +2,8 @@ package dev.xhyrom.lighteco.common.plugin;
|
||||||
|
|
||||||
import dev.xhyrom.lighteco.api.manager.ContextManager;
|
import dev.xhyrom.lighteco.api.manager.ContextManager;
|
||||||
import dev.xhyrom.lighteco.api.platform.Platform;
|
import dev.xhyrom.lighteco.api.platform.Platform;
|
||||||
|
import dev.xhyrom.lighteco.common.config.Config;
|
||||||
|
import dev.xhyrom.lighteco.common.manager.command.CommandManager;
|
||||||
import dev.xhyrom.lighteco.common.manager.currency.CurrencyManager;
|
import dev.xhyrom.lighteco.common.manager.currency.CurrencyManager;
|
||||||
import dev.xhyrom.lighteco.common.manager.user.UserManager;
|
import dev.xhyrom.lighteco.common.manager.user.UserManager;
|
||||||
import dev.xhyrom.lighteco.common.plugin.bootstrap.LightEcoBootstrap;
|
import dev.xhyrom.lighteco.common.plugin.bootstrap.LightEcoBootstrap;
|
||||||
|
@ -13,8 +15,10 @@ public interface LightEcoPlugin {
|
||||||
|
|
||||||
@NonNull LightEcoBootstrap getBootstrap();
|
@NonNull LightEcoBootstrap getBootstrap();
|
||||||
|
|
||||||
|
@NonNull Config getConfig();
|
||||||
@NonNull UserManager getUserManager();
|
@NonNull UserManager getUserManager();
|
||||||
@NonNull CurrencyManager getCurrencyManager();
|
@NonNull CurrencyManager getCurrencyManager();
|
||||||
|
@NonNull CommandManager getCommandManager();
|
||||||
@NonNull ContextManager<?> getContextManager();
|
@NonNull ContextManager<?> getContextManager();
|
||||||
|
|
||||||
@NonNull Storage getStorage();
|
@NonNull Storage getStorage();
|
||||||
|
|
Loading…
Reference in a new issue