mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 05:28:59 +00:00
When unloading world, only save if it has data
This commit is contained in:
@@ -535,6 +535,13 @@ public class BCauldron {
|
|||||||
return bcauldrons.remove(block) != null;
|
return bcauldrons.remove(block) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are any Cauldrons in that World
|
||||||
|
*/
|
||||||
|
public static boolean hasDataInWorld(String name) {
|
||||||
|
return bcauldrons.keySet().stream().anyMatch(block -> block.getWorld().getName().equals(name));
|
||||||
|
}
|
||||||
|
|
||||||
// unloads cauldrons that are in a unloading world
|
// unloads cauldrons that are in a unloading world
|
||||||
// as they were written to file just before, this is safe to do
|
// as they were written to file just before, this is safe to do
|
||||||
public static void onUnload(String name) {
|
public static void onUnload(String name) {
|
||||||
|
|||||||
@@ -472,6 +472,13 @@ public class Barrel implements InventoryHolder {
|
|||||||
return body.getBrokenBlock(force);
|
return body.getBrokenBlock(force);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are any Barrels in that World
|
||||||
|
*/
|
||||||
|
public static boolean hasDataInWorld(String name) {
|
||||||
|
return barrels.stream().anyMatch(barrel -> barrel.spigot.getWorld().getName().equals(name));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unloads barrels that are in a unloading world
|
* unloads barrels that are in a unloading world
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -453,7 +453,7 @@ public class BData {
|
|||||||
// Increment the Data Mutex if it is not -1
|
// Increment the Data Mutex if it is not -1
|
||||||
while (BData.dataMutex.updateAndGet(i -> i >= 0 ? i + 1 : i) <= 0) {
|
while (BData.dataMutex.updateAndGet(i -> i >= 0 ? i + 1 : i) <= 0) {
|
||||||
wait++;
|
wait++;
|
||||||
if (wait > 60) {
|
if (!BConfig.loadDataAsync || wait > 60) {
|
||||||
P.p.errorLog("Could not load World Data, Mutex: " + BData.dataMutex.get());
|
P.p.errorLog("Could not load World Data, Mutex: " + BData.dataMutex.get());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,10 +45,13 @@ public class WorldListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onWorldUnload(WorldUnloadEvent event) {
|
public void onWorldUnload(WorldUnloadEvent event) {
|
||||||
DataSave.save(true);
|
|
||||||
String worldName = event.getWorld().getName();
|
String worldName = event.getWorld().getName();
|
||||||
|
if (Barrel.hasDataInWorld(worldName) || BCauldron.hasDataInWorld(worldName)) {
|
||||||
|
P.p.log("Saving due to data in unloading world");
|
||||||
|
DataSave.save(true);
|
||||||
Barrel.onUnload(worldName);
|
Barrel.onUnload(worldName);
|
||||||
BCauldron.onUnload(worldName);
|
BCauldron.onUnload(worldName);
|
||||||
|
}
|
||||||
Wakeup.onUnload(worldName);
|
Wakeup.onUnload(worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user