mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-25 00:01:05 +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:
parent
2b274497a7
commit
0cd5f08949
7 changed files with 26 additions and 10 deletions
|
@ -27,9 +27,7 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
plugin.load();
|
||||
}
|
||||
public void onLoad() {}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.xhyrom.lighteco.bukkit;
|
||||
|
||||
import dev.xhyrom.lighteco.api.LightEco;
|
||||
import dev.xhyrom.lighteco.api.managers.ContextManager;
|
||||
import dev.xhyrom.lighteco.api.platform.Platform;
|
||||
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 lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin {
|
||||
|
@ -38,6 +40,11 @@ public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin {
|
|||
this.contextManager = new BukkitContextManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerApiOnPlatform(LightEco api) {
|
||||
this.getBootstrap().getServer().getServicesManager().register(LightEco.class, api, this.getBootstrap().getLoader(), ServicePriority.Normal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Platform.@NonNull Type getPlatformType() {
|
||||
return Platform.Type.BUKKIT;
|
||||
|
|
|
@ -4,6 +4,7 @@ version: ${version}
|
|||
main: dev.xhyrom.lighteco.bukkit.BukkitLightEcoLoader
|
||||
author: ${author}
|
||||
api-version: 1.20
|
||||
load: STARTUP
|
||||
|
||||
softdepend:
|
||||
- Vault
|
|
@ -17,4 +17,8 @@ public class TypedMap<T> {
|
|||
public <V> void put(T key, V value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,6 @@ public class StandardUserManager extends AbstractManager<UUID, User> implements
|
|||
|
||||
@Override
|
||||
public void invalidateCaches() {
|
||||
|
||||
values().forEach(User::invalidateCaches);
|
||||
}
|
||||
}
|
|
@ -33,4 +33,8 @@ public class User {
|
|||
public <T> void setBalance(@NonNull Currency<?> currency, @NonNull T balance) {
|
||||
balances.put(currency, balance);
|
||||
}
|
||||
|
||||
public void invalidateCaches() {
|
||||
balances.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.xhyrom.lighteco.common.plugin;
|
||||
|
||||
import dev.xhyrom.lighteco.api.LightEco;
|
||||
import dev.xhyrom.lighteco.api.LightEcoProvider;
|
||||
import dev.xhyrom.lighteco.common.api.LightEcoApi;
|
||||
import dev.xhyrom.lighteco.common.storage.Storage;
|
||||
|
@ -11,24 +12,25 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin {
|
|||
private Storage storage;
|
||||
private LightEcoApi api;
|
||||
|
||||
public final void load() {
|
||||
public final void enable() {
|
||||
// setup storage
|
||||
StorageFactory factory = new StorageFactory(this);
|
||||
this.storage = factory.get();
|
||||
|
||||
// register listeners
|
||||
this.registerListeners();
|
||||
|
||||
// setup managers
|
||||
this.setupManagers();
|
||||
|
||||
// register api
|
||||
this.api = new LightEcoApi(this);
|
||||
LightEcoProvider.set(this.api);
|
||||
}
|
||||
|
||||
public final void enable() {
|
||||
// register listeners
|
||||
this.registerListeners();
|
||||
this.registerApiOnPlatform(this.api);
|
||||
}
|
||||
|
||||
protected abstract void registerListeners();
|
||||
|
||||
protected abstract void setupManagers();
|
||||
protected abstract void registerApiOnPlatform(LightEco api);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue