Search in sources :

Example 1 with Map

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);
}
Also used : Map(com.voxelgameslib.voxelgameslib.map.Map) Description(co.aikar.commands.annotation.Description) Subcommand(co.aikar.commands.annotation.Subcommand) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 2 with Map

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: ");
}
Also used : Scoreboard(com.voxelgameslib.voxelgameslib.components.scoreboard.Scoreboard) Map(com.voxelgameslib.voxelgameslib.map.Map)

Example 3 with 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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) MapException(com.voxelgameslib.voxelgameslib.exception.MapException) WorldException(com.voxelgameslib.voxelgameslib.exception.WorldException) MapException(com.voxelgameslib.voxelgameslib.exception.MapException) IOException(java.io.IOException) ZipException(net.lingala.zip4j.exception.ZipException) ZipFile(net.lingala.zip4j.core.ZipFile) MapInfo(com.voxelgameslib.voxelgameslib.map.MapInfo) JsonReader(com.google.gson.stream.JsonReader) ArrayList(java.util.ArrayList) List(java.util.List) Map(com.voxelgameslib.voxelgameslib.map.Map) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File) FileHeader(net.lingala.zip4j.model.FileHeader) Nonnull(javax.annotation.Nonnull)

Example 4 with Map

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;
}
Also used : Vector3D(com.voxelgameslib.voxelgameslib.map.Vector3D) MapFeature(com.voxelgameslib.voxelgameslib.feature.features.MapFeature) SpawnFeature(com.voxelgameslib.voxelgameslib.feature.features.SpawnFeature) Map(com.voxelgameslib.voxelgameslib.map.Map) Location(org.bukkit.Location) Subcommand(co.aikar.commands.annotation.Subcommand) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 5 with Map

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
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) WorldException(com.voxelgameslib.voxelgameslib.exception.WorldException) MapFeature(com.voxelgameslib.voxelgameslib.feature.features.MapFeature) ZipException(net.lingala.zip4j.exception.ZipException) Map(com.voxelgameslib.voxelgameslib.map.Map) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File) SpawnFeature(com.voxelgameslib.voxelgameslib.feature.features.SpawnFeature) Subcommand(co.aikar.commands.annotation.Subcommand) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Aggregations

Map (com.voxelgameslib.voxelgameslib.map.Map)6 CommandPermission (co.aikar.commands.annotation.CommandPermission)4 Subcommand (co.aikar.commands.annotation.Subcommand)4 Syntax (co.aikar.commands.annotation.Syntax)3 Description (co.aikar.commands.annotation.Description)2 WorldException (com.voxelgameslib.voxelgameslib.exception.WorldException)2 MapFeature (com.voxelgameslib.voxelgameslib.feature.features.MapFeature)2 SpawnFeature (com.voxelgameslib.voxelgameslib.feature.features.SpawnFeature)2 File (java.io.File)2 ZipFile (net.lingala.zip4j.core.ZipFile)2 ZipException (net.lingala.zip4j.exception.ZipException)2 JsonReader (com.google.gson.stream.JsonReader)1 Scoreboard (com.voxelgameslib.voxelgameslib.components.scoreboard.Scoreboard)1 MapException (com.voxelgameslib.voxelgameslib.exception.MapException)1 MapInfo (com.voxelgameslib.voxelgameslib.map.MapInfo)1 Vector3D (com.voxelgameslib.voxelgameslib.map.Vector3D)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1