Esempio n. 1
0
  // TODO: Convert this to use one of the new text classes?
  public static String listKits(final IEssentials ess, final User user) throws Exception {
    try {
      final ConfigurationSection kits = ess.getSettings().getKits();
      final StringBuilder list = new StringBuilder();
      for (String kitItem : kits.getKeys(false)) {
        if (user == null) {
          list.append(" ").append(capitalCase(kitItem));
        } else if (user.isAuthorized("essentials.kits." + kitItem.toLowerCase(Locale.ENGLISH))) {
          String cost = "";
          String name = capitalCase(kitItem);
          BigDecimal costPrice =
              new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user);
          if (costPrice.signum() > 0) {
            cost = tl("kitCost", NumberUtil.displayCurrency(costPrice, ess));
          }

          Kit kit = new Kit(kitItem, ess);
          if (kit.getNextUse(user) != 0) {
            name = tl("kitDelay", name);
          }

          list.append(" ").append(name).append(cost);
        }
      }
      return list.toString().trim();
    } catch (Exception ex) {
      throw new Exception(tl("kitError"), ex);
    }
  }
Esempio n. 2
0
  @Override
  public ResourceFactory parse(ConfigurationSection input, String key) throws ParsingException {

    if (input == null) throw new NullArgumentException("input");
    if (key == null) throw new NullArgumentException("key");

    // Move to the next section
    if (key != null && input.isConfigurationSection(key)) {
      input = input.getConfigurationSection(key);
    }

    ItemsFactory factory = new ItemsFactory();

    for (String node : input.getKeys(false)) {

      Query query = itemParser.parse(node);

      // Handle both item queries and potion queries
      if (query instanceof ItemQuery)
        factory.addItems((ItemQuery) query, rangeParser.parse(input, node));
      else if (query instanceof PotionQuery)
        factory.addItems(((PotionQuery) query).toItemQuery(true), rangeParser.parse(input, node));
      else throw ParsingException.fromFormat("Unable to parse range on item %s.", key);
    }

    return factory;
  }
Esempio n. 3
0
 // ItemStack
 public static HashMap<Integer, ItemStack> loadInventory(final ConfigurationSection config) {
   final Set<String> entries = config.getKeys(false);
   final HashMap<Integer, ItemStack> res = new HashMap<Integer, ItemStack>(entries.size());
   for (final String key : entries)
     res.put(Integer.parseInt(key), loadItemStack(config.getConfigurationSection(key)));
   return res;
 }
Esempio n. 4
0
 private boolean importIsland(uSkyBlock plugin, File file) {
   log.info("Importing " + file);
   FileConfiguration config = new YamlConfiguration();
   readConfig(config, file);
   if (config.contains("party.leader") && !config.contains("party.leader.name")) {
     String leaderName = config.getString("party.leader");
     ConfigurationSection leaderSection = config.createSection("party.leader");
     leaderSection.set("name", leaderName);
     leaderSection.set("uuid", UUIDUtil.asString(getUUID(leaderName)));
   }
   ConfigurationSection members = config.getConfigurationSection("party.members");
   if (members != null) {
     for (String member : members.getKeys(false)) {
       ConfigurationSection section = members.getConfigurationSection(member);
       if (!section.contains("name")) {
         members.set(member, null);
         String uuid = UUIDUtil.asString(getUUID(member));
         members.createSection(uuid, section.getValues(true));
         members.set(uuid + ".name", member);
       } else {
         log.info("Skipping " + member + ", already has a name");
       }
     }
   }
   try {
     config.save(file);
     return true;
   } catch (IOException e) {
     log.log(Level.SEVERE, "Failed to import " + file, e);
     return false;
   }
 }
 public static void loadClasses(ConfigurationSection cs) {
   if (cs == null) {
     Log.info(BattleArena.getPName() + " has no classes");
     return;
   }
   StringBuilder sb = new StringBuilder();
   Set<String> keys = cs.getKeys(false);
   boolean first = true;
   for (String className : keys) {
     ArenaClass ac = parseArenaClass(cs.getConfigurationSection(className));
     if (ac == null) continue;
     if (first) first = false;
     else sb.append(", ");
     sb.append(ac.getName());
     ArenaClassController.addClass(ac);
   }
   if (first) {
     Log.info(
         BattleArena.getPName()
             + " no predefined classes found. inside of "
             + cs.getCurrentPath());
   } else {
     Log.info(BattleArena.getPName() + " registering classes: " + sb.toString());
   }
 }
