use of com.voxelgameslib.voxelgameslib.components.map.Map in project VoxelGamesLibv2 by VoxelGamesLib.
the class WorldHandler method loadMap.
/**
* Tries to load the map data for a name
*
* @param name the name of the map to load
* @return the loaded map
* @throws MapException when
*/
@Nonnull
public Map loadMap(@Nonnull String name) {
Optional<Map> map = getMap(name);
if (!map.isPresent()) {
Optional<MapInfo> mapInfo = getMapInfo(name);
if (!mapInfo.isPresent()) {
throw new MapException("Unknown map " + name + ". Did you register it into the world config?");
}
try {
ZipFile zipFile = new ZipFile(new File(worldsFolder, mapInfo.get().getWorldName() + ".zip"));
for (FileHeader header : (List<FileHeader>) zipFile.getFileHeaders()) {
if (header.getFileName().endsWith("config.json")) {
InputStream stream = zipFile.getInputStream(header);
Map m = gson.fromJson(new JsonReader(new InputStreamReader(stream)), Map.class);
m.initMarkers(mapHandler);
maps.add(m);
return m;
}
}
throw new MapException("Could not load map config for map " + name + ". Fileheader was null. Does it has a map.json?");
} catch (Exception e) {
throw new MapException("Error while trying to load map config " + name + "(" + mapInfo.get().getWorldName() + ".zip)", e);
}
} else {
return map.get();
}
}
use of com.voxelgameslib.voxelgameslib.components.map.Map in project VoxelGamesLibv2 by VoxelGamesLib.
the class WorldCommands method load.
@Subcommand("load")
@CommandPermission("%admin")
@Syntax("<mapname> - the name of the map to load")
@Description("Loads a map onto the server")
public void load(@Nonnull User sender, @Nonnull String mapName) {
Optional<Map> o = handler.getMap(mapName);
Map map = o.orElseGet(() -> handler.loadMap(mapName));
handler.loadWorld(map, sender.getUuid(), false);
}
use of com.voxelgameslib.voxelgameslib.components.map.Map in project VoxelGamesLibv2 by VoxelGamesLib.
the class WorldModifyCommands method start.
@Subcommand("start")
@CommandPermission("%admin")
@Syntax("<world> - the name of the map you want to modify")
public void start(@Nonnull User user, @Nonnull String world) {
if (editor != null) {
Lang.msg(user, LangKey.WORLD_CREATOR_IN_USE, editor.getDisplayName());
return;
}
editor = user;
// load data
Optional<Map> o = worldHandler.getMap(world);
this.map = o.orElseGet(() -> worldHandler.loadMap(world));
// load world
map.load(editor.getUuid(), map.getWorldName());
File file = new File(worldHandler.getWorldContainer(), map.getLoadedName(editor.getUuid()));
try {
ZipFile zip = new ZipFile(new File(worldHandler.getWorldsFolder(), 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);
}
worldHandler.loadLocalWorld(map.getLoadedName(editor.getUuid()));
// tp
user.getPlayer().teleportAsync(map.getCenter().toLocation(map.getLoadedName(user.getUuid())));
if (gameHandler.getDefaultGame().isParticipating(editor.getUuid())) {
gameHandler.getDefaultGame().leave(editor, false);
}
game = gameHandler.startGame(EditModeGame.GAMEMODE);
game.getActivePhase().getNextPhase().getFeature(SpawnFeature.class).addSpawn(map.getCenter());
game.getActivePhase().getNextPhase().getFeature(MapFeature.class).setMap(map);
map.load(game.getUuid(), map.getWorldName());
game.join(editor);
game.endPhase();
map.getInfo().setWorldName(map.getWorldName());
Lang.msg(user, LangKey.WORLD_MODIFY_START);
// TODO use inventory for world creator
}
use of com.voxelgameslib.voxelgameslib.components.map.Map in project VoxelGamesLibv2 by VoxelGamesLib.
the class WorldCreator method world.
@Subcommand("world")
@CommandPermission("%admin")
public void world(@Nonnull User sender, @Nonnull String worldName) {
if (step != 1) {
Lang.msg(sender, LangKey.WORLD_CREATOR_WRONG_STEP, step, 1);
return;
}
gameHandler.getGames(sender.getUuid(), true).forEach(game -> game.leave(sender, false));
this.worldName = worldName;
worldHandler.loadLocalWorld(worldName);
Location spawnLoc = Bukkit.getWorld(worldName).getSpawnLocation();
Vector3D spawn = new Vector3D(spawnLoc.getX(), spawnLoc.getY(), spawnLoc.getZ());
sender.getPlayer().teleportAsync(spawnLoc);
game = gameHandler.startGame(EditModeGame.GAMEMODE);
game.getActivePhase().getNextPhase().getFeature(SpawnFeature.class).addSpawn(spawn);
Map map = new Map(null, worldName, spawn, 100);
map.load(game.getUuid(), worldName);
game.getActivePhase().getNextPhase().getFeature(MapFeature.class).setMap(map);
game.join(editor);
game.endPhase();
Lang.msg(sender, LangKey.WORLD_CREATOR_ENTER_CENTER, "/worldcreator center");
step = 2;
}
use of com.voxelgameslib.voxelgameslib.components.map.Map in project VoxelGamesLibv2 by VoxelGamesLib.
the class WorldCommands method tp.
@Subcommand("tp")
@CommandPermission("%admin")
@Syntax("<world> - the name of the world to tp to")
@Description("Teleports you to a world")
public void tp(@Nonnull User sender, @Nonnull String world) {
Optional<Map> o = handler.getMap(world);
if (o.isPresent()) {
Map map = o.get();
sender.getPlayer().teleportAsync(map.getCenter().toLocation(map.getLoadedName(sender.getUuid())));
} else {
World w = Bukkit.getWorld(world);
if (w != null) {
sender.getPlayer().teleportAsync(Bukkit.getWorld(world).getSpawnLocation());
}
Lang.msg(sender, LangKey.WORLD_UNKNOWN_MAP, world);
}
}
Aggregations