More event wip

This commit is contained in:
Lukas Rieger (Blue) 2024-05-20 21:33:14 +02:00
parent bd93071d02
commit 648894ee26
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6

View File

@ -30,6 +30,10 @@
import de.bluecolored.bluemap.common.MissingResourcesException;
import de.bluecolored.bluemap.common.api.BlueMapAPIImpl;
import de.bluecolored.bluemap.common.config.*;
import de.bluecolored.bluemap.common.debug.StateDumper;
import de.bluecolored.bluemap.common.events.EventUtils;
import de.bluecolored.bluemap.common.events.PluginLifecycleEvent;
import de.bluecolored.bluemap.common.events.WebserverStartEvent;
import de.bluecolored.bluemap.common.live.LivePlayersDataSupplier;
import de.bluecolored.bluemap.common.plugin.skins.PlayerSkinUpdater;
import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;
@ -39,7 +43,6 @@
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
import de.bluecolored.bluemap.common.web.*;
import de.bluecolored.bluemap.common.web.http.HttpServer;
import de.bluecolored.bluemap.common.debug.StateDumper;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.map.BmMap;
import de.bluecolored.bluemap.core.metrics.Metrics;
@ -119,6 +122,9 @@ private void load(@Nullable ResourcePack preloadedResourcePack) throws IOExcepti
if (loaded) return;
unload(); //ensure nothing is left running (from a failed load or something)
// plugin pre load event
EventUtils.dispatch(PluginLifecycleEvent.Load.Pre.DISPATCHER, new PluginLifecycleEvent.Load.Pre(this));
//load configs
BlueMapConfigManager configManager = BlueMapConfigManager.builder()
.minecraftVersion(serverInterface.getMinecraftVersion())
@ -144,6 +150,12 @@ private void load(@Nullable ResourcePack preloadedResourcePack) throws IOExcepti
Logger.global.remove(DEBUG_FILE_LOG_NAME);
}
// plugin configuration event
EventUtils.dispatch(
PluginLifecycleEvent.Load.Configurations.DISPATCHER,
new PluginLifecycleEvent.Load.Configurations(this, configManager)
);
//load plugin state
try {
GsonConfigurationLoader loader = GsonConfigurationLoader.builder()
@ -231,6 +243,10 @@ private void load(@Nullable ResourcePack preloadedResourcePack) throws IOExcepti
webserverConfig.resolveIp(),
webserverConfig.getPort()
));
// webserver start event
EventUtils.dispatch(WebserverStartEvent.DISPATCHER, new WebserverStartEvent(webServer, routingRequestHandler));
webServer.start();
} catch (UnknownHostException ex) {
throw new ConfigurationException("BlueMap failed to resolve the ip in your webserver-config.\n" +
@ -374,6 +390,10 @@ public void run() {
//done
loaded = true;
// plugin post load event
EventUtils.dispatch(PluginLifecycleEvent.Load.Post.DISPATCHER, new PluginLifecycleEvent.Load.Post(this));
}
} catch (ConfigurationException ex) {
Logger.global.logWarning(ex.getFormattedExplanation());
@ -395,6 +415,9 @@ public void unload(boolean keepWebserver) {
try {
synchronized (this) {
// plugin pre unload event
EventUtils.dispatch(PluginLifecycleEvent.Unload.Pre.DISPATCHER, new PluginLifecycleEvent.Unload.Pre(this));
//disable api
if (api != null) api.unregister();
api = null;
@ -474,6 +497,10 @@ public void unload(boolean keepWebserver) {
//done
loaded = false;
// plugin post unload event
EventUtils.dispatch(PluginLifecycleEvent.Unload.Post.DISPATCHER, new PluginLifecycleEvent.Unload.Post(this));
}
} finally {
loadingLock.unlock();
@ -513,6 +540,9 @@ public void lightReload() throws IOException {
public synchronized void save() {
if (blueMap == null) return;
// plugin save event
EventUtils.dispatch(PluginLifecycleEvent.Save.DISPATCHER, new PluginLifecycleEvent.Save(this));
if (pluginState != null) {
try {
GsonConfigurationLoader loader = GsonConfigurationLoader.builder()