Exemple #1
0
 public void loadSpellConfiguration(String dataWorld) {
   File file = this.getFile(this.getDataWorldFile(dataWorld) + "/spells/", "massivespells.config");
   try {
     if (!file.exists()) {
       file.createNewFile();
       BufferedWriter bw = new BufferedWriter(new FileWriter(file));
       bw.write("// The format for creating configurations for a new spell");
       bw.write("// [spellname],[manarequired],[cooldown],[lengthofspell(0 for default)]");
       bw.write(
           "// Once configured, you must create .class file in the /plugins/spells/classes/ folder with the name of the spell as the name of the file, with the specified format to create a custom spell.");
       bw.close();
     }
     BufferedReader br = new BufferedReader(new FileReader(file));
     String line = "";
     String[] splitted = null;
     while ((line = br.readLine()) != null) {
       if (!line.replaceAll(" ", "")
           .substring(0, 2)
           .equals("//")) { // Allows for some comments ^_^
         if (line.contains(",")) {
           splitted = line.split(",");
           String spellName = splitted[0];
           int manaRequired = Integer.parseInt(splitted[1]);
           long cooldown = Long.parseLong(splitted[2]);
           long length = Long.parseLong(splitted[3]);
           SpellType spellType = null;
           for (SpellType spelltype : SpellType.values()) {
             if (spelltype.getName().equalsIgnoreCase(splitted[4])) {
               spellType = spelltype;
             }
           }
           ArrayList<String> bonuses = new ArrayList<String>();
           for (int i = 5; i < splitted.length; i++) {
             bonuses.add(splitted[i]);
           }
           Spell spell = new Spell(spellName, cooldown, manaRequired, length, spellType, bonuses);
           GeneralData.spells.add(spell);
         } else {
           log.info("Invalid syntax for spells configuration file");
         }
       }
     }
     br.close();
   } catch (IOException ex) {
     log.info("Unable to read spell configuration file, check for errors.");
   }
 }