Search in sources :

Example 1 with Vector3D

use of com.voxelgameslib.voxelgameslib.internal.math.Vector3D in project VoxelGamesLibv2 by VoxelGamesLib.

the class WorldModifyCommands method center.

@Subcommand("center")
@CommandPermission("%admin")
public void center(@Nonnull User user, @Nullable @co.aikar.commands.annotation.Optional String set) {
    if (!check(user))
        return;
    // view
    if (set == null) {
        Lang.msg(user, LangKey.WORLD_MODIFY_CENTER_VIEW, map.getCenter());
    } else // edit
    {
        map.setCenter(new Vector3D(user.getPlayer().getLocation().getX(), user.getPlayer().getLocation().getY(), user.getPlayer().getLocation().getZ()));
        Lang.msg(user, LangKey.WORLD_MODIFY_CENTER_EDIT, map.getCenter());
    }
}
Also used : Vector3D(com.voxelgameslib.voxelgameslib.internal.math.Vector3D) Subcommand(co.aikar.commands.annotation.Subcommand) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 2 with Vector3D

use of com.voxelgameslib.voxelgameslib.internal.math.Vector3D in project VoxelGamesLibv2 by VoxelGamesLib.

the class WorldCreator method center.

@Subcommand("center")
@CommandPermission("%admin")
public void center(@Nonnull User sender) {
    if (step != 2) {
        Lang.msg(sender, LangKey.WORLD_CREATOR_WRONG_STEP, step, 2);
        return;
    }
    center = new Vector3D(sender.getPlayer().getLocation().getX(), sender.getPlayer().getLocation().getY(), sender.getPlayer().getLocation().getZ());
    Lang.msg(sender, LangKey.WORLD_CREATOR_ENTER_RADIUS, "/worldcreator radius ");
    step = 3;
}
Also used : Vector3D(com.voxelgameslib.voxelgameslib.internal.math.Vector3D) Subcommand(co.aikar.commands.annotation.Subcommand) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 3 with Vector3D

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

Example 4 with Vector3D

use of com.voxelgameslib.voxelgameslib.internal.math.Vector3D in project VoxelGamesLibv2 by VoxelGamesLib.

the class MapScanner method searchForMarkers.

/**
 * Searches the map for "markers". Most of the time these are implemented as tile entities (skulls)
 *
 * @param map    the map to scan
 * @param center the center location
 * @param range  the range in where to scan
 */
public void searchForMarkers(@Nonnull Map map, @Nonnull Vector3D center, int range, @Nonnull UUID gameid) {
    World world = Bukkit.getWorld(map.getLoadedName(gameid));
    if (world == null) {
        throw new MapException("Could not find world " + map.getLoadedName(gameid) + "(" + map.getInfo().getDisplayName() + ")" + ". Is it loaded?");
    }
    List<Marker> markers = new ArrayList<>();
    List<ChestMarker> chestMarkers = new ArrayList<>();
    int startX = (int) center.getX();
    int startY = (int) center.getZ();
    int minX = Math.min(startX - range, startX + range);
    int minZ = Math.min(startY - range, startY + range);
    int maxX = Math.max(startX - range, startX + range);
    int maxZ = Math.max(startY - range, startY + range);
    for (int x = minX; x <= maxX; x += 16) {
        for (int z = minZ; z <= maxZ; z += 16) {
            Chunk chunk = world.getChunkAt(x >> 4, z >> 4);
            for (BlockState te : chunk.getTileEntities()) {
                if (te.getType() == Material.PLAYER_HEAD) {
                    Skull skull = (Skull) te;
                    String markerData = getMarkerData(skull);
                    if (markerData == null)
                        continue;
                    MarkerDefinition markerDefinition = mapHandler.createMarkerDefinition(markerData);
                    markers.add(new Marker(new Vector3D(skull.getX(), skull.getY(), skull.getZ()), DirectionUtil.directionToYaw(skull.getRotation()), markerData, markerDefinition));
                } else if (te.getType() == Material.CHEST) {
                    Chest chest = (Chest) te;
                    String name = chest.getBlockInventory().getName();
                    ItemStack[] items = new ItemStack[chest.getBlockInventory().getStorageContents().length];
                    for (int i = 0; i < items.length; i++) {
                        ItemStack is = chest.getBlockInventory().getItem(i);
                        if (is == null) {
                            items[i] = new ItemStack(Material.AIR);
                        } else {
                            items[i] = is;
                        }
                    }
                    chestMarkers.add(new ChestMarker(new Vector3D(chest.getX(), chest.getY(), chest.getZ()), name, items));
                }
            }
        }
    }
    map.setMarkers(markers);
    map.setChestMarkers(chestMarkers);
}
Also used : Chest(org.bukkit.block.Chest) ArrayList(java.util.ArrayList) MapException(com.voxelgameslib.voxelgameslib.api.exception.MapException) World(org.bukkit.World) Chunk(org.bukkit.Chunk) BlockState(org.bukkit.block.BlockState) Vector3D(com.voxelgameslib.voxelgameslib.internal.math.Vector3D) Skull(org.bukkit.block.Skull) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

Vector3D (com.voxelgameslib.voxelgameslib.internal.math.Vector3D)4 CommandPermission (co.aikar.commands.annotation.CommandPermission)3 Subcommand (co.aikar.commands.annotation.Subcommand)3 MapException (com.voxelgameslib.voxelgameslib.api.exception.MapException)1 MapFeature (com.voxelgameslib.voxelgameslib.api.feature.features.MapFeature)1 SpawnFeature (com.voxelgameslib.voxelgameslib.api.feature.features.SpawnFeature)1 Map (com.voxelgameslib.voxelgameslib.components.map.Map)1 ArrayList (java.util.ArrayList)1 Chunk (org.bukkit.Chunk)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 BlockState (org.bukkit.block.BlockState)1 Chest (org.bukkit.block.Chest)1 Skull (org.bukkit.block.Skull)1 ItemStack (org.bukkit.inventory.ItemStack)1