🐛 Fixed async shutdown task exception, closes #60
This commit is contained in:
parent
6edbce3689
commit
9cbfbb6f27
3 changed files with 11 additions and 24 deletions
|
@ -123,7 +123,7 @@ public class V10LiftPlugin extends JavaPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
dbManager.save(true);
|
dbManager.save();
|
||||||
dbManager.closeConnection();
|
dbManager.closeConnection();
|
||||||
|
|
||||||
instance = null;
|
instance = null;
|
||||||
|
|
|
@ -361,7 +361,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
DataManager.clearMovingTasks();
|
DataManager.clearMovingTasks();
|
||||||
V10LiftPlugin.getSConfig().reloadConfig();
|
V10LiftPlugin.getSConfig().reloadConfig();
|
||||||
try {
|
try {
|
||||||
V10LiftPlugin.getDBManager().save(true);
|
V10LiftPlugin.getDBManager().save();
|
||||||
V10LiftPlugin.getDBManager().load();
|
V10LiftPlugin.getDBManager().load();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -955,7 +955,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
||||||
DataManager.removeDoorEditPlayer(p.getUniqueId());
|
DataManager.removeDoorEditPlayer(p.getUniqueId());
|
||||||
|
|
||||||
V10LiftPlugin.getDBManager().saveLift(liftName, lift);
|
V10LiftPlugin.getDBManager().saveLift(liftName, lift, false);
|
||||||
|
|
||||||
BlockState bs;
|
BlockState bs;
|
||||||
Sign sign;
|
Sign sign;
|
||||||
|
|
|
@ -93,27 +93,10 @@ public class DBManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save all lifts to data
|
* Save all lifts to data
|
||||||
* This is done async
|
|
||||||
*/
|
*/
|
||||||
public void save() {
|
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()) {
|
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||||
saveLift(entry.getKey(), entry.getValue());
|
saveLift(entry.getKey(), entry.getValue(), true);
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
|
||||||
saveLift(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,12 +106,16 @@ public class DBManager {
|
||||||
* @param liftName The name of the lift
|
* @param liftName The name of the lift
|
||||||
* @param lift The lift itself
|
* @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...");
|
Bukkit.getLogger().info("[V10Lift] Saving lift " + liftName + " to data...");
|
||||||
|
|
||||||
byte[] blob = gson.toJson(lift).getBytes();
|
byte[] blob = gson.toJson(lift).getBytes();
|
||||||
|
if (sync) {
|
||||||
|
updateLift(liftName, blob);
|
||||||
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> updateLift(liftName, blob));
|
Bukkit.getScheduler().runTaskAsynchronously(V10LiftPlugin.getInstance(), () -> updateLift(liftName, blob));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a lift in data
|
* Update a lift in data
|
||||||
|
|
Loading…
Reference in a new issue