🐛 Fixed async shutdown task exception, closes #60

This commit is contained in:
stijnb1234 2022-06-15 11:14:15 +02:00
parent 6edbce3689
commit 9cbfbb6f27
3 changed files with 11 additions and 24 deletions

View file

@ -123,7 +123,7 @@ public class V10LiftPlugin extends JavaPlugin {
@Override
public void onDisable() {
dbManager.save(true);
dbManager.save();
dbManager.closeConnection();
instance = null;

View file

@ -361,7 +361,7 @@ public class V10LiftCommand implements CommandExecutor {
DataManager.clearMovingTasks();
V10LiftPlugin.getSConfig().reloadConfig();
try {
V10LiftPlugin.getDBManager().save(true);
V10LiftPlugin.getDBManager().save();
V10LiftPlugin.getDBManager().load();
} catch (SQLException e) {
e.printStackTrace();
@ -955,7 +955,7 @@ public class V10LiftCommand implements CommandExecutor {
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
DataManager.removeDoorEditPlayer(p.getUniqueId());
V10LiftPlugin.getDBManager().saveLift(liftName, lift);
V10LiftPlugin.getDBManager().saveLift(liftName, lift, false);
BlockState bs;
Sign sign;

View file

@ -93,27 +93,10 @@ public class DBManager {
/**
* Save all lifts to data
* This is done async
*/
public void save() {
save(false);
}
/**
* Save all lifts to data
* @param force true if sync, false if async
*/
public void save(boolean force) {
if (!force) {
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> {
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
saveLift(entry.getKey(), entry.getValue());
}
});
} else {
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
saveLift(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
saveLift(entry.getKey(), entry.getValue(), true);
}
}
@ -123,11 +106,15 @@ public class DBManager {
* @param liftName The name of the lift
* @param lift The lift itself
*/
public void saveLift(String liftName, Lift lift) {
public void saveLift(String liftName, Lift lift, boolean sync) {
Bukkit.getLogger().info("[V10Lift] Saving lift " + liftName + " to data...");
byte[] blob = gson.toJson(lift).getBytes();
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> updateLift(liftName, blob));
if (sync) {
updateLift(liftName, blob);
} else {
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> updateLift(liftName, blob));
}
}
/**