Search in sources :

Example 6 with Player

use of com.gianlu.pyxreborn.Models.Player in project PretendYoureXyzzyReborn by devgianlu.

the class Games method kickPlayer.

/**
 * Kicks a player from the game.
 */
public void kickPlayer(@NotNull Game game, @NotNull Player user, KickReason reason) {
    for (Player player : game.players) {
        if (Objects.equals(player, user)) {
            game.players.remove(user);
            JsonObject obj = new JsonObject();
            obj.addProperty(Fields.KICKED.toString(), reason.toString());
            server.sendMessage(user.user, obj);
        }
    }
}
Also used : Player(com.gianlu.pyxreborn.Models.Player) JsonObject(com.google.gson.JsonObject)

Example 7 with Player

use of com.gianlu.pyxreborn.Models.Player 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

Player (com.gianlu.pyxreborn.Models.Player)7 GeneralException (com.gianlu.pyxreborn.Exceptions.GeneralException)4 JsonObject (com.google.gson.JsonObject)4 AdminOnly (com.gianlu.pyxreborn.Annotations.AdminOnly)2 Game (com.gianlu.pyxreborn.Models.Game)2 User (com.gianlu.pyxreborn.Models.User)2 GameManager (com.gianlu.pyxreborn.server.GameManager)2 JsonElement (com.google.gson.JsonElement)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 WebSocket (org.java_websocket.WebSocket)1