예제 #1
0
  @CommandNode(
      name = "remove",
      permission = "mytown.cmd.assistant.ranks.perm.remove",
      parentName = "mytown.cmd.assistant.ranks.perm")
  public static void ranksPermRemoveCommand(ICommandSender sender, List<String> args) {

    if (args.size() < 2)
      throw new WrongUsageException(getLocal().getLocalization("mytown.cmd.usage.ranks.perm"));

    Resident res = getDatasource().getOrMakeResident(sender);
    Town town = getTownFromResident(res);

    Rank rank = getRankFromTown(town, args.get(0));

    if (!CommandManager.commandList.keySet().contains(args.get(1)))
      throw new CommandException(
          getLocal().getLocalization("mytown.cmd.err.ranks.perm.notexist", args.get(1)));

    // Removing permission if everything is alright
    if (rank.removePermission(args.get(1))) {
      getDatasource().saveRank(rank, rank.getTown().getDefaultRank().equals(rank));
      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.town.ranks.perm.remove", args.get(1), args.get(0)));
    } else
      throw new CommandException(
          getLocal().getLocalization("mytown.cmd.err.ranks.perm.remove.failed", args.get(1)));
  }
예제 #2
0
  @CommandNode(
      name = "promote",
      permission = "mytown.cmd.assistant.promote",
      parentName = "mytown.cmd",
      completionKeys = {"residentCompletion", "rankCompletion"})
  public static void promoteCommand(ICommandSender sender, List<String> args) {

    // /t promote <user> <rank>
    if (args.size() < 2)
      throw new WrongUsageException(getLocal().getLocalization("mytown.cmd.usage.promote"));
    Resident resSender = getDatasource().getOrMakeResident(sender);
    Resident resTarget = getResidentFromName(args.get(0));
    Town town = getTownFromResident(resSender);

    if (!resTarget.getTowns().contains(town))
      throw new CommandException(
          getLocal()
              .getLocalization("mytown.cmd.err.resident.notsametown", args.get(0), town.getName()));

    // TODO: implement this properly
    if (args.get(1).equalsIgnoreCase("mayor"))
      throw new CommandException(getLocal().getLocalization("mytown.cmd.err.promote.notMayor"));
    Rank rank = getRankFromTown(town, args.get(1));
    if (getDatasource().updateResidentToTownLink(resTarget, town, rank)) {
      resSender.sendMessage(getLocal().getLocalization("mytown.cmd.promote.success.sender"));
      resTarget.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.cmd.promote.success.target", rank.getName(), town.getName()));
    }
  }
예제 #3
0
  @CommandNode(
      name = "list",
      permission = "mytown.cmd.assistant.ranks.perm.list",
      parentName = "mytown.cmd.assistant.ranks.perm")
  public static void ranksPermListCommand(ICommandSender sender, List<String> args) {

    Rank rank;
    Resident res = getDatasource().getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    if (args.size() == 0) {
      rank = getRankFromResident(res);
    } else {
      rank = getRankFromTown(town, args.get(0));
    }

    String msg = "";
    for (String s : rank.getPermissions()) {
      msg += '\n' + s;
    }

    res.sendMessage(
        getLocal()
            .getLocalization(
                "mytown.notification.town.ranks.perm.list",
                rank.getName(),
                rank.getTown().getName(),
                msg));
  }
예제 #4
0
    @Command(
        name = "remove",
        permission = "mytown.cmd.assistant.ranks.remove",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks remove <rank>",
        completionKeys = {"rankCompletion"})
    public static CommandResponse ranksRemoveCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);
      Rank rank = getRankFromTown(town, args.get(0));

      if (rank.getType().unique) {
        throw new MyTownCommandException("mytown.cmd.err.ranks.cantDelete");
      }

      for (Rank residentRank : town.residentsMap.values()) {
        if (residentRank == rank) {
          throw new MyTownCommandException("mytown.cmd.err.ranks.assigned");
        }
      }

      getDatasource().deleteRank(rank);
      res.sendMessage(
          getLocal()
              .getLocalization("mytown.notification.town.ranks.rem", args.get(0), town.getName()));

      return CommandResponse.DONE;
    }
예제 #5
0
  @Command(
      name = "promote",
      permission = "mytown.cmd.assistant.promote",
      parentName = "mytown.cmd",
      syntax = "/town promote <resident> <rank>",
      completionKeys = {"residentCompletion", "rankCompletion"})
  public static CommandResponse promoteCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 2) return CommandResponse.SEND_SYNTAX;
    Resident resSender = MyTownUniverse.instance.getOrMakeResident(sender);
    Resident resTarget = getResidentFromName(args.get(0));
    Town town = getTownFromResident(resSender);

    if (!resTarget.townsContainer.contains(town))
      throw new MyTownCommandException(
          "mytown.cmd.err.resident.notsametown", args.get(0), town.getName());

    Rank mayorRank = town.ranksContainer.getMayorRank();
    if (args.get(1).equalsIgnoreCase(mayorRank.getName()))
      throw new MyTownCommandException("mytown.cmd.err.promote.notMayor");
    Rank rank = getRankFromTown(town, args.get(1));
    if (getDatasource().updateResidentToTownLink(resTarget, town, rank)) {
      resSender.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.cmd.promote.success.sender", resTarget.getPlayerName(), rank.getName()));
      resTarget.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.cmd.promote.success.target", rank.getName(), town.getName()));
    }
    return CommandResponse.DONE;
  }
예제 #6
0
 public Rank getRank(String rank, Town town) {
   for (Rank r : Constants.DEFAULT_RANKS) {
     if (r.parse(rank)) return r;
   }
   if (town != null)
     for (Rank r : town.getAdditionalRanks()) {
       if (r.parse(rank)) return r;
     }
   return Constants.DEFAULT_RANKS[0]; // TODO Change later?
 }
예제 #7
0
    @Command(
        name = "reset",
        permission = "mytown.cmd.assistant.ranks.reset",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks reset")
    public static CommandResponse ranksResetCommand(ICommandSender sender, List<String> args) {
      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);

      for (Rank defaultRank : Rank.defaultRanks) {
        Rank rank = town.ranksContainer.get(defaultRank.getName());

        rank.permissionsContainer.clear();
        rank.permissionsContainer.addAll(defaultRank.permissionsContainer);
        rank.setType(defaultRank.getType());

        getDatasource().saveRank(rank);
      }

      for (int i = 0; i < town.ranksContainer.size(); i++) {
        Rank rank = town.ranksContainer.get(i);
        if (!Rank.defaultRanks.contains(rank.getName())) {
          getDatasource().deleteRank(rank);
          i--;
        }
      }

      res.sendMessage(getLocal().getLocalization("mytown.notification.ranks.reset"));

      return CommandResponse.DONE;
    }
예제 #8
0
  /** Populates the tab completion map. */
  public static void populateCompletionMap() {

    List<String> populator = new ArrayList<String>();
    for (Town town : getUniverse().towns) {
      populator.add(town.getName());
    }

    CommandCompletion.addCompletions("townCompletionAndAll", populator);
    CommandCompletion.addCompletion("townCompletionAndAll", "@a");

    CommandCompletion.addCompletions("townCompletion", populator);

    populator = new ArrayList<String>();
    for (Resident res : getUniverse().residents) {
      populator.add(res.getPlayerName());
    }
    CommandCompletion.addCompletions("residentCompletion", populator);

    populator = new ArrayList<String>();
    for (FlagType flag : FlagType.values()) {
      populator.add(flag.name.toLowerCase());
    }
    CommandCompletion.addCompletions("flagCompletion", populator);

    populator = new ArrayList<String>();
    for (FlagType flag : FlagType.values()) {
      if (flag.isWhitelistable) populator.add(flag.name.toLowerCase());
    }
    CommandCompletion.addCompletions("flagCompletionWhitelist", populator);

    populator = new ArrayList<String>();
    for (Plot plot : MyTownUniverse.instance.plots) {
      populator.add(plot.toString());
    }
    CommandCompletion.addCompletions("plotCompletion", populator);

    populator = new ArrayList<String>();
    for (Rank rank : Rank.defaultRanks) {
      populator.add(rank.getName());
    }
    CommandCompletion.addCompletions("rankCompletion", populator);
  }
예제 #9
0
  @Command(
      name = "list",
      permission = "mytown.cmd.assistant.ranks.perm.list",
      parentName = "mytown.cmd.assistant.ranks.perm",
      syntax = "/town ranks perm list [rank]")
  public static CommandResponse ranksPermListCommand(ICommandSender sender, List<String> args) {
    Rank rank;
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    if (args.isEmpty()) {
      rank = getRankFromResident(res);
    } else {
      rank = getRankFromTown(town, args.get(0));
    }

    res.sendMessage(
        getLocal()
            .getLocalization(
                "mytown.notification.town.ranks.perm.list",
                rank.getName(),
                town.getName(),
                rank.permissionsContainer.toString()));
    return CommandResponse.DONE;
  }
예제 #10
0
    @Command(
        name = "set",
        permission = "mytown.cmd.assistant.ranks.set",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks set <rank> <type>",
        completionKeys = {"rankCompletion"})
    public static CommandResponse ranksSetCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 2) {
        return CommandResponse.SEND_SYNTAX;
      }

      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);
      Rank rank = getRankFromTown(town, args.get(0));
      Rank.Type type = getRankTypeFromString(args.get(1));

      if (type.unique) {
        Rank fromRank = town.ranksContainer.get(type);
        if (fromRank == rank) {
          throw new MyTownCommandException("mytown.cmd.err.ranks.set.already", type.toString());
        }

        fromRank.setType(Rank.Type.REGULAR);
        rank.setType(type);

        getDatasource().saveRank(rank);
        getDatasource().saveRank(fromRank);
      } else {
        if (rank.getType().unique) {
          throw new MyTownCommandException("mytown.cmd.err.ranks.set.unique", rank.getName());
        }

        rank.setType(type);

        getDatasource().saveRank(rank);
      }

      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.ranks.set.successful", rank.getName(), type.toString()));
      return CommandResponse.DONE;
    }