Fix Async Load Exception on 1.12 and lower

This commit is contained in:
Sn0wStorm 2020-04-12 18:06:03 +02:00
parent 0dd03133dc
commit ef868fc7eb
3 changed files with 53 additions and 36 deletions

View File

@ -58,6 +58,7 @@ public class BConfig {
// Barrel
public static boolean openEverywhere;
public static boolean loadDataAsync = true;
// Cauldron
public static boolean useOffhandForCauldron;
@ -244,6 +245,11 @@ public class BConfig {
Brew.loadSeed(config, new File(P.p.getDataFolder(), "config.yml"));
if (!P.use1_13) {
// world.getBlockAt loads Chunks in 1.12 and lower. Can't load async
loadDataAsync = false;
}
PluginItem.registerForConfig("brewery", BreweryPluginItem::new);
PluginItem.registerForConfig("mmoitems", MMOItemsPluginItem::new);
PluginItem.registerForConfig("slimefun", SlimefunPluginItem::new);

View File

@ -186,26 +186,11 @@ public class BData {
final List<World> worlds = P.p.getServer().getWorlds();
P.p.getServer().getScheduler().runTaskAsynchronously(P.p, () -> {
if (!acquireDataLoadMutex()) return; // Tries for 60 sec
try {
for (World world : worlds) {
if (world.getName().startsWith("DXL_")) {
loadWorldData(BUtil.getDxlName(world.getName()), world);
} else {
loadWorldData(world.getUID().toString(), world);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
releaseDataLoadMutex();
if (BData.dataMutex.get() == 0) {
P.p.log("Background data loading complete.");
}
}
});
if (BConfig.loadDataAsync) {
P.p.getServer().getScheduler().runTaskAsynchronously(P.p, () -> lwDataTask(worlds));
} else {
lwDataTask(worlds);
}
} else {
P.p.log("No data.yml found, will create new one!");
@ -278,6 +263,27 @@ public class BData {
}
}
public static void lwDataTask(List<World> worlds) {
if (!acquireDataLoadMutex()) return; // Tries for 60 sec
try {
for (World world : worlds) {
if (world.getName().startsWith("DXL_")) {
loadWorldData(BUtil.getDxlName(world.getName()), world);
} else {
loadWorldData(world.getUID().toString(), world);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
releaseDataLoadMutex();
if (BConfig.loadDataAsync && BData.dataMutex.get() == 0) {
P.p.log("Background data loading complete.");
}
}
}
// load Block locations of given world
// can be run async
public static void loadWorldData(String uuid, World world) {
@ -421,7 +427,7 @@ public class BData {
}
}
// Merge Loaded Data in Main Thred
// Merge Loaded Data in Main Thread
P.p.getServer().getScheduler().runTask(P.p, () -> {
if (P.p.getServer().getWorld(world.getUID()) == null) {
return;

View File

@ -4,6 +4,7 @@ import com.dre.brewery.BCauldron;
import com.dre.brewery.Barrel;
import com.dre.brewery.P;
import com.dre.brewery.Wakeup;
import com.dre.brewery.filedata.BConfig;
import com.dre.brewery.filedata.BData;
import com.dre.brewery.filedata.DataSave;
import com.dre.brewery.utility.BUtil;
@ -19,23 +20,27 @@ public class WorldListener implements Listener {
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
final World world = event.getWorld();
P.p.getServer().getScheduler().runTaskAsynchronously(P.p, () -> {
if (!BData.acquireDataLoadMutex()) return; // Tries for 60 sec
if (BConfig.loadDataAsync) {
P.p.getServer().getScheduler().runTaskAsynchronously(P.p, () -> lwDataTask(world));
} else {
lwDataTask(world);
}
}
try {
if (world.getName().startsWith("DXL_")) {
BData.loadWorldData(BUtil.getDxlName(world.getName()), world);
} else {
BData.loadWorldData(world.getUID().toString(), world);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
BData.releaseDataLoadMutex();
private void lwDataTask(World world) {
if (!BData.acquireDataLoadMutex()) return; // Tries for 60 sec
try {
if (world.getName().startsWith("DXL_")) {
BData.loadWorldData(BUtil.getDxlName(world.getName()), world);
} else {
BData.loadWorldData(world.getUID().toString(), world);
}
});
} catch (Exception e) {
e.printStackTrace();
} finally {
BData.releaseDataLoadMutex();
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)