use of com.voxelgameslib.voxelgameslib.components.map.Marker in project VoxelGamesLibv2 by VoxelGamesLib.
the class SpawnFeature method enable.
@Override
public void enable() {
map = getPhase().getFeature(MapFeature.class).getMap();
for (Marker marker : map.getMarkers(spawnMarker)) {
spawns.add(marker.getLoc());
}
if (spawns.size() == 0) {
log.warning("Could not find any spawns on map " + map.getInfo().getDisplayName() + "(" + map.getInfo().getWorldName() + ")");
getPhase().getGame().abortGame();
return;
}
if (isInitialSpawn) {
for (User user : getPhase().getGame().getPlayers()) {
user.getPlayer().teleportAsync(getSpawn(user.getPlayer().getUniqueId()));
}
}
}
use of com.voxelgameslib.voxelgameslib.components.map.Marker in project VoxelGamesLibv2 by VoxelGamesLib.
the class WorldHandler method loadWorld.
/**
* Loads a world. Needs to copy the file from the repo, unzip it and let the implementation load it <br><b>Always
* needs to call super! Super needs to be called first (because it copies the world)</b>
*
* @param map the map that should be loaded
* @param gameid the id of the game this map belongs to
* @return the loaded world
* @throws WorldException something goes wrong
*/
@Nonnull
public World loadWorld(@Nonnull Map map, @Nonnull UUID gameid, boolean replaceMarkers) {
map.load(gameid, "TEMP_" + map.getWorldName() + "_" + gameid.toString().split("-")[0]);
log.finer("Loading map " + map.getInfo().getDisplayName() + " as " + map.getLoadedName(gameid));
File file = new File(worldContainer, map.getLoadedName(gameid));
try {
ZipFile zip = new ZipFile(new File(worldsFolder, map.getWorldName() + ".zip"));
zip.extractAll(file.getAbsolutePath());
FileUtils.delete(new File(file, "uid.dat"));
} catch (ZipException e) {
throw new WorldException("Could not unzip world " + map.getInfo().getDisplayName() + " (" + map.getWorldName() + ".zip).", e);
}
World world = loadLocalWorld(map.getLoadedName(gameid));
// load chunks based on markers
int i = 0;
int a = 0;
List<CompletableFuture<Chunk>> futures = new ArrayList<>();
for (Marker m : map.getMarkers()) {
Location l = m.getLoc().toLocation(world.getName());
if (!l.isChunkLoaded()) {
futures.add(l.getWorld().getChunkAtAsync(l));
i++;
} else {
a++;
}
}
if (replaceMarkers) {
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenRun(() -> {
replaceMarkers(world, map);
});
}
log.finer("Loaded " + i + " chunks and ignored " + a + " already loaded");
return world;
}
Aggregations