Search in sources :

Example 6 with VoxelGameLibException

use of com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.

the class AbstractPhase method checkEnd.

private void checkEnd() {
    // check all victory conditions
    User winner = null;
    Team winnerTeam = null;
    for (VictoryCondition victoryCondition : victoryConditions) {
        if (!victoryCondition.completed()) {
            return;
        }
        if (victoryCondition.getWinner() != null) {
            if (!victoryCondition.getWinner().equals(winner)) {
                if (winner == null) {
                    if (winnerTeam != null && !winnerTeam.contains(victoryCondition.getWinner())) {
                        throw new VoxelGameLibException(victoryCondition.getName() + " defined a winner even tho we already have a winning team!");
                    }
                    winner = victoryCondition.getWinner();
                } else {
                    throw new VoxelGameLibException(victoryCondition.getName() + " defined a different winner than one of the conditions before it!");
                }
            }
        }
        if (victoryCondition.getWinnerTeam() != null) {
            if (!victoryCondition.getWinnerTeam().equals(winnerTeam)) {
                if (winnerTeam == null) {
                    if (winner != null && !victoryCondition.getWinnerTeam().contains(winner)) {
                        throw new VoxelGameLibException(victoryCondition.getName() + " defined a winning team even tho we already have a winning user!");
                    } else {
                        winnerTeam = victoryCondition.getWinnerTeam();
                    }
                } else {
                    throw new VoxelGameLibException(victoryCondition.getName() + " defined a different winning team than one of the conditions before it!");
                }
            }
        }
    }
    // all done, end this game
    getGame().endGame(winnerTeam, winner);
}
Also used : User(com.voxelgameslib.voxelgameslib.user.User) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) Team(com.voxelgameslib.voxelgameslib.components.team.Team) VictoryCondition(com.voxelgameslib.voxelgameslib.condition.VictoryCondition) EmptyVictoryCondition(com.voxelgameslib.voxelgameslib.condition.conditions.EmptyVictoryCondition)

Example 7 with VoxelGameLibException

use of com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.

the class LangFormatter method handleClick.

@Nonnull
private static ClickEvent handleClick(@Nonnull String token) {
    String[] args = token.split(":");
    ClickEvent clickEvent;
    if (args.length < 2)
        throw new VoxelGameLibException("Can't parse click action (too few args) " + token);
    switch(args[1]) {
        case "run_command":
            clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, token.replace("click:run_command:", ""));
            break;
        case "suggest_command":
            clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, token.replace("click:suggest_command:", ""));
            break;
        case "open_url":
            clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, token.replace("click:open_url:", ""));
            break;
        case "change_page":
            clickEvent = new ClickEvent(ClickEvent.Action.CHANGE_PAGE, token.replace("click:change_page:", ""));
            break;
        default:
            throw new VoxelGameLibException("Can't parse click action (invalid type " + args[1] + ") " + token);
    }
    return clickEvent;
}
Also used : ClickEvent(net.kyori.text.event.ClickEvent) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) Nonnull(javax.annotation.Nonnull)

Example 8 with VoxelGameLibException

use of com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.

the class LangFormatter method handleHover.

@Nonnull
private static HoverEvent handleHover(@Nonnull String token) {
    String[] args = token.split(":");
    HoverEvent hoverEvent;
    if (args.length < 2)
        throw new VoxelGameLibException("Can't parse hover action (too few args) " + token);
    switch(args[1]) {
        case "show_text":
            hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, parseFormat(token.replace("hover:show_text:", "")));
            break;
        case "show_item":
            hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_ITEM, parseFormat(token.replace("hover:show_item:", "")));
            break;
        case "show_entity":
            hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_ENTITY, parseFormat(token.replace("hover:show_entity:", "")));
            break;
        default:
            throw new VoxelGameLibException("Can't parse hover action (invalid type " + args[1] + ") " + token);
    }
    return hoverEvent;
}
Also used : HoverEvent(net.kyori.text.event.HoverEvent) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) Nonnull(javax.annotation.Nonnull)

Aggregations

VoxelGameLibException (com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException)8 Nonnull (javax.annotation.Nonnull)3 CommandPermission (co.aikar.commands.annotation.CommandPermission)2 Subcommand (co.aikar.commands.annotation.Subcommand)2 ItemBuilder (com.voxelgameslib.voxelgameslib.utils.ItemBuilder)2 ItemStack (org.bukkit.inventory.ItemStack)2 SkullMeta (org.bukkit.inventory.meta.SkullMeta)2 Skin (org.mineskin.data.Skin)2 BukkitCommandExecutionContext (co.aikar.commands.BukkitCommandExecutionContext)1 InvalidCommandArgument (co.aikar.commands.InvalidCommandArgument)1 Syntax (co.aikar.commands.annotation.Syntax)1 Team (com.voxelgameslib.voxelgameslib.components.team.Team)1 VictoryCondition (com.voxelgameslib.voxelgameslib.condition.VictoryCondition)1 EmptyVictoryCondition (com.voxelgameslib.voxelgameslib.condition.conditions.EmptyVictoryCondition)1 GameStartException (com.voxelgameslib.voxelgameslib.exception.GameStartException)1 DefaultGameData (com.voxelgameslib.voxelgameslib.game.DefaultGameData)1 GameMode (com.voxelgameslib.voxelgameslib.game.GameMode)1 Locale (com.voxelgameslib.voxelgameslib.lang.Locale)1 MarkerDefinition (com.voxelgameslib.voxelgameslib.map.MarkerDefinition)1 Trackable (com.voxelgameslib.voxelgameslib.stats.Trackable)1