Example #1
0
  public ConfigManager(MobManager instance) {

    this.instance = instance;

    config = instance.getConfig();

    configFile = new File(instance.getDataFolder() + File.separator + "config.yml");

    initializeConfig();

    loadConfig();

    saveConfig();
  }
Example #2
0
  public void initializeConfig() {

    boolean configFileExists = configFile.exists();

    if (configFileExists == true) {

      try {

        config.options().copyDefaults(true);
        config.load(this.configFile);

      } catch (Exception e) {

        e.printStackTrace();
      }

    } else {

      instance.getLogger().info("Creating Default Config File");

      config.options().copyDefaults(true);
    }
  }
Example #3
0
  public void loadConfig() {

    // worlds
    worlds = config.getConfigurationSection("settings.worlds");

    for (String worldKey : worlds.getKeys(false)) {

      ConfigurationSection world = worlds.getConfigurationSection(worldKey);
      String worldName = worldKey;

      List<Mob> thisWorldsMobs = new ArrayList<Mob>();

      for (String mobKey : world.getKeys(false)) {

        ConfigurationSection mob = world.getConfigurationSection(mobKey);
        ConfigurationSection drops = mob.getConfigurationSection("drops");

        String mobName = mobKey;
        Boolean spawns = mob.getBoolean("spawns");
        Integer spawnChance = mob.getInt("spawn-chance");

        Mob mobObject = new Mob(instance, mobName, spawns, spawnChance);

        if (drops == null) {

          // no custom drops

        } else {

          // custom drops
          for (String dropKey : drops.getKeys(false)) {

            String[] dropArray = drops.getString(dropKey).split(",");
            Integer dropChance = Integer.valueOf(dropArray[0]);
            Integer dropQuantity = Integer.valueOf(dropArray[1]);
            Short dropShort = (short) 0;
            Byte dropByte = (byte) 0;

            if (dropArray.length > 2) {

              dropByte = Integer.valueOf(dropArray[2]).byteValue();

              if (dropArray.length == 4) {

                dropShort = Integer.valueOf(dropArray[3]).shortValue();
              }
            }

            Drop dropObject =
                new Drop(
                    instance,
                    dropChance,
                    new ItemStack(Integer.valueOf(dropKey), dropQuantity, dropShort, dropByte));
            mobObject.addDrop(dropObject);
          }
        }

        thisWorldsMobs.add(mobObject);
      }

      instance.getLogger().info("Adding World " + worldName);
      instance.worlds.add(new World(instance, worldName, thisWorldsMobs));
    }
  }