Example #1
0
  @Command(
      name = "rename",
      descref = Messages.Help.Description.RENAME,
      permission = Permissions.PERMISSION_RENAME,
      minArgs = 2,
      usage = "/spleef rename <game> <to>")
  public void onRenameCommand(CommandContext context, HeavySpleef heavySpleef)
      throws CommandException {
    final CommandSender sender =
        context.getSender() instanceof Player
            ? heavySpleef.getSpleefPlayer(context.getSender())
            : context.getSender();

    final String from = context.getString(0);
    final String to = context.getString(1);

    GameManager manager = heavySpleef.getGameManager();

    CommandValidate.isTrue(
        manager.hasGame(from),
        i18n.getVarString(Messages.Command.GAME_DOESNT_EXIST).setVariable("game", from).toString());
    CommandValidate.isTrue(
        !manager.hasGame(to), i18n.getString(Messages.Command.GAME_ALREADY_EXIST));

    Game game = manager.getGame(from);
    final String oldName = game.getName();

    manager.renameGame(
        game,
        to,
        new FutureCallback<Void>() {

          @Override
          public void onSuccess(Void result) {
            sender.sendMessage(
                i18n.getVarString(Messages.Command.GAME_RENAMED)
                    .setVariable("from", oldName)
                    .setVariable("to", to)
                    .toString());
          }

          @Override
          public void onFailure(Throwable t) {
            sender.sendMessage(
                i18n.getVarString(Messages.Command.ERROR_ON_SAVE)
                    .setVariable("detail-message", t.toString())
                    .toString());
          }
        });
  }
Example #2
0
 @TabComplete("rename")
 public void onRenameTabComplete(
     CommandContext context, List<String> list, HeavySpleef heavySpleef) {
   GameManager manager = heavySpleef.getGameManager();
   if (context.argsLength() == 1) {
     for (Game game : manager.getGames()) {
       list.add(game.getName());
     }
   }
 }