Ejemplo n.º 1
0
 public static FlagType getFlagTypeFromName(String name) {
   try {
     return FlagType.valueOf(name.toUpperCase());
   } catch (IllegalArgumentException e) {
     throw new MyTownCommandException("mytown.cmd.err.flagNotExists", e, name);
   }
 }
Ejemplo n.º 2
0
 @Override
 public Flag deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   JsonObject jsonObject = json.getAsJsonObject();
   FlagType flagType = FlagType.valueOf(jsonObject.get("flagType").getAsString());
   return new Flag(flagType, jsonObject.get("value").getAsString());
 }
Ejemplo n.º 3
0
 @SuppressWarnings("unchecked")
 @Override
 public void create(List<Flag> items) {
   for (FlagType type : FlagType.values()) {
     if (type.isWildPerm) {
       items.add(new Flag(type, type.defaultWildValue));
     }
   }
   super.create(items);
 }
Ejemplo n.º 4
0
 public static Flag getFlagFromName(Flag.Container flagsContainer, String name) {
   Flag flag;
   try {
     flag = flagsContainer.get(FlagType.valueOf(name.toUpperCase()));
   } catch (IllegalArgumentException ex) {
     throw new MyTownCommandException("mytown.cmd.err.flagNotExists", ex, name);
   }
   if (flag == null) throw new MyTownCommandException("mytown.cmd.err.flagNotExists", name);
   return flag;
 }
Ejemplo n.º 5
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);
  }
Ejemplo n.º 6
0
  @SuppressWarnings("unchecked")
  @Override
  public boolean validate(List<Flag> items) {
    boolean isValid = true;

    for (Iterator<Flag> it = items.iterator(); it.hasNext(); ) {
      Flag item = it.next();
      if (item.flagType == null) {
        MyTown.instance.LOG.error("An unrecognized flagType has been found. Removing...");
        it.remove();
        isValid = false;
        continue;
      }
      if (!item.flagType.isWildPerm) {
        MyTown.instance.LOG.error(
            "A non wild flagType has been found in WildPerms config file. Removing...");
        it.remove();
        isValid = false;
      }
    }

    for (FlagType type : FlagType.values()) {
      if (type.isWildPerm) {
        boolean ok = false;
        for (Flag f : items) {
          if (f.flagType == type) {
            ok = true;
          }
        }
        if (!ok) {
          MyTown.instance.LOG.error(
              "FlagType {} for Wild does not exist in the WildPerms file. Adding...", type.name);
          items.add(new Flag(type, type.defaultValue));
          isValid = false;
        }
      }
    }
    return isValid;
  }
Ejemplo n.º 7
0
 public static Flag getFlagFromType(Flag.Container flagsContainer, FlagType flagType) {
   Flag flag = flagsContainer.get(flagType);
   if (flag == null)
     throw new MyTownCommandException("mytown.cmd.err.flagNotExists", flagType.toString());
   return flag;
 }