Esempio n. 1
0
  public void initWorld(World world) {
    String name = world.getName();

    if (getConfig().getConfigurationSection("worlds." + name) == null)
      getConfig().createSection("worlds." + name);
    ConfigurationSection worldConfig = getConfig().getConfigurationSection("worlds." + name);
    worldConfig.addDefault("global", "none");

    Biome globalBiome;
    try {
      String gName = worldConfig.getString("global");
      if (gName.equalsIgnoreCase("none")) globalBiome = null;
      else globalBiome = Biome.valueOf(gName.toUpperCase());
    } catch (Exception e) { // unsupported global biome in config
      log.warning("[BioMed] Unrecognized global biome for world \"" + world.getName() + "\"");
      globalBiome = null;
    }
    if (globalBiome != null) {
      GlobalBlockPopulator pop = new GlobalBlockPopulator();
      pop.setBiome(globalBiome);
      world.getPopulators().add(pop);
      globalBiomes.put(name, pop);
    }

    // load regions from config (backwards compatibility)
    List<Map<?, ?>> worldRegions = null;
    try {
      worldRegions = worldConfig.getMapList("regions");
      worldConfig.set("regions", null);
    } catch (Exception e) {
      // No regions to load
      return;
    }
    if (worldRegions == null) {
      return;
    }
    boolean found = false;
    for (Map<?, ?> worldRegion : worldRegions) {
      int x, z, lx, lz;
      Biome biome;
      try {
        x = (Integer) worldRegion.get("x");
        z = (Integer) worldRegion.get("z");
        lx = (Integer) worldRegion.get("lx");
        lz = (Integer) worldRegion.get("lz");
        biome = Biome.valueOf((String) worldRegion.get("biome"));

        BioMedUtils.setBiomes(x, z, lx, lz, world, biome);
        found = true;
      } catch (Exception e) {
        log.warning(
            "[BioMed] config for world \""
                + world.getName()
                + "\" contains an invalid region. Ignoring it.");
      }
    }
    if (found) {
      log.info("[BioMed] finished importing regions for world \"" + name + "\".");
      saveConfig();
    }
  }
  public WarningActionsConfig(ConfigurationSection config) {
    isEnabled = config.getBoolean("enabled", false);
    actions = new HashMap<>();

    if (!isEnabled) return;

    ConfigurationSection actionsConf = config.getConfigurationSection("actions");

    if (actionsConf == null) return;

    for (String amount : actionsConf.getKeys(false)) {
      if (!StringUtils.isNumeric(amount)) {
        plugin.getLogger().warning("Invalid warning action, " + amount + " is not numeric");
        continue;
      }

      // New check
      List<Map<?, ?>> mapList = actionsConf.getMapList(amount);
      if (mapList != null && mapList.size() != 0) {
        List<ActionCommand> actionCommands = new ArrayList<>(mapList.size());

        for (Map<?, ?> map : mapList) {
          if (map.get("cmd") == null) {
            plugin.getLogger().severe("Missing cmd from warningActions " + amount);
            continue;
          }

          long delay = 0;

          if (map.get("delay") != null) {
            try {
              delay = Long.valueOf((Integer) map.get("delay"));
            } catch (NumberFormatException e) {
              plugin.getLogger().severe("Invalid delay for " + map.get("cmd"));
              continue;
            }

            delay = delay * 20L; // Convert from seconds to ticks
          }

          actionCommands.add(new ActionCommand((String) map.get("cmd"), delay));
        }

        this.actions.put(NumberUtils.toDouble(amount), actionCommands);
      } else {
        List<String> actions = actionsConf.getStringList(amount);
        if (actions.size() == 0) continue;

        plugin
            .getLogger()
            .warning(
                "warningActions amount "
                    + amount
                    + " is using a deprecated list, please use new cmd and delay syntax");
        List<ActionCommand> actionCommands = new ArrayList<>(actions.size());

        for (String action : actions) {
          actionCommands.add(new ActionCommand(action, 0));
        }

        this.actions.put(NumberUtils.toDouble(amount), actionCommands);
      }
    }
  }