Esempio n. 6
0
 @Override
 public void initialize(Spell spell, ConfigurationSection parameters)
 {
     super.initialize(spell, parameters);
     if (parameters.contains("biomes"))
     {
         ConfigurationSection biomeConfig = ConfigurationUtils.getConfigurationSection(parameters, "biomes");
         biomeMap = new HashMap<>();
         Collection<String> biomeKeys = biomeConfig.getKeys(false);
         for (String biomeKey : biomeKeys)
         {
             try {
                 Biome biome = Biome.valueOf(biomeKey.toUpperCase());
                 List<String> treeTypes = ConfigurationUtils.getStringList(biomeConfig, biomeKey);
                 for (String typeKey : treeTypes)
                 {
                     try {
                         TreeType treeType = TreeType.valueOf(typeKey.toUpperCase());
                         List<TreeType> biomeTypes = biomeMap.get(biome);
                         if (biomeTypes == null) {
                             biomeTypes = new ArrayList<>();
                             biomeMap.put(biome, biomeTypes);
                         }
                         biomeTypes.add(treeType);
                     } catch (Exception treeEx) {
                         Bukkit.getLogger().warning("Invalid tree type: " + typeKey);
                     }
                 }
             } catch (Exception biomeEx) {
                 Bukkit.getLogger().warning("Invalid biome: " + biomeKey);
             }
         }
     }
 }
  public static AbstractRewardSettings<EntityType> parseConfig(ConfigurationSection config) {
    Map<EntityType, List<AbstractRewardSource>> sources =
        new HashMap<EntityType, List<AbstractRewardSource>>();
    ConfigurationSection rewardTable = config.getConfigurationSection("RewardTable");

    if (rewardTable != null) {
      for (String typeName : rewardTable.getKeys(false)) {
        EntityType type = EntityType.fromName(typeName);

        if (type != null) {
          AbstractRewardSource source =
              configureRewardSource(
                  RewardSourceFactory.createSource(
                      typeName, rewardTable.getConfigurationSection(typeName)),
                  config);

          if (!sources.containsKey(type)) {
            sources.put(type, new ArrayList<AbstractRewardSource>());
          }

          sources
              .get(type)
              .add(
                  mergeSets(
                      source,
                      rewardTable.getConfigurationSection(typeName),
                      config.getConfigurationSection("RewardSets")));
        }
      }
    }

    EntityRewardSettings settings = new EntityRewardSettings(sources);
    settings.setHuntingRules(loadHuntingRules(config));
    return settings;
  }
 private static ConfigurationSection getSection(String name) {
   ConfigurationSection section = yaml.getConfigurationSection(name);
   if (section == null)
     for (String key : yaml.getKeys(false))
       if (key.equalsIgnoreCase(name)) section = yaml.getConfigurationSection(key);
   return section;
 }
Esempio n. 9
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 protected List getList(Field field, ConfigurationSection cs, String path, int depth)
     throws Exception {
   depth++;
   int listSize = cs.getKeys(false).size();
   String key = path;
   if (key.lastIndexOf(".") >= 0) {
     key = key.substring(key.lastIndexOf("."));
   }
   List list = new ArrayList();
   if (listSize > 0) {
     int loaded = 0;
     int i = 0;
     while (loaded < listSize) {
       if (cs.isSet(key + i)) {
         Object in = cs.get(key + i);
         in = loadObject(field, cs, key + i, depth);
         list.add(in);
         loaded++;
       }
       i++;
       // ugly overflow guard... should only be needed if config was manually edited very badly
       if (i > (listSize * 3)) loaded = listSize;
     }
   }
   return list;
 }
Esempio n. 10
0
 /**
  * Loads a list of ItemStack objects from a ConfigurationSection.
  *
  * @param section Where to read the saved list.
  * @return A correctly build List of Itemstack Objects.
  */
 public static List<ItemStack> loadItemStack(ConfigurationSection section) {
   List<ItemStack> stacks = new LinkedList<>();
   for (String key : section.getKeys(false)) {
     stacks.add((ItemStack) section.get(key));
   }
   return stacks;
 }
