コード例 #1
0
ファイル: Commands.java プロジェクト: CaioRanyel/MyTown2
 public static Rank.Type getRankTypeFromString(String name) {
   try {
     return Rank.Type.valueOf(name.toUpperCase());
   } catch (IllegalArgumentException e) {
     throw new MyTownCommandException("mytown.cmd.err.ranks.typeNotExists", e, name);
   }
 }
コード例 #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;
    }