Optimizations and potentially fixing a ConcurrentModificationException involving the TransientEntityTracker

Fixes #4368
This commit is contained in:
nossr50
2021-01-01 14:04:36 -08:00
parent 959d1e4a05
commit fbecbc167a
6 changed files with 144 additions and 49 deletions

View File

@@ -88,6 +88,7 @@ public class mcMMO extends JavaPlugin {
private static ChatManager chatManager;
private static CommandManager commandManager; //ACF
private static TransientEntityTracker transientEntityTracker;
private static boolean serverShutdownExecuted = false;
/* Adventure */
private static BukkitAudiences audiences;
@@ -292,6 +293,7 @@ public class mcMMO extends JavaPlugin {
commandManager = new CommandManager(this);
transientEntityTracker = new TransientEntityTracker();
setServerShutdown(false); //Reset flag, used to make decisions about async saves
}
public static PlayerLevelUtils getPlayerLevelUtils() {
@@ -327,6 +329,10 @@ public class mcMMO extends JavaPlugin {
*/
@Override
public void onDisable() {
setServerShutdown(true);
//TODO: Write code to catch unfinished async save tasks, for now we just hope they finish in time, which they should in most cases
mcMMO.p.getLogger().info("Server shutdown has been executed, saving and cleaning up data...");
try {
UserManager.saveAll(); // Make sure to save player information if the server shuts down
UserManager.clearAll();
@@ -345,11 +351,6 @@ public class mcMMO extends JavaPlugin {
catch (Exception e) { e.printStackTrace(); }
debug("Canceling all tasks...");
getServer().getScheduler().cancelTasks(this); // This removes our tasks
debug("Unregister all events...");
HandlerList.unregisterAll(this); // Cancel event registrations
if (Config.getInstance().getBackupsEnabled()) {
// Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
try {
@@ -369,6 +370,11 @@ public class mcMMO extends JavaPlugin {
}
}
debug("Canceling all tasks...");
getServer().getScheduler().cancelTasks(this); // This removes our tasks
debug("Unregister all events...");
HandlerList.unregisterAll(this); // Cancel event registrations
databaseManager.onDisable();
debug("Was disabled."); // How informative!
}
@@ -727,4 +733,13 @@ public class mcMMO extends JavaPlugin {
public static TransientEntityTracker getTransientEntityTracker() {
return transientEntityTracker;
}
public static synchronized boolean isServerShutdownExecuted() {
return serverShutdownExecuted;
}
private static synchronized void setServerShutdown(boolean bool) {
serverShutdownExecuted = bool;
}
}