Improve softreload
All checks were successful
SteamWarCI Build successful

This commit is contained in:
2025-10-30 16:29:57 +01:00
parent 6d8c765483
commit 62c41cdda8
2 changed files with 19 additions and 0 deletions

View File

@ -122,6 +122,7 @@ public class Persistent {
container = proxy.getPluginManager().getPlugin("velocitycore").orElseThrow();
plugin = (ReloadablePlugin) container.getInstance().orElseThrow();
} catch (NoSuchElementException e) {
e.printStackTrace();
logger.log(Level.WARNING, "Could not find loaded VelocityCore, continuing without unloading.");
}
@ -129,6 +130,7 @@ public class Persistent {
try {
newContainer = prepareLoad();
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.SEVERE, "Could not instantiate new VelocityCore, aborting softreload.", e);
return Command.SINGLE_SUCCESS;
}
@ -136,13 +138,19 @@ public class Persistent {
broadcast("§eNetwork update is starting§8.");
try {
if(container != null && plugin != null) {
System.out.println("Proxy Shutdown Event");
plugin.onProxyShutdown(new ProxyShutdownEvent());
System.out.println("Unloading of Container");
unload(container, plugin);
}
System.out.println("Loading of new Container");
registerPlugin.invoke((VelocityPluginManager) proxy.getPluginManager(), newContainer);
System.out.println("Proxy Initialization Event");
((ReloadablePlugin) newContainer.getInstance().orElseThrow()).onProxyInitialization(new ProxyInitializeEvent());
System.out.println("Proxy Initialization Event finished");
} catch (Throwable t) {
t.printStackTrace();
logger.log(Level.SEVERE, "Error during softreload", t);
broadcast("§cNetwork update failed§8, §cexpect network restart soon§8.");
return Command.SINGLE_SUCCESS;

View File

@ -45,6 +45,7 @@ import de.steamwar.velocitycore.commands.ServerSwitchCommand;
import de.steamwar.velocitycore.commands.TeamCommand;
import de.steamwar.velocitycore.discord.DiscordBot;
import de.steamwar.velocitycore.discord.DiscordConfig;
import de.steamwar.velocitycore.listeners.BasicListener;
import de.steamwar.velocitycore.listeners.PollSystem;
import lombok.Getter;
import lombok.NonNull;
@ -171,6 +172,16 @@ public class VelocityCore implements ReloadablePlugin {
((PacketHandler) any).register();
}
}
@Override
protected void unlinkObject(Object any) {
if (any instanceof PacketHandler) {
((PacketHandler) any).unregister();
}
if (any instanceof BasicListener) {
VelocityCore.getProxy().getEventManager().unregisterListener(instance, any);
}
}
};
try {
linker.link();