Skip to content

Commit

Permalink
Add shutdown handling to sponge
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed May 22, 2023
1 parent 66d0b9f commit 85daac9
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sponge/src/main/java/net/william278/huskhomes/SpongeHuskHomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.spongepowered.api.event.lifecycle.ConstructPluginEvent;
import org.spongepowered.api.event.lifecycle.RegisterCommandEvent;
import org.spongepowered.api.event.lifecycle.StartedEngineEvent;
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
import org.spongepowered.api.network.EngineConnection;
import org.spongepowered.api.network.channel.ChannelBuf;
import org.spongepowered.api.network.channel.raw.RawDataChannel;
Expand Down Expand Up @@ -201,6 +202,17 @@ public void onServerStarted(final StartedEngineEvent<org.spongepowered.api.Serve
initialize("metrics", (plugin) -> this.registerMetrics(METRICS_ID));
}

@Listener
public void onShutdown(final StoppingEngineEvent<org.spongepowered.api.Server> event) {
if (database != null) {
database.terminate();
}
if (broker != null) {
broker.close();
}
cancelAllTasks();
}

@Listener
public void onRegisterCommands(final RegisterCommandEvent<Raw> event) {
initialize("commands", (plugin) -> this.commands = registerCommands(event));
Expand Down

0 comments on commit 85daac9

Please sign in to comment.