mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-22 06:51: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
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {}
|
||||||
plugin.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,6 @@ public class StandardUserManager extends AbstractManager<UUID, User> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidateCaches() {
|
public void invalidateCaches() {
|
||||||
|
values().forEach(User::invalidateCaches);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue