Skip to content

Commit

Permalink
Fix errors on disable if plugin failed to load
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgeiss0702 committed Aug 24, 2022
1 parent 038167d commit 86156f3
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/main/java/us/ajg0702/leaderboards/LeaderboardPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,29 +204,34 @@ private Iterable<String> getSignPath(String end) {
@Override
public void onDisable() {
shuttingDown = true;
getContextLoader().checkReload(false);
if(getContextLoader() != null) getContextLoader().checkReload(false);
Bukkit.getScheduler().cancelTasks(this);
getTopManager().shutdown();
if(getTopManager() != null) getTopManager().shutdown();

if(getCache() != null) {
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.execute(() -> {
getLogger().info("Shutting down cache method..");
getCache().getMethod().shutdown();
getLogger().info("Cache method shut down");
});
executorService.shutdown();
try {
if (!executorService.awaitTermination(15, TimeUnit.SECONDS)) {
executorService.shutdownNow();
getLogger().warning("Cache took too long to shut down. Skipping it.");
}
}catch(InterruptedException ignored){}
}

ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.execute(() -> {
getLogger().info("Shutting down cache method..");
getCache().getMethod().shutdown();
getLogger().info("Cache method shut down");
});
executorService.shutdown();
try {
if (!executorService.awaitTermination(15, TimeUnit.SECONDS)) {
executorService.shutdownNow();
getLogger().warning("Cache took too long to shut down. Skipping it.");
}
}catch(InterruptedException ignored){}
getLogger().info("Killing remaining workers");
killWorkers(1000);
Debug.info("1st kill pass done, retrying for remaining");
killWorkers(5000);
getLogger().info("Remaining workers killed");

getLogger().info("ajLeaderboards v"+getDescription().getVersion()+" disabled.");

Bukkit.getScheduler().getActiveWorkers().forEach(bukkitWorker -> {
Debug.info("Active worker: "+bukkitWorker.getOwner().getDescription().getName()+" "+bukkitWorker.getTaskId());
for (StackTraceElement stackTraceElement : bukkitWorker.getThread().getStackTrace()) {
Expand Down

0 comments on commit 86156f3

Please sign in to comment.