예제 #1
0
 @Command(
     aliases = {"join", "play"},
     desc = "Join a team.",
     usage = "[team]")
 public static void join(final CommandContext cmd, CommandSender sender) throws CommandException {
   if (!(sender instanceof Player)) {
     throw new CommandException(
         ChatConstant.ERROR_CONSOLE_NO_USE.getMessage(ChatUtil.getLocale(sender)));
   }
   if (GameHandler.getGameHandler().getMatch().getState().equals(MatchState.ENDED)
       || GameHandler.getGameHandler().getMatch().getState().equals(MatchState.CYCLING)) {
     throw new CommandException(
         ChatUtil.getWarningMessage(
             new LocalizedChatMessage(ChatConstant.ERROR_MATCH_OVER)
                 .getMessage(((Player) sender).getLocale())));
   }
   Optional<TeamModule> originalTeam = Teams.getTeamByPlayer((Player) sender);
   if (cmd.argsLength() == 0 && originalTeam.isPresent() && !originalTeam.get().isObserver()) {
     throw new CommandException(
         ChatUtil.getWarningMessage(
             ChatColor.RED
                 + new LocalizedChatMessage(
                         ChatConstant.ERROR_ALREADY_JOINED,
                         Teams.getTeamByPlayer((Player) sender).get().getCompleteName()
                             + ChatColor.RED)
                     .getMessage(((Player) sender).getLocale())));
   }
   Optional<TeamModule> destinationTeam = Optional.absent();
   if (cmd.argsLength() > 0) {
     for (TeamModule teamModule :
         GameHandler.getGameHandler().getMatch().getModules().getModules(TeamModule.class)) {
       if (teamModule.getName().toLowerCase().startsWith(cmd.getJoinedStrings(0).toLowerCase())) {
         destinationTeam = Optional.of(teamModule);
         break;
       }
     }
     if (!destinationTeam.isPresent()) {
       throw new CommandException(
           ChatConstant.ERROR_NO_TEAM_MATCH.getMessage(ChatUtil.getLocale(sender)));
     }
     if (destinationTeam.get().contains(sender)) {
       throw new CommandException(
           ChatUtil.getWarningMessage(
               ChatColor.RED
                   + new LocalizedChatMessage(
                           ChatConstant.ERROR_ALREADY_JOINED,
                           destinationTeam.get().getCompleteName() + ChatColor.RED)
                       .getMessage(ChatUtil.getLocale(sender))));
     }
     destinationTeam.get().add((Player) sender, false);
   } else {
     destinationTeam = Teams.getTeamWithFewestPlayers(GameHandler.getGameHandler().getMatch());
     if (destinationTeam.isPresent()) {
       destinationTeam.get().add((Player) sender, false);
     } else {
       throw new CommandException(
           ChatConstant.ERROR_TEAMS_FULL.getMessage(ChatUtil.getLocale(sender)));
     }
   }
 }