Esempio n. 11
0
 public void load(MagickElement element, ConfigurationSection spellSection) throws Exception {
   for (String spellKey : spellSection.getKeys(false)) {
     ConfigurationSection spell = spellSection.getConfigurationSection(spellKey);
     SpellEntry spellEntry = new SpellEntry(this.element);
     spellEntry.load(element, spell);
     spellRegistries.put(spellKey, spellEntry);
   }
 }
 public void setCooldown(String command, OfflinePlayer p) {
   ConfigurationSection cmdCds = plugin.getConfig().getConfigurationSection("command_cooldowns");
   if (cmdCds == null) return;
   boolean contains = cmdCds.getKeys(false).contains(command);
   if (plugin.cooldownAliases)
     if (plugin.getCommand(command) != null)
       for (String alias : plugin.getCommand(command).getAliases())
         if (cmdCds.getKeys(false).contains(alias)) {
           contains = true;
           break;
         }
   if (contains) {
     long cooldown = cmdCds.getLong(command);
     PConfManager.setPValLong(
         p, new Date().getTime() + (cooldown * 1000), "command_cooldowns." + command);
   }
 }
 private Set<ChatColor> possibleColors() {
   Set<ChatColor> result = EnumSet.noneOf(ChatColor.class);
   ConfigurationSection colorSection = getConfig().getConfigurationSection("colors");
   for (String colorName : colorSection.getKeys(false)) {
     ConfigurationSection singleColor = colorSection.getConfigurationSection(colorName);
     result.add(ChatColor.getByChar(singleColor.getString("code")));
   }
   return result;
 }
 private ChatColor getPermColor(Player player) {
   ConfigurationSection colorSection = getConfig().getConfigurationSection("colors");
   for (String colorName : colorSection.getKeys(false)) {
     if (player.hasPermission("coloredplayernames." + colorName)) {
       return ChatColor.getByChar(colorSection.getString(colorName + ".code"));
     }
   }
   return null;
 }
 /**
  * Gets the group of a world.
  *
  * @param w World to get group of
  * @return String of group name or null if no group
  */
 public String getWorldGroup(World w) {
   ConfigurationSection cs =
       this.plugin.getConfig().getConfigurationSection("worldmanager.inventory_separation.groups");
   Set<String> s = cs.getKeys(false);
   for (String group : s) {
     List<String> worlds = cs.getStringList(group);
     if (worlds.contains(w.getName())) return group;
   }
   return null;
 }
Esempio n. 16
0
 /** Method to add all the head kits to the kit list */
 private void parseKits() {
   ConfigurationSection headSec =
       plugin.getConfigManager().getConfig("kits.yml").getConfig().getConfigurationSection("kits");
   for (String s : headSec.getKeys(false)) {
     Kit newKit = parseKit(headSec.getConfigurationSection(s), s);
     if (newKit != null) {
       headKits.add(newKit);
     }
   }
 }
Esempio n. 17
0
 /** Get all boughthomes from the config */
 private void getBoughtHomes() {
   if (config.contains("boughthome")) { // See if the config contains the boughthomes section
     ConfigurationSection boughtConfig =
         config.getConfigurationSection("boughthome"); // Get the section
     for (String key : boughtConfig.getKeys(false)) { // Loop thru all players
       boughtHomes.put(
           Integer.valueOf(key), boughtConfig.getInt(key)); // Put the player in the map
     }
   }
 }
 private double weight(ChatColor color) {
   ConfigurationSection colorSection = getConfig().getConfigurationSection("colors");
   for (String colorName : colorSection.getKeys(false)) {
     ConfigurationSection singleColor = colorSection.getConfigurationSection(colorName);
     if (singleColor.getString("code").equals(String.valueOf(color.getChar()))) {
       return singleColor.getDouble("weight");
     }
   }
   return 0.0;
 }
Esempio n. 19
0
 public static <T> List<T> loadList(
     final ConfigurationSection config,
     final Class<T> parentClazz,
     final Class<?>[] paraClazzes,
     final Object[] paraObjects) {
   final ArrayList<T> list = new ArrayList<T>();
   if (config == null) return list;
   for (final String key : config.getKeys(false))
     list.add(load(config.getConfigurationSection(key), parentClazz, paraClazzes, paraObjects));
   return list;
 }
Esempio n. 20
0
  /**
   * Util for YAMLReader to get all child-keys as Set<String> for a given Node
   *
   * @param config the YAMLConfiguration to search through
   * @param yamlNode the Node to get the children from
   * @return the children as Set<String>
   */
  public Set<String> getYAMLChildren(String yamlNode) {
    try {
      ConfigurationSection tempMem = getConfigurationSection(yamlNode);
      Set<String> tempSet = tempMem.getKeys(false);
      return tempSet;

    } catch (Exception e) {
      Set<String> empty = new LinkedHashSet<String>();
      return empty;
    }
  }
 @Override
 protected void load(ConfigurationSection config) {
   super.load(config);
   offers.clear();
   ConfigurationSection costsSection = config.getConfigurationSection("costs");
   if (costsSection != null) {
     for (String key : costsSection.getKeys(false)) {
       offers.put(key, costsSection.getInt(key));
     }
   }
 }
Esempio n. 22
0
 public Map<String, String[]> getCommandAliases() {
   Map<String, String[]> aliases = new HashMap<String, String[]>();
   ConfigurationSection section = config.getConfigurationSection("aliases");
   if (section == null) return aliases;
   List<String> cmdAliases = new ArrayList<String>();
   for (String key : section.getKeys(false)) {
     cmdAliases.clear();
     cmdAliases.addAll(section.getStringList(key));
     aliases.put(key, cmdAliases.toArray(new String[cmdAliases.size()]));
   }
   return aliases;
 }
