1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-11-10 01:18:07 +01:00

feat: register api on platform, load managers, listeners in enable(), load at startup

register api on platform - bukkit with ServicesManager
This commit is contained in:
xHyroM 2023-08-03 22:29:54 +02:00
parent 2b274497a7
commit 0cd5f08949
No known key found for this signature in database
GPG key ID: BE0423F386C436AA
7 changed files with 26 additions and 10 deletions

View file

@ -27,9 +27,7 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
} }
@Override @Override
public void onLoad() { public void onLoad() {}
plugin.load();
}
@Override @Override
public void onEnable() { public void onEnable() {

View file

@ -1,5 +1,6 @@
package dev.xhyrom.lighteco.bukkit; package dev.xhyrom.lighteco.bukkit;
import dev.xhyrom.lighteco.api.LightEco;
import dev.xhyrom.lighteco.api.managers.ContextManager; import dev.xhyrom.lighteco.api.managers.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;
@ -9,6 +10,7 @@ import dev.xhyrom.lighteco.common.plugin.AbstractLightEcoPlugin;
import dev.xhyrom.lighteco.common.managers.user.StandardUserManager; import dev.xhyrom.lighteco.common.managers.user.StandardUserManager;
import lombok.Getter; import lombok.Getter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.ServicePriority;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin { public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin {
@ -38,6 +40,11 @@ public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin {
this.contextManager = new BukkitContextManager(); this.contextManager = new BukkitContextManager();
} }
@Override
protected void registerApiOnPlatform(LightEco api) {
this.getBootstrap().getServer().getServicesManager().register(LightEco.class, api, this.getBootstrap().getLoader(), ServicePriority.Normal);
}
@Override @Override
public Platform.@NonNull Type getPlatformType() { public Platform.@NonNull Type getPlatformType() {
return Platform.Type.BUKKIT; return Platform.Type.BUKKIT;

View file

@ -4,6 +4,7 @@ version: ${version}
main: dev.xhyrom.lighteco.bukkit.BukkitLightEcoLoader main: dev.xhyrom.lighteco.bukkit.BukkitLightEcoLoader
author: ${author} author: ${author}
api-version: 1.20 api-version: 1.20
load: STARTUP
softdepend: softdepend:
- Vault - Vault

View file

@ -17,4 +17,8 @@ public class TypedMap<T> {
public <V> void put(T key, V value) { public <V> void put(T key, V value) {
map.put(key, value); map.put(key, value);
} }
public void clear() {
map.clear();
}
} }

View file

@ -33,6 +33,6 @@ public class StandardUserManager extends AbstractManager<UUID, User> implements
@Override @Override
public void invalidateCaches() { public void invalidateCaches() {
values().forEach(User::invalidateCaches);
} }
} }

View file

@ -33,4 +33,8 @@ public class User {
public <T> void setBalance(@NonNull Currency<?> currency, @NonNull T balance) { public <T> void setBalance(@NonNull Currency<?> currency, @NonNull T balance) {
balances.put(currency, balance); balances.put(currency, balance);
} }
public void invalidateCaches() {
balances.clear();
}
} }

View file

@ -1,5 +1,6 @@
package dev.xhyrom.lighteco.common.plugin; package dev.xhyrom.lighteco.common.plugin;
import dev.xhyrom.lighteco.api.LightEco;
import dev.xhyrom.lighteco.api.LightEcoProvider; import dev.xhyrom.lighteco.api.LightEcoProvider;
import dev.xhyrom.lighteco.common.api.LightEcoApi; import dev.xhyrom.lighteco.common.api.LightEcoApi;
import dev.xhyrom.lighteco.common.storage.Storage; import dev.xhyrom.lighteco.common.storage.Storage;
@ -11,24 +12,25 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin {
private Storage storage; private Storage storage;
private LightEcoApi api; private LightEcoApi api;
public final void load() { public final void enable() {
// setup storage // setup storage
StorageFactory factory = new StorageFactory(this); StorageFactory factory = new StorageFactory(this);
this.storage = factory.get(); this.storage = factory.get();
// register listeners
this.registerListeners();
// setup managers // setup managers
this.setupManagers(); this.setupManagers();
// register api // register api
this.api = new LightEcoApi(this); this.api = new LightEcoApi(this);
LightEcoProvider.set(this.api); LightEcoProvider.set(this.api);
} this.registerApiOnPlatform(this.api);
public final void enable() {
// register listeners
this.registerListeners();
} }
protected abstract void registerListeners(); protected abstract void registerListeners();
protected abstract void setupManagers(); protected abstract void setupManagers();
protected abstract void registerApiOnPlatform(LightEco api);
} }