
Originally Posted by
Kris
There should be another method that takes a second parameter, so getRegion(regionId, true) - don't forget the true part. That's what force-loads the requested region, instead of just returning the reference in whatever form it currently is in.
Tried the : World.getRegion(12952, true);
Found this in World.Java , seems to be the only get regions in it.
Code:
public static final Map<Integer, Region> getRegions() {
// synchronized (lock) {
return regions;
// }
}
public static final Region getRegion(int id) {
return getRegion(id, false);
}
public static final Region getRegion(int id, boolean load) {
// synchronized (lock) {
Region region = regions.get(id);
if (region == null) {
region = new Region(id);
regions.put(id, region);
}
if (load)
region.checkLoadMap();
return region;
// }
These are the only load regions
Code:
public static void executeAfterLoadRegion(final int regionId, final Runnable event) {
executeAfterLoadRegion(regionId, 0, event);
}
public static void executeAfterLoadRegion(final int regionId, long startTime, final Runnable event) {
executeAfterLoadRegion(regionId, startTime, 10000, event);
}
public static void executeAfterLoadRegion(final int fromRegionX, final int fromRegionY, final int toRegionX, final int toRegionY, long startTime, final long expireTime, final Runnable event) {
final long start = Utils.currentTimeMillis();
for (int x = fromRegionX; x <= toRegionX; x++) {
for (int y = fromRegionY; y <= toRegionY; y++) {
int regionId = MapUtils.encode(Structure.REGION, x, y);
World.getRegion(regionId, true); // forces check load if not
// loaded
}
}
GameEngine.get().getFastExecutor().schedule(new TimerTask() {
@Override
public void run() {
try {
for (int x = fromRegionX; x <= toRegionX; x++) {
for (int y = fromRegionY; y <= toRegionY; y++) {
int regionId = MapUtils.encode(Structure.REGION, x, y);
if (!World.isRegionLoaded(regionId) && Utils.currentTimeMillis() - start < expireTime)
return;
}
}
event.run();
cancel();
} catch (Throwable e) {
e.printStackTrace();
}
}
}, startTime, 600);
}
/*
* TODO make this use code from above to save lines lo, they do same
*/
public static void executeAfterLoadRegion(final int regionId, long startTime, final long expireTime, final Runnable event) {
final long start = Utils.currentTimeMillis();
World.getRegion(regionId, true); // forces check load if not loaded
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
if (!World.isRegionLoaded(regionId) && Utils.currentTimeMillis() - start < expireTime)
return;
event.run();
cancel();
} catch (Throwable e) {
e.printStackTrace();
}
}
}, startTime, 600);
}