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();
}
}
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);
}
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));
}
Aggregations