Ejemplo n.º 1
0
  @CommandNode(
      name = "set",
      permission = "mytown.cmd.assistant.perm.town.set",
      parentName = "mytown.cmd.assistant.perm.town",
      completionKeys = "flagCompletion")
  public static void permSetTownCommand(ICommandSender sender, List<String> args) {

    if (args.size() < 2)
      throw new WrongUsageException(getLocal().getLocalization("mytown.cmd.err.perm.set.usage"));
    Resident res = getDatasource().getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    Flag flag = getFlagFromTown(town, args.get(0));

    if (flag.setValueFromString(args.get(1))) {
      ChatUtils.sendLocalizedChat(
          sender,
          getLocal(),
          "mytown.notification.town.perm.set.success",
          args.get(0),
          args.get(1));
    } else
      throw new CommandException(
          getLocal().getLocalization("mytown.cmd.err.perm.valueNotValid", args.get(1)));
    getDatasource().saveFlag(flag, town);
  }
Ejemplo n.º 2
0
  @Command(
      name = "toggle",
      permission = "mytown.cmd.assistant.perm.toggle",
      parentName = "mytown.cmd.everyone.perm",
      syntax = "/town perm toggle <flag>",
      completionKeys = "flagCompletion")
  public static CommandResponse permToggleCommand(ICommandSender sender, List<String> args) {

    if (args.size() < 1) return CommandResponse.SEND_SYNTAX;
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    Flag flag = getFlagFromName(town.flagsContainer, args.get(0));

    if (!flag.flagType.configurable) {
      throw new MyTownCommandException("mytown.cmd.err.flag.unconfigurable", args.get(0));
    } else {
      if (flag.toggle()) {
        ChatUtils.sendLocalizedChat(sender, getLocal(), "mytown.notification.perm.success");
      } else {
        throw new MyTownCommandException("mytown.cmd.err.perm.valueNotValid", args.get(1));
      }
    }
    getDatasource().saveFlag(flag, town);
    return CommandResponse.DONE;
  }