Esempio n. 23
0
 public ArrayList<ItemStack> deserializeIngredients(ConfigurationSection matSection) {
   ArrayList<ItemStack> ingredients = new ArrayList<ItemStack>();
   for (String mat : matSection.getKeys(false)) {
     String[] matSplit = mat.split(",");
     ItemStack item = new ItemStack(Material.getMaterial(matSplit[0]), matSection.getInt(mat));
     if (matSplit.length == 2) {
       item.setDurability((short) P.p.parseInt(matSplit[1]));
     }
     ingredients.add(item);
   }
   return ingredients;
 }
 private void setPlayers() {
   ConfigurationSection section =
       this.getConfiguration().getConfigurationSection("reserved-players");
   this.reservedPlayers.clear();
   for (String key : section.getKeys(false)) {
     try {
       this.reservedPlayers.put(key, ReservationType.valueOf(section.getString(key)));
     } catch (final IllegalArgumentException exception) {
       this.getLogger().warning(this, "invalid-reservation", key);
     }
   }
 }
Esempio n. 25
0
 @Override
 public void loadSettings(FileConfiguration config) {
   ConfigurationSection sectionE = config.getConfigurationSection("Skills.Weaponry.Entities");
   ConfigurationSection section = config.getConfigurationSection("Skills.Weaponry");
   if (sectionE.getKeys(false) != null) {
     for (String s : sectionE.getKeys(false)) {
       if (EntityType.valueOf(s.toUpperCase()) != null) {
         EntityType type = EntityType.valueOf(s.toUpperCase());
         Double val = sectionE.getDouble(s);
         entities.put(type, val);
       }
     }
   }
   if (section.getStringList("Weapons") != null) {
     for (String s : section.getStringList("Weapons")) {
       if (Material.valueOf(s.toUpperCase()) != null) {
         Material type = Material.valueOf(s.toUpperCase());
         weapons.add(type);
       }
     }
   }
 }
Esempio n. 26
0
 private List<ServerInfo> loadServers() {
   List<ServerInfo> list = new ArrayList<>();
   ConfigurationSection server = config.getConfigurationSection("servers");
   for (String servername : server.getKeys(false)) {
     ConfigurationSection cs = server.getConfigurationSection(servername);
     String displayname = cs.getString("displayname");
     String[] addre = cs.getString("address").split(":");
     InetSocketAddress address = new InetSocketAddress(addre[0], Integer.parseInt(addre[1]));
     ServerInfo si = new ServerInfo(servername, address, displayname);
     list.add(si);
   }
   return list;
 }
Esempio n. 27
0
  @Override
  public Map<String, List<String>> getAllWorldInheritance() {
    ConfigurationSection worldsSection = this.permissions.getConfigurationSection("worlds");
    if (worldsSection == null) {
      return Collections.emptyMap();
    }

    Map<String, List<String>> ret = new HashMap<String, List<String>>();
    for (String world : worldsSection.getKeys(false)) {
      ret.put(world, getWorldInheritance(world));
    }
    return Collections.unmodifiableMap(ret);
  }
Esempio n. 28
0
  @Override
  public PermissionUser[] getRegisteredUsers() {
    List<PermissionUser> users = new LinkedList<PermissionUser>();
    ConfigurationSection usersSection = this.permissions.getConfigurationSection("users");

    if (usersSection != null) {
      for (String userName : usersSection.getKeys(false)) {
        users.add(this.manager.getUser(userName));
      }
    }

    return users.toArray(new PermissionUser[users.size()]);
  }
 public static List<Scoreboard> load(FileConfiguration config) {
   List<Scoreboard> scoreboards = new ArrayList<>();
   ConfigurationSection boards = config.getConfigurationSection("boards");
   if (boards != null) {
     for (String id : boards.getKeys(false)) {
       ConfigurationSection section = boards.getConfigurationSection(id);
       if (section != null) {
         scoreboards.add(loadScoreboard(section, id));
       }
     }
   }
   return scoreboards;
 }
Esempio n. 30
0
 @Override
 public Map<String, String[]> getCommandAliases() {
   Map<String, String[]> aliases = new HashMap<>();
   ConfigurationSection section =
       config.getConfigFile(ServerConfig.Key.COMMANDS_FILE).getConfigurationSection("aliases");
   if (section == null) {
     return aliases;
   }
   for (String key : section.getKeys(false)) {
     List<String> list = section.getStringList(key);
     aliases.put(key, list.toArray(new String[list.size()]));
   }
   return aliases;
 }