Search in sources :

Example 1 with DefaultGameData

use of com.voxelgameslib.voxelgameslib.game.DefaultGameData in project VoxelGamesLibv2 by VoxelGamesLib.

the class TeamFeature method enable.

@Override
public void enable() {
    getPhase().setAllowJoin(false);
    DefaultGameData gameData = getPhase().getGame().getGameData(DefaultGameData.class).orElse(new DefaultGameData());
    teams = gameData.teams;
    if (teams == null || teams.size() == 0) {
        log.severe("You need to run team select before running team feature!");
        getPhase().getGame().abortGame();
    }
}
Also used : DefaultGameData(com.voxelgameslib.voxelgameslib.game.DefaultGameData)

Example 2 with DefaultGameData

use of com.voxelgameslib.voxelgameslib.game.DefaultGameData in project VoxelGamesLibv2 by VoxelGamesLib.

the class VoteFeature method disable.

@Override
public void disable() {
    Map<Integer, Integer> votes = new HashMap<>();
    int max = -1;
    int maxMap = -1;
    for (Integer map : this.votes.values()) {
        int old = votes.getOrDefault(map, 0);
        old++;
        if (old > max) {
            max = old;
            maxMap = map;
        }
        votes.put(map, old);
    }
    MapInfo winner = availableMaps.get(maxMap);
    if (winner == null) {
        // use first map if nobody won
        winner = availableMaps.values().iterator().next();
    }
    DefaultGameData gameData = getPhase().getGame().getGameData(DefaultGameData.class).orElse(new DefaultGameData());
    gameData.voteWinner = winner;
    getPhase().getGame().putGameData(gameData);
    getPhase().getGame().broadcastMessage(LangKey.VOTE_END, winner.getName(), winner.getAuthor(), Math.max(max, 0));
}
Also used : HashMap(java.util.HashMap) MapInfo(com.voxelgameslib.voxelgameslib.map.MapInfo) DefaultGameData(com.voxelgameslib.voxelgameslib.game.DefaultGameData)

Example 3 with DefaultGameData

use of com.voxelgameslib.voxelgameslib.game.DefaultGameData in project VoxelGamesLibv2 by VoxelGamesLib.

the class MapFeature method enable.

@Override
public void enable() {
    // we already set the map externally, no need to do anything of the following, just set the world
    if (map != null) {
        world = Bukkit.getWorld(map.getLoadedName(getPhase().getGame().getUuid()));
        return;
    }
    DefaultGameData gameData = getPhase().getGame().getGameData(DefaultGameData.class).orElse(new DefaultGameData());
    if ((type == Type.LOBBY && gameData.lobbyMap == null) || (type == Type.VOTEWINNER && gameData.voteWinner == null)) {
        throw new GameStartException(getPhase().getGame().getGameMode(), "No map data was stored!");
    }
    String mapName;
    if (type == Type.LOBBY) {
        mapName = gameData.lobbyMap.getName();
    } else if (type == Type.VOTEWINNER) {
        mapName = gameData.voteWinner.getName();
    } else {
        throw new VoxelGameLibException("Unknown maptype");
    }
    try {
        map = worldHandler.loadMap(mapName);
        if (!map.isLoaded(getPhase().getGame().getUuid())) {
            world = worldHandler.loadWorld(map, getPhase().getGame().getUuid(), true);
        } else {
            world = Bukkit.getWorld(map.getLoadedName(getPhase().getGame().getUuid()));
        }
    } catch (Exception ex) {
        throw new GameStartException(getPhase().getGame().getGameMode(), ex);
    }
}
Also used : VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) GameStartException(com.voxelgameslib.voxelgameslib.exception.GameStartException) DefaultGameData(com.voxelgameslib.voxelgameslib.game.DefaultGameData) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) GameStartException(com.voxelgameslib.voxelgameslib.exception.GameStartException)

Example 4 with DefaultGameData

use of com.voxelgameslib.voxelgameslib.game.DefaultGameData in project VoxelGamesLibv2 by VoxelGamesLib.

the class TeamSelectFeature method disable.

@Override
public void disable() {
    Map<String, Integer> sizes = calcSizes();
    // add everyone who isn't in a team yet to the smallest team
    for (User user : getPhase().getGame().getPlayers()) {
        if (!getTeam(user).isPresent()) {
            Team t = getTeam(findSmallest(sizes)).orElseThrow(() -> new RuntimeException("Null team encountered"));
            t.join(user, user.getRating(getPhase().getGame().getGameMode()));
            Lang.msg(user, LangKey.TEAM_AUTO_ASSIGNED, t.getName());
            sizes.put(t.getName(), sizes.get(t.getName()) + 1);
        }
    }
    // make teams balanced
    balance();
    // save teams for next phase
    DefaultGameData defaultGameData = getPhase().getGame().getGameData(DefaultGameData.class).orElse(new DefaultGameData());
    defaultGameData.teams = teams;
    getPhase().getGame().putGameData(defaultGameData);
}
Also used : User(com.voxelgameslib.voxelgameslib.user.User) Team(com.voxelgameslib.voxelgameslib.components.team.Team) DefaultGameData(com.voxelgameslib.voxelgameslib.game.DefaultGameData)

Aggregations

DefaultGameData (com.voxelgameslib.voxelgameslib.game.DefaultGameData)4 Team (com.voxelgameslib.voxelgameslib.components.team.Team)1 GameStartException (com.voxelgameslib.voxelgameslib.exception.GameStartException)1 VoxelGameLibException (com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException)1 MapInfo (com.voxelgameslib.voxelgameslib.map.MapInfo)1 User (com.voxelgameslib.voxelgameslib.user.User)1 HashMap (java.util.HashMap)1