mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-10 01:18:07 +01:00
feat: unhook platform hooks
This commit is contained in:
parent
759140cf6f
commit
2452314fad
8 changed files with 65 additions and 8 deletions
|
@ -27,9 +27,6 @@ public class BukkitLightEcoLoader extends JavaPlugin {
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
CommandAPI.onEnable();
|
CommandAPI.onEnable();
|
||||||
this.bootstrap.onEnable();
|
this.bootstrap.onEnable();
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null)
|
|
||||||
new PlaceholderAPIExpansion(this.bootstrap.getPlugin()).register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,6 +3,7 @@ package dev.xhyrom.lighteco.bukkit;
|
||||||
import dev.xhyrom.lighteco.api.LightEco;
|
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.hooks.Hooks;
|
||||||
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.BukkitCommandManager;
|
||||||
import dev.xhyrom.lighteco.bukkit.manager.BukkitContextManager;
|
import dev.xhyrom.lighteco.bukkit.manager.BukkitContextManager;
|
||||||
|
@ -12,7 +13,6 @@ import dev.xhyrom.lighteco.common.manager.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.bukkit.plugin.ServicePriority;
|
||||||
import org.bukkit.plugin.java.PluginClassLoader;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -50,6 +50,16 @@ public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin {
|
||||||
this.getBootstrap().getServer().getServicesManager().register(LightEco.class, api, this.getBootstrap().getLoader(), ServicePriority.Normal);
|
this.getBootstrap().getServer().getServicesManager().register(LightEco.class, api, this.getBootstrap().getLoader(), ServicePriority.Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerPlatformHooks() {
|
||||||
|
Hooks.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void removePlatformHooks() {
|
||||||
|
Hooks.unregister();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Platform.@NonNull Type getPlatformType() {
|
public Platform.@NonNull Type getPlatformType() {
|
||||||
return Platform.Type.BUKKIT;
|
return Platform.Type.BUKKIT;
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package dev.xhyrom.lighteco.bukkit.hooks;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class Hooks {
|
||||||
|
private static PlaceholderAPIExpansion placeholderAPIExpansion;
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null)
|
||||||
|
placeholderAPIExpansion.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void unregister() {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null)
|
||||||
|
placeholderAPIExpansion.unregister();
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,5 +12,5 @@ public interface DependencyManager extends AutoCloseable {
|
||||||
ClassLoader obtainClassLoaderWith(Set<Dependency> dependencies);
|
ClassLoader obtainClassLoaderWith(Set<Dependency> dependencies);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void close() throws Exception;
|
void close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package dev.xhyrom.lighteco.common.dependencies;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.io.MoreFiles;
|
import com.google.common.io.MoreFiles;
|
||||||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||||
|
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
||||||
import dev.xhyrom.lighteco.common.util.URLClassLoaderAccess;
|
import dev.xhyrom.lighteco.common.util.URLClassLoaderAccess;
|
||||||
import dev.xhyrom.lighteco.common.storage.StorageType;
|
import dev.xhyrom.lighteco.common.storage.StorageType;
|
||||||
|
|
||||||
|
@ -22,11 +23,13 @@ public class DependencyManagerImpl implements DependencyManager {
|
||||||
private final EnumMap<Dependency, Path> loaded = new EnumMap<>(Dependency.class);
|
private final EnumMap<Dependency, Path> loaded = new EnumMap<>(Dependency.class);
|
||||||
private final Map<ImmutableSet<Dependency>, IsolatedClassLoader> loaders = new HashMap<>();
|
private final Map<ImmutableSet<Dependency>, IsolatedClassLoader> loaders = new HashMap<>();
|
||||||
|
|
||||||
|
private final PluginLogger logger;
|
||||||
private final DependencyRegistry registry;
|
private final DependencyRegistry registry;
|
||||||
private final Path cacheDirectory;
|
private final Path cacheDirectory;
|
||||||
private final URLClassLoaderAccess classLoader;
|
private final URLClassLoaderAccess classLoader;
|
||||||
|
|
||||||
public DependencyManagerImpl(LightEcoPlugin plugin) {
|
public DependencyManagerImpl(LightEcoPlugin plugin) {
|
||||||
|
this.logger = plugin.getBootstrap().getLogger();
|
||||||
this.registry = new DependencyRegistry();
|
this.registry = new DependencyRegistry();
|
||||||
this.cacheDirectory = setupCacheDirectory(plugin);
|
this.cacheDirectory = setupCacheDirectory(plugin);
|
||||||
this.classLoader = URLClassLoaderAccess.create((URLClassLoader) plugin.getBootstrap().getClass().getClassLoader());
|
this.classLoader = URLClassLoaderAccess.create((URLClassLoader) plugin.getBootstrap().getClass().getClassLoader());
|
||||||
|
@ -159,7 +162,7 @@ public class DependencyManagerImpl implements DependencyManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
throw new RuntimeException(exception);
|
this.logger.error("Failed to close class loader", exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,9 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin {
|
||||||
// setup managers
|
// setup managers
|
||||||
this.setupManagers();
|
this.setupManagers();
|
||||||
|
|
||||||
|
// register platform hooks
|
||||||
|
this.registerPlatformHooks();
|
||||||
|
|
||||||
// register api
|
// register api
|
||||||
this.api = new LightEcoApi(this);
|
this.api = new LightEcoApi(this);
|
||||||
LightEcoProvider.set(this.api);
|
LightEcoProvider.set(this.api);
|
||||||
|
@ -63,13 +66,24 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void disable() {
|
public final void disable() {
|
||||||
this.userSaveTask.run(); // save all users synchronously
|
// save dirty users synchronously
|
||||||
|
this.userSaveTask.run();
|
||||||
|
|
||||||
|
// remove platform hooks
|
||||||
|
this.removePlatformHooks();
|
||||||
|
|
||||||
|
// shutdown storage
|
||||||
this.storage.shutdown();
|
this.storage.shutdown();
|
||||||
|
|
||||||
|
// close isolated class loaders
|
||||||
|
this.dependencyManager.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void registerListeners();
|
protected abstract void registerListeners();
|
||||||
|
|
||||||
protected abstract void setupManagers();
|
protected abstract void setupManagers();
|
||||||
protected abstract void registerApiOnPlatform(LightEco api);
|
protected abstract void registerApiOnPlatform(LightEco api);
|
||||||
|
|
||||||
|
protected abstract void registerPlatformHooks();
|
||||||
|
protected abstract void removePlatformHooks();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ import dev.xhyrom.lighteco.currency.money.common.MoneyCurrency;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class BukkitMCLoader extends JavaPlugin {
|
public class BukkitMCLoader extends JavaPlugin {
|
||||||
|
private VaultFactory vaultFactory;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
LightEco provider = LightEcoProvider.get();
|
LightEco provider = LightEcoProvider.get();
|
||||||
|
@ -23,8 +25,15 @@ public class BukkitMCLoader extends JavaPlugin {
|
||||||
|
|
||||||
if (getServer().getPluginManager().getPlugin("Vault") != null) {
|
if (getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||||
getSLF4JLogger().info("Vault found, hooking...");
|
getSLF4JLogger().info("Vault found, hooking...");
|
||||||
new VaultFactory(this).hook();
|
|
||||||
|
this.vaultFactory = new VaultFactory(this);
|
||||||
|
this.vaultFactory.hook();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
this.vaultFactory.unhook();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,4 +21,11 @@ public class VaultFactory {
|
||||||
ServicesManager manager = Bukkit.getServicesManager();
|
ServicesManager manager = Bukkit.getServicesManager();
|
||||||
manager.register(Economy.class, vault, this.plugin, ServicePriority.Highest);
|
manager.register(Economy.class, vault, this.plugin, ServicePriority.Highest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unhook() {
|
||||||
|
if (this.vault == null) return;
|
||||||
|
|
||||||
|
ServicesManager manager = Bukkit.getServicesManager();
|
||||||
|
manager.unregister(Economy.class, vault);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue