Esempio n. 1
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;
    }
Esempio n. 2
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;
    }