Skip to content

Commit

Permalink
Fix bluemap not stopping correctly when stopping the server
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Nov 23, 2019
1 parent 27d7f37 commit 4ed0731
Showing 1 changed file with 12 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ public synchronized void load() throws ExecutionException, IOException, NoSuchRe
handleMissingResources(defaultResourceFile, configFile);
unload();

//only register reload command
syncExecutor.submit(() -> //just to be save we do this on the server thread
Sponge.getCommandManager().register(this, new Commands(this).createStandaloneReloadCommand(), "bluemap")
).get();

Sponge.getCommandManager().register(this, new Commands(this).createStandaloneReloadCommand(), "bluemap");
return;
}

Expand Down Expand Up @@ -232,9 +228,7 @@ public synchronized void load() throws ExecutionException, IOException, NoSuchRe
}

//start map updater
syncExecutor.submit(() ->
this.updateHandler = new MapUpdateHandler()
).get();
this.updateHandler = new MapUpdateHandler();

//create/update webfiles
WebFilesManager webFilesManager = new WebFilesManager(config.getWebRoot());
Expand All @@ -261,9 +255,7 @@ public synchronized void load() throws ExecutionException, IOException, NoSuchRe
}

//init commands
syncExecutor.submit(() -> //just to be save we do this on the server thread
Sponge.getCommandManager().register(this, new Commands(this).createRootCommand(), "bluemap")
).get();
Sponge.getCommandManager().register(this, new Commands(this).createRootCommand(), "bluemap");

//metrics
Sponge.getScheduler().createTaskBuilder()
Expand All @@ -279,20 +271,14 @@ public synchronized void load() throws ExecutionException, IOException, NoSuchRe
}

public synchronized void unload() {
try {
syncExecutor.submit(() -> { //just to be save we do this on the server thread
//unregister commands
Sponge.getCommandManager().getOwnedBy(this).forEach(Sponge.getCommandManager()::removeMapping);
//unregister commands
Sponge.getCommandManager().getOwnedBy(this).forEach(Sponge.getCommandManager()::removeMapping);

//unregister listeners
if (updateHandler != null) Sponge.getEventManager().unregisterListeners(updateHandler);

//stop scheduled tasks
Sponge.getScheduler().getScheduledTasks(this).forEach(t -> t.cancel());
}).get();
} catch (InterruptedException | ExecutionException unexpected) {
throw new RuntimeException("Unexpected exception!", unexpected); //should never happen
}
//unregister listeners
if (updateHandler != null) Sponge.getEventManager().unregisterListeners(updateHandler);

//stop scheduled tasks
Sponge.getScheduler().getScheduledTasks(this).forEach(t -> t.cancel());

//stop services
if (renderManager != null) renderManager.stop();
Expand Down Expand Up @@ -354,10 +340,8 @@ public void onServerStart(GameStartingServerEvent evt) {

@Listener
public void onServerStop(GameStoppingEvent evt) {
asyncExecutor.execute(() -> {
unload();
Logger.global.logInfo("Saved and stopped!");
});
unload();
Logger.global.logInfo("Saved and stopped!");
}

@Listener
Expand Down

0 comments on commit 4ed0731

Please sign in to comment.