mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 06:38:56 +00:00
Fix Async Load Exception on 1.12 and lower
This commit is contained in:
@@ -58,6 +58,7 @@ public class BConfig {
|
|||||||
|
|
||||||
// Barrel
|
// Barrel
|
||||||
public static boolean openEverywhere;
|
public static boolean openEverywhere;
|
||||||
|
public static boolean loadDataAsync = true;
|
||||||
|
|
||||||
// Cauldron
|
// Cauldron
|
||||||
public static boolean useOffhandForCauldron;
|
public static boolean useOffhandForCauldron;
|
||||||
@@ -244,6 +245,11 @@ public class BConfig {
|
|||||||
|
|
||||||
Brew.loadSeed(config, new File(P.p.getDataFolder(), "config.yml"));
|
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("brewery", BreweryPluginItem::new);
|
||||||
PluginItem.registerForConfig("mmoitems", MMOItemsPluginItem::new);
|
PluginItem.registerForConfig("mmoitems", MMOItemsPluginItem::new);
|
||||||
PluginItem.registerForConfig("slimefun", SlimefunPluginItem::new);
|
PluginItem.registerForConfig("slimefun", SlimefunPluginItem::new);
|
||||||
|
|||||||
@@ -186,26 +186,11 @@ public class BData {
|
|||||||
|
|
||||||
|
|
||||||
final List<World> worlds = P.p.getServer().getWorlds();
|
final List<World> worlds = P.p.getServer().getWorlds();
|
||||||
P.p.getServer().getScheduler().runTaskAsynchronously(P.p, () -> {
|
if (BConfig.loadDataAsync) {
|
||||||
if (!acquireDataLoadMutex()) return; // Tries for 60 sec
|
P.p.getServer().getScheduler().runTaskAsynchronously(P.p, () -> lwDataTask(worlds));
|
||||||
|
|
||||||
try {
|
|
||||||
for (World world : worlds) {
|
|
||||||
if (world.getName().startsWith("DXL_")) {
|
|
||||||
loadWorldData(BUtil.getDxlName(world.getName()), world);
|
|
||||||
} else {
|
} else {
|
||||||
loadWorldData(world.getUID().toString(), world);
|
lwDataTask(worlds);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
releaseDataLoadMutex();
|
|
||||||
if (BData.dataMutex.get() == 0) {
|
|
||||||
P.p.log("Background data loading complete.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
P.p.log("No data.yml found, will create new one!");
|
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
|
// load Block locations of given world
|
||||||
// can be run async
|
// can be run async
|
||||||
public static void loadWorldData(String uuid, World world) {
|
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, () -> {
|
P.p.getServer().getScheduler().runTask(P.p, () -> {
|
||||||
if (P.p.getServer().getWorld(world.getUID()) == null) {
|
if (P.p.getServer().getWorld(world.getUID()) == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.dre.brewery.BCauldron;
|
|||||||
import com.dre.brewery.Barrel;
|
import com.dre.brewery.Barrel;
|
||||||
import com.dre.brewery.P;
|
import com.dre.brewery.P;
|
||||||
import com.dre.brewery.Wakeup;
|
import com.dre.brewery.Wakeup;
|
||||||
|
import com.dre.brewery.filedata.BConfig;
|
||||||
import com.dre.brewery.filedata.BData;
|
import com.dre.brewery.filedata.BData;
|
||||||
import com.dre.brewery.filedata.DataSave;
|
import com.dre.brewery.filedata.DataSave;
|
||||||
import com.dre.brewery.utility.BUtil;
|
import com.dre.brewery.utility.BUtil;
|
||||||
@@ -19,7 +20,14 @@ public class WorldListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onWorldLoad(WorldLoadEvent event) {
|
public void onWorldLoad(WorldLoadEvent event) {
|
||||||
final World world = event.getWorld();
|
final World world = event.getWorld();
|
||||||
P.p.getServer().getScheduler().runTaskAsynchronously(P.p, () -> {
|
if (BConfig.loadDataAsync) {
|
||||||
|
P.p.getServer().getScheduler().runTaskAsynchronously(P.p, () -> lwDataTask(world));
|
||||||
|
} else {
|
||||||
|
lwDataTask(world);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lwDataTask(World world) {
|
||||||
if (!BData.acquireDataLoadMutex()) return; // Tries for 60 sec
|
if (!BData.acquireDataLoadMutex()) return; // Tries for 60 sec
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -33,9 +41,6 @@ public class WorldListener implements Listener {
|
|||||||
} finally {
|
} finally {
|
||||||
BData.releaseDataLoadMutex();
|
BData.releaseDataLoadMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
|||||||
Reference in New Issue
Block a user