Package org.bukkit.configuration

Examples of org.bukkit.configuration.ConfigurationSection


            .append(System.getProperty("line.separator"));
        conf.options().header(header.toString());
        conf.options().copyDefaults(true);
        conf.options().indent(2);
       
        ConfigurationSection titleSection = conf.getConfigurationSection("Titles");
        if (titleSection == null) {
            titleSection = conf.createSection("Titles");
        }
        for (String titleKey : titleSection.getKeys(false)) {
            String titleName = conf.getString("Titles."+titleKey+".Name");
            String titleShortName = conf.getString("Titles."+titleKey+".ShortName");
            ChatColor titleColor = ChatColor.matchColor(conf.getString("Titles."+titleKey+".ChatColour", ""));
            int levelReq = conf.getInt("Titles."+titleKey+".levelReq", -1);
           
View Full Code Here


            .append(System.getProperty("line.separator"))
            .append("      y: 100")
            .append(System.getProperty("line.separator"))
            .append("      z: -150");
        conf.options().header(header.toString());
        ConfigurationSection areaSection = conf.getConfigurationSection("restrictedareas");
        if (areaSection != null) {
            for (String areaKey : areaSection.getKeys(false)) {
                String worldName = conf.getString("restrictedareas."+areaKey+".world");
                double multiplier = conf.getDouble("restrictedareas."+areaKey+".multiplier", 0.0);
                World world = Bukkit.getServer().getWorld(worldName);
                if (world == null)
                    continue;
View Full Code Here

            .append(System.getProperty("line.separator"))
            .append("Stores information about each job.").append(System.getProperty("line.separator"))
            .append(System.getProperty("line.separator"))
            .append("For example configurations, visit http://dev.bukkit.org/server-mods/jobs/.").append(System.getProperty("line.separator"))
            .toString());
        ConfigurationSection jobsSection = conf.getConfigurationSection("Jobs");
        if (jobsSection == null) {
            jobsSection = conf.createSection("Jobs");
        }
        for (String jobKey : jobsSection.getKeys(false)) {
            ConfigurationSection jobSection = jobsSection.getConfigurationSection(jobKey);
            String jobName = jobSection.getString("fullname");
            if (jobName == null) {
                Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid fullname property. Skipping job!");
                continue;
            }
           
            int maxLevel = jobSection.getInt("max-level", 0);
            if (maxLevel < 0)
                maxLevel = 0;

            Integer maxSlots = jobSection.getInt("slots", 0);
            if (maxSlots.intValue() <= 0) {
                maxSlots = null;
            }

            String jobShortName = jobSection.getString("shortname");
            if (jobShortName == null) {
                Jobs.getPluginLogger().warning("Job " + jobKey + " is missing the shortname property.  Skipping job!");
                continue;
            }
           
            String description = jobSection.getString("description", "");
           
            ChatColor color = ChatColor.WHITE;
            if (jobSection.contains("ChatColour")) {
                color = ChatColor.matchColor(jobSection.getString("ChatColour", ""));
                if (color == null) {
                    color = ChatColor.WHITE;
                    Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid ChatColour property.  Defaulting to WHITE!");
                }
            }
            DisplayMethod displayMethod = DisplayMethod.matchMethod(jobSection.getString("chat-display", ""));
            if (displayMethod == null) {
                Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid chat-display property. Defaulting to None!");
                displayMethod = DisplayMethod.NONE;
            }
           
            Parser maxExpEquation;
            String maxExpEquationInput = jobSection.getString("leveling-progression-equation");
            try {
                maxExpEquation = new Parser(maxExpEquationInput);
                // test equation
                maxExpEquation.setVariable("numjobs", 1);
                maxExpEquation.setVariable("joblevel", 1);
                maxExpEquation.getValue();
            } catch(Exception e) {
                Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid leveling-progression-equation property. Skipping job!");
                continue;
            }
           
            Parser incomeEquation;
            String incomeEquationInput = jobSection.getString("income-progression-equation");
            try {
                incomeEquation = new Parser(incomeEquationInput);
                // test equation
                incomeEquation.setVariable("numjobs", 1);
                incomeEquation.setVariable("joblevel", 1);
                incomeEquation.setVariable("baseincome", 1);
                incomeEquation.getValue();
            } catch(Exception e) {
                Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid income-progression-equation property. Skipping job!");
                continue;
            }
           
            Parser expEquation;
            String expEquationInput = jobSection.getString("experience-progression-equation");
            try {
                expEquation = new Parser(expEquationInput);
                // test equation
                expEquation.setVariable("numjobs", 1);
                expEquation.setVariable("joblevel", 1);
                expEquation.setVariable("baseexperience", 1);
                expEquation.getValue();
            } catch(Exception e) {
                Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid experience-progression-equation property. Skipping job!");
                continue;
            }
           
            // Permissions
            ArrayList<JobPermission> jobPermissions = new ArrayList<JobPermission>();
            ConfigurationSection permissionsSection = jobSection.getConfigurationSection("permissions");
            if(permissionsSection != null) {
                for(String permissionKey : permissionsSection.getKeys(false)) {
                    ConfigurationSection permissionSection = permissionsSection.getConfigurationSection(permissionKey);
                   
                    String node = permissionKey.toLowerCase();
                    if (permissionSection == null) {
                        Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid permission key" + permissionKey + "!");
                        continue;
                    }
                    boolean value = permissionSection.getBoolean("value", true);
                    int levelRequirement = permissionSection.getInt("level", 0);
                    jobPermissions.add(new JobPermission(node, value, levelRequirement));
                }
            }
           
            Job job = new Job(jobName, jobShortName, description, color, maxExpEquation, displayMethod, maxLevel, maxSlots, jobPermissions);
           
            for (ActionType actionType : ActionType.values()) {
                ConfigurationSection typeSection = jobSection.getConfigurationSection(actionType.getName());
                ArrayList<JobInfo> jobInfo = new ArrayList<JobInfo>();
                if (typeSection != null) {
                    for (String key : typeSection.getKeys(false)) {
                        ConfigurationSection section = typeSection.getConfigurationSection(key);
                        String myKey = key.toUpperCase();
                        String type = null;
                        String subType = "";
                       
                        if (myKey.contains("-")) {
                            // uses subType
                            subType = ":" + myKey.split("-")[1];
                            myKey = myKey.split("-")[0];
                        }
                        Material material = Material.matchMaterial(myKey);
                        if (material == null) {
                            // try integer method
                            Integer matId = null;
                            try {
                                matId = Integer.decode(myKey);
                            } catch (NumberFormatException e) {}
                            if (matId != null) {
                                material = Material.getMaterial(matId);
                                if (material != null) {
                                    Jobs.getPluginLogger().warning("Job " + jobKey + " " + actionType.getName() + " is using a block by number ID: " + key + "!");
                                    Jobs.getPluginLogger().warning("Please switch to using the Material name instead: "+material.toString()+"!");
                                    Jobs.getPluginLogger().warning("Blocks by number IDs may break in a future release!");
                                }
                            }
                        }
                       
                        if (material != null) {
                            // Break and Place actions MUST be blocks
                            if (actionType == ActionType.BREAK || actionType == ActionType.PLACE) {
                                if (!material.isBlock()) {
                                    Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid " + actionType.getName() + " type property: " + key + "! Material must be a block!");
                                    continue;
                                }
                            }
                            // START HACK
                            /*
                             * Historically, GLOWING_REDSTONE_ORE would ONLY work as REDSTONE_ORE, and putting
                             * GLOWING_REDSTONE_ORE in the configuration would not work.  Unfortunately, this is
                             * completely backwards and wrong.
                             *
                             * To maintain backwards compatibility, all instances of REDSTONE_ORE should normalize
                             * to GLOWING_REDSTONE_ORE, and warn the user to change their configuration.  In the
                             * future this hack may be removed and anybody using REDSTONE_ORE will have their
                             * configurations broken.
                             */
                            if (material == Material.REDSTONE_ORE) {
                                Jobs.getPluginLogger().warning("Job "+jobKey+" is using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE.");
                                Jobs.getPluginLogger().warning("Automatically changing block to GLOWING_REDSTONE_ORE.  Please update your configuration.");
                                Jobs.getPluginLogger().warning("In vanilla minecraft, REDSTONE_ORE changes to GLOWING_REDSTONE_ORE when interacted with.");
                                Jobs.getPluginLogger().warning("In the future, Jobs using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE may fail to work correctly.");
                                material = Material.GLOWING_REDSTONE_ORE;
                            }
                            // END HACK
                           
                            type = material.toString();
                        } else if (actionType == ActionType.KILL) {
                            // check entities
                            EntityType entity = EntityType.fromName(key);
                            if (entity == null) {
                                try {
                                    entity = EntityType.valueOf(key.toUpperCase());
                                } catch (IllegalArgumentException e) {}
                            }
                           
                            if (entity != null && entity.isAlive())
                                type = entity.toString();
                        }
                       
                        if (type == null) {
                            Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid " + actionType.getName() + " type property: " + key + "!");
                            continue;
                        }
                       
                        double income = section.getDouble("income", 0.0);
                        double experience = section.getDouble("experience", 0.0);
                       
                        jobInfo.add(new JobInfo(type+subType, income, incomeEquation, experience, expEquation));
                    }
                }
                job.setJobInfo(actionType, jobInfo);
View Full Code Here

protected String buildHeader() { return ""; }
// Use global defaults as the defaults for top-level sections
public ConfigurationSection createSection(String path) {
  ConfigurationSection section = super.createSection(path);
  if (section != null && section.getParent() == this) {
   Configuration defaults = this.getDefaults();
   if (defaults != null) {
    for (String key : defaults.getKeys(true))
     section.addDefault(key, defaults.get(key));
   }
  }
  return section;
}
View Full Code Here

// Compatibility with stock Bukkit getConfig()
public FileConfiguration getConfig() {
  String defaultCategory = this.getConfigManager().getDefaultCategory();
  if (defaultCategory != null) {
   ConfigurationSection section = this.getConfig(defaultCategory);
   if (section instanceof FileConfiguration)
    return (FileConfiguration) section;
  }
  return null;
}
View Full Code Here

  return this.get(category, null);
}
public ConfigurationSection get(String category, String section) {
  category = category.trim().toLowerCase();
  ConfigurationSection categorySection = this.categories.get(category);
  if (categorySection != null && section != null)
   return categorySection.getConfigurationSection(section);
  return categorySection;
}
View Full Code Here

private ConfigManager addDefaults(ConfigurationSection category,
                                   ConfigurationSection... defaults) {
  if (category != null && defaults != null) {
   for (ConfigurationSection defaultSection : defaults) {
    if (defaultSection != null) {
     ConfigurationSection defaultDefaults = defaultSection.getDefaultSection();
     if (defaultDefaults != null) {
      for (String key : defaultDefaults.getKeys(true))
       category.addDefault(key, defaultDefaults.get(key));
     }
     for (String key : defaultSection.getKeys(true))
      category.addDefault(key, defaultSection.get(key));
    }
   }
View Full Code Here

  return this.load(category);
}
public String filename(String category) {
  category = category.trim().toLowerCase();
  ConfigurationSection section = this.categories.get(category);
  if (section instanceof FileConfiguration && this.filenames.containsKey(category))
   return this.filenames.get(category);
  return null;
}
View Full Code Here

public ConfigManager save(String category, String subsection)
                      throws ConfigManagerException {
  if (category == null)
   return this.save();
  category = category.trim().toLowerCase();
  ConfigurationSection section = this.categories.get(category);
  if (section instanceof FileConfiguration && this.filenames.containsKey(category)) {
   try {
    File file = new File(this.getDataFolder(), this.filenames.get(category));
    if (subsection != null && section instanceof DirectoryConfiguration)
     ((DirectoryConfiguration) section).save(file, subsection);
View Full Code Here

        return null;
    }
   
    protected HashMap<String, Boolean> getAllPerms(String desc, String path) {
        HashMap<String, Boolean> result = new HashMap<String, Boolean>();
        ConfigurationSection node = getNode(path);
       
        int failures = 0;
        String firstFailure = "";
       
        Set<String> keys = node.getKeys(false);
        for (String key : keys) {
            if (node.isBoolean(key)) {
                result.put(key, node.getBoolean(key));
            } else {
                ++failures;
                if (firstFailure.length() == 0) {
                    firstFailure = key;
                }
View Full Code Here

TOP

Related Classes of org.bukkit.configuration.ConfigurationSection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.