use of com.voxelgameslib.voxelgameslib.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.map.Map in project VoxelGamesLibv2 by VoxelGamesLib.
the class MapInfoFeature method enable.
@Override
public void enable() {
MapFeature mapFeature = getPhase().getFeature(MapFeature.class);
Map map = mapFeature.getMap();
ScoreboardFeature scoreboardFeature = getPhase().getFeature(ScoreboardFeature.class);
Scoreboard scoreboard = scoreboardFeature.getScoreboard();
for (String mode : map.getInfo().getGamemodes()) {
scoreboard.createAndAddLine(mode);
}
scoreboard.createAndAddLine(ChatColor.YELLOW + "" + ChatColor.BOLD + "Gamemodes: ");
scoreboard.createAndAddLine(map.getInfo().getAuthor());
scoreboard.createAndAddLine(ChatColor.YELLOW + "" + ChatColor.BOLD + "Author: ");
scoreboard.createAndAddLine(map.getInfo().getName());
scoreboard.createAndAddLine(ChatColor.YELLOW + "" + ChatColor.BOLD + "Map: ");
}
use of com.voxelgameslib.voxelgameslib.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().getName() + ".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, e);
}
} else {
return map.get();
}
}
use of com.voxelgameslib.voxelgameslib.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;
}
this.worldName = worldName;
worldHandler.loadLocalWorld(worldName);
Location spawnLoc = Bukkit.getWorld(worldName).getSpawnLocation();
Vector3D spawn = new Vector3D(spawnLoc.getX(), spawnLoc.getY(), spawnLoc.getZ());
sender.getPlayer().teleport(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.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().getName() + ".", e);
}
worldHandler.loadLocalWorld(map.getLoadedName(editor.getUuid()));
// tp
user.getPlayer().teleport(map.getCenter().toLocation(map.getLoadedName(user.getUuid())));
if (gameHandler.getDefaultGame().isParticipating(editor.getUuid())) {
gameHandler.getDefaultGame().leave(editor);
}
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();
Lang.msg(user, LangKey.WORLD_MODIFY_START);
// TODO use inventory for world creator
}
Aggregations