예제 #2
0
    @Command(
        aliases = {"banip", "ipban"},
        usage = "<target> [reason...]",
        desc = "Ban an IP address",
        flags = "st:",
        min = 1,
        max = -1)
    @CommandPermissions({"commandbook.bans.ban.ip"})
    public void banIP(CommandContext args, CommandSender sender) throws CommandException {

      String message = args.argsLength() >= 2 ? args.getJoinedStrings(1) : "Banned!";
      long endDate = args.hasFlag('t') ? CommandBookUtil.matchFutureDate(args.getFlag('t')) : 0L;

      String addr =
          args.getString(0).replace("\r", "").replace("\n", "").replace("\0", "").replace("\b", "");

      // Need to kick + log
      for (Player player : CommandBook.server().getOnlinePlayers()) {
        if (player.getAddress().getAddress().getHostAddress().equals(addr)) {
          player.kickPlayer(message);
          getBanDatabase().logKick(player, sender, message);
        }
      }

      getBanDatabase().ban(null, addr, sender, message, endDate);

      sender.sendMessage(ChatColor.YELLOW + addr + " banned.");

      if (!getBanDatabase().save()) {
        sender.sendMessage(ChatColor.RED + "Bans database failed to save. See console.");
      }
    }
  public static void help(
      CommandContext args,
      WorldEdit we,
      LocalSession session,
      LocalPlayer player,
      EditSession editSession) {
    final CommandsManager<LocalPlayer> commandsManager = we.getCommandsManager();

    if (args.argsLength() == 0) {
      SortedSet<String> commands =
          new TreeSet<String>(
              new Comparator<String>() {
                @Override
                public int compare(String o1, String o2) {
                  final int ret =
                      o1.replaceAll("/", "").compareToIgnoreCase(o2.replaceAll("/", ""));
                  if (ret == 0) {
                    return o1.compareToIgnoreCase(o2);
                  }
                  return ret;
                }
              });
      commands.addAll(commandsManager.getCommands().keySet());

      StringBuilder sb = new StringBuilder();
      boolean first = true;
      for (String command : commands) {
        if (!first) {
          sb.append(", ");
        }

        sb.append('/');
        sb.append(command);
        first = false;
      }

      player.print(sb.toString());

      return;
    }

    String command = args.getJoinedStrings(0).replaceAll("/", "");

    String helpMessage = commandsManager.getHelpMessages().get(command);
    if (helpMessage == null) {
      player.printError("Unknown command '" + command + "'.");
      return;
    }

    player.print(helpMessage);
  }
예제 #4
0
    @Command(
        aliases = {"kick"},
        usage = "<target> [reason...]",
        desc = "Kick a user",
        flags = "os",
        min = 1,
        max = -1)
    @CommandPermissions({"commandbook.kick"})
    public void kick(CommandContext args, CommandSender sender) throws CommandException {
      Iterable<Player> targets = PlayerUtil.matchPlayers(sender, args.getString(0));
      String message = args.argsLength() >= 2 ? args.getJoinedStrings(1) : "Kicked!";

      String broadcastPlayers = "";
      for (Player player : targets) {
        if (CommandBook.inst().hasPermission(player, "commandbook.kick.exempt")
            && !(args.hasFlag('o')
                && CommandBook.inst().hasPermission(sender, "commandbook.kick.exempt.override"))) {
          sender.sendMessage(
              ChatColor.RED
                  + "Player "
                  + player.getName()
                  + ChatColor.RED
                  + " is exempt from being kicked!");
          continue;
        }
        player.kickPlayer(message);
        broadcastPlayers += PlayerUtil.toColoredName(player, ChatColor.YELLOW) + " ";
        getBanDatabase().logKick(player, sender, message);
      }

      if (broadcastPlayers.length() > 0) {
        sender.sendMessage(ChatColor.YELLOW + "Player(s) kicked.");
        // Broadcast the Message
        if (config.broadcastKicks && !args.hasFlag('s')) {
          BasePlugin.server()
              .broadcastMessage(
                  ChatColor.YELLOW
                      + PlayerUtil.toColoredName(sender, ChatColor.YELLOW)
                      + " has kicked "
                      + broadcastPlayers
                      + " - "
                      + message);
        }
      }
    }
예제 #5
0
    @Command(
        aliases = {"unbanip", "unipban"},
        usage = "<target> [reason...]",
        desc = "Unban an IP address",
        min = 1,
        max = -1)
    @CommandPermissions({"commandbook.bans.unban.ip"})
    public void unbanIP(CommandContext args, CommandSender sender) throws CommandException {

      String addr =
          args.getString(0).replace("\r", "").replace("\n", "").replace("\0", "").replace("\b", "");
      String message = args.argsLength() >= 2 ? args.getJoinedStrings(1) : "Unbanned!";

      if (getBanDatabase().unban(null, addr, sender, message)) {
        sender.sendMessage(ChatColor.YELLOW + addr + " unbanned.");

        if (!getBanDatabase().save()) {
          sender.sendMessage(ChatColor.RED + "Bans database failed to save. See console.");
        }
      } else {
        sender.sendMessage(ChatColor.RED + addr + " was not banned.");
      }
    }
예제 #6
0
    @Command(
        aliases = {"force"},
        desc = "Force a player onto a team",
        usage = "<player> <team>",
        min = 2)
    @CommandPermissions("spork.team.force")
    public static void force(CommandContext cmd, CommandSender sender) {
      SporkPlayer player = SporkPlayer.getPlayer(cmd.getString(0));
      if (player == null) {
        sender.sendMessage(ChatColor.RED + "No players matched query.");
        return;
      }

      SporkTeam team = SporkMap.getMap().getTeam(cmd.getJoinedStrings(1));
      if (team == null) {
        sender.sendMessage(ChatColor.RED + "No teams matched query.");
        return;
      }

      ChatColor old = player.getTeamColour();
      player.setTeam(team);
      sender.sendMessage(
          old + player.getName() + ChatColor.GRAY + " forced onto " + team.getColoredName());
    }
예제 #7
0
    @Command(
        aliases = {"alias"},
        desc = "Change the alias of a team",
        usage = "<old name> <new name>",
        min = 1,
        max = 2)
    @CommandPermissions("spork.team.alias")
    public static void alias(CommandContext cmd, CommandSender sender) {
      String oldName = cmd.getString(0);
      String newName = cmd.getJoinedStrings(1);

      SporkTeam team = SporkMap.getMap().getTeam(oldName);
      if (team == null) {
        sender.sendMessage(ChatColor.RED + "No teams matched query.");
        return;
      }

      String old = team.getName();
      ChatColor color = team.getColor();
      team.setName(newName);

      Bukkit.broadcastMessage(
          color + old + ChatColor.GRAY + " has been renamed to " + color + newName);
    }
예제 #8
0
    @Command(
        aliases = {"ban"},
        usage = "[-t end ] <target> [reason...]",
        desc = "Ban a user or IP address (with the -i flag)",
        flags = "set:o",
        min = 1,
        max = -1)
    @CommandPermissions({"commandbook.bans.ban"})
    public void ban(CommandContext args, CommandSender sender) throws CommandException {
      String banName;
      String banAddress = null;
      long endDate = args.hasFlag('t') ? CommandBookUtil.matchFutureDate(args.getFlag('t')) : 0L;
      String message = args.argsLength() >= 2 ? args.getJoinedStrings(1) : "Banned!";

      final boolean hasExemptOverride =
          args.hasFlag('o')
              && CommandBook.inst().hasPermission(sender, "commandbook.bans.exempt.override");
      // Check if it's a player in the server right now
      try {
        Player player;

        // Exact mode matches names exactly
        if (args.hasFlag('e')) {
          player = PlayerUtil.matchPlayerExactly(sender, args.getString(0));
        } else {
          player = PlayerUtil.matchSinglePlayer(sender, args.getString(0));
        }

        if (CommandBook.inst().hasPermission(player, "commandbook.bans.exempt")
            && !hasExemptOverride) {
          throw new CommandException(
              "This player is exempt from being banned! "
                  + "(use -o flag to override if you have commandbook.bans.exempt.override)");
        }

        // Need to kick + log
        player.kickPlayer(message);
        getBanDatabase().logKick(player, sender, message);

        banName = player.getName();

        sender.sendMessage(
            ChatColor.YELLOW
                + player.getName()
                + " ("
                + player.getDisplayName()
                + ChatColor.YELLOW
                + ") banned and kicked.");
      } catch (CommandException e) {
        banName =
            args.getString(0)
                .replace("\r", "")
                .replace("\n", "")
                .replace("\0", "")
                .replace("\b", "");

        sender.sendMessage(ChatColor.YELLOW + banName + " banned.");
      }

      // Broadcast the Message
      if (config.broadcastBans && !args.hasFlag('s')) {
        CommandBook.server()
            .broadcastMessage(
                ChatColor.YELLOW
                    + PlayerUtil.toColoredName(sender, ChatColor.YELLOW)
                    + " has banned "
                    + banName
                    + " - "
                    + message);
      }

      getBanDatabase().ban(banName, banAddress, sender, message, endDate);

      if (!getBanDatabase().save()) {
        sender.sendMessage(ChatColor.RED + "Bans database failed to save. See console.");
      }
    }