示例#1
0
  @TabComplete("spectate")
  public static void onSpectateTabComplete(
      CommandContext context, List<String> list, HeavySpleef heavySpleef) throws CommandException {
    GameManager manager = heavySpleef.getGameManager();

    if (context.argsLength() == 1) {
      for (Game game : manager.getGames()) {
        if (!game.isFlagPresent(FlagSpectate.class)) {
          continue;
        }

        list.add(game.getName());
      }
    }
  }
示例#2
0
  @Command(
      name = "spectate",
      description = "Spectates a spleef game",
      usage = "/spleef spectate [game]",
      permission = Permissions.PERMISSION_SPECTATE)
  @PlayerOnly
  public static void onSpectateCommand(CommandContext context, HeavySpleef heavySpleef)
      throws CommandException {
    Player player = context.getSender();
    SpleefPlayer spleefPlayer = heavySpleef.getSpleefPlayer(player);
    String gameName = context.getStringSafely(0);
    final I18N i18n = I18NManager.getGlobal();

    GameManager manager = heavySpleef.getGameManager();

    Game game = null;
    FlagSpectate spectateFlag = null;

    for (Game otherGame : manager.getGames()) {
      if (!otherGame.isFlagPresent(FlagSpectate.class)) {
        continue;
      }

      FlagSpectate flag = otherGame.getFlag(FlagSpectate.class);
      if (!flag.isSpectating(spleefPlayer)) {
        continue;
      }

      game = otherGame;
      spectateFlag = flag;
      break;
    }

    if (game == null) {
      CommandValidate.isTrue(
          !gameName.isEmpty(),
          i18n.getVarString(Messages.Command.USAGE_FORMAT)
              .setVariable("usage", context.getCommand().getUsage())
              .toString());
      CommandValidate.isTrue(
          manager.hasGame(gameName),
          i18n.getVarString(Messages.Command.GAME_DOESNT_EXIST)
              .setVariable("game", gameName)
              .toString());

      game = manager.getGame(gameName);

      spectateFlag = game.getFlag(FlagSpectate.class);
      CommandValidate.notNull(spectateFlag, i18n.getString(Messages.Player.NO_SPECTATE_FLAG));
    }

    CommandValidate.isTrue(
        game.getFlag(FlagQueueLobby.class) == null || !game.isQueued(spleefPlayer),
        i18n.getString(Messages.Command.CANNOT_SPECTATE_IN_QUEUE_LOBBY));

    if (!spectateFlag.isSpectating(spleefPlayer)) {
      boolean success = spectateFlag.spectate(spleefPlayer, game);
      if (success) {
        spleefPlayer.sendMessage(
            i18n.getVarString(Messages.Player.PLAYER_SPECTATE)
                .setVariable("game", game.getName())
                .toString());
      }
    } else {
      spectateFlag.leave(spleefPlayer);
      spleefPlayer.sendMessage(
          i18n.getVarString(Messages.Player.PLAYER_LEAVE_SPECTATE)
              .setVariable("game", game.getName())
              .toString());
    }
  }