Search in sources :

Example 1 with GameManager

use of com.gianlu.pyxreborn.server.GameManager in project PretendYoureXyzzyReborn by devgianlu.

the class Games method startGame.

/**
 * Starts a game. Creating the {@link GameManager} if needed.
 */
public void startGame(Game game) throws GeneralException {
    if (game.status != Game.Status.LOBBY)
        throw new GeneralException(ErrorCodes.GAME_ALREADY_STARTED);
    GameManager manager = managedGames.findGameManagerByGameId(game.gid);
    if (manager == null) {
        manager = new GameManager(server, game);
        manager.start();
        managedGames.add(manager);
    } else {
        manager.start();
    }
}
Also used : GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException) GameManager(com.gianlu.pyxreborn.server.GameManager)

Example 2 with GameManager

use of com.gianlu.pyxreborn.server.GameManager in project PretendYoureXyzzyReborn by devgianlu.

the class BaseHandlerWithGameManager method handleRequest.

@Override
public final JsonObject handleRequest(Server server, @NotNull User user, JsonObject request, JsonObject response) throws GeneralException {
    JsonElement gid = request.get(Fields.GID.toString());
    if (gid == null)
        throw new GeneralException(ErrorCodes.INVALID_REQUEST);
    GameManager manager = server.games.getGameManagerFor(gid.getAsInt());
    if (manager == null)
        throw new GeneralException(ErrorCodes.GAME_NOT_STARTED);
    Player player = manager.game.findPlayerByNickname(user.nickname);
    if (player == null)
        throw new GeneralException(ErrorCodes.NOT_IN_THIS_GAME);
    return handleRequest(server, player, manager, request, response);
}
Also used : Player(com.gianlu.pyxreborn.Models.Player) GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException) JsonElement(com.google.gson.JsonElement) GameManager(com.gianlu.pyxreborn.server.GameManager)

Example 3 with GameManager

use of com.gianlu.pyxreborn.server.GameManager in project PretendYoureXyzzyReborn by devgianlu.

the class Games method killGame.

/**
 * Kills the game, kicking everyone and deleting the game
 */
@AdminOnly
public void killGame(@NotNull Game game, KickReason majorReason) {
    GameManager manager = managedGames.findGameManagerByGameId(game.gid);
    if (manager != null) {
        try {
            manager.stop();
        } catch (GeneralException ignored) {
        }
    }
    if (!game.players.isEmpty()) {
        for (Player player : game.players) {
            kickPlayer(game, player, majorReason);
        }
    }
    if (!game.spectators.isEmpty()) {
        for (User spectator : game.spectators) {
            kickSpectator(game, spectator, majorReason);
        }
    }
    if (manager != null)
        managedGames.remove(manager);
    remove(game);
    server.broadcastMessage(Utils.event(Events.GAME_REMOVED));
}
Also used : Player(com.gianlu.pyxreborn.Models.Player) GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException) User(com.gianlu.pyxreborn.Models.User) GameManager(com.gianlu.pyxreborn.server.GameManager) AdminOnly(com.gianlu.pyxreborn.Annotations.AdminOnly)

Aggregations

GeneralException (com.gianlu.pyxreborn.Exceptions.GeneralException)3 GameManager (com.gianlu.pyxreborn.server.GameManager)3 Player (com.gianlu.pyxreborn.Models.Player)2 AdminOnly (com.gianlu.pyxreborn.Annotations.AdminOnly)1 User (com.gianlu.pyxreborn.Models.User)1 JsonElement (com.google.gson.JsonElement)1