示例#1
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);
             }
         }
     }
 }
示例#2
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 static boolean mP(final World w, final String idFrom, final String idTo) {
    final Location plot1Bottom = getPlotBottomLoc(w, idFrom);
    final Location plot2Bottom = getPlotBottomLoc(w, idTo);
    final Location plot1Top = getPlotTopLoc(w, idFrom);

    final int distanceX = plot1Bottom.getBlockX() - plot2Bottom.getBlockX();
    final int distanceZ = plot1Bottom.getBlockZ() - plot2Bottom.getBlockZ();

    for (int x = plot1Bottom.getBlockX(); x <= plot1Top.getBlockX(); x++) {
      for (int z = plot1Bottom.getBlockZ(); z <= plot1Top.getBlockZ(); z++) {
        Block plot1Block = w.getBlockAt(new Location(w, x, 0, z));
        Block plot2Block = w.getBlockAt(new Location(w, x - distanceX, 0, z - distanceZ));

        final String plot1Biome = plot1Block.getBiome().name();
        final String plot2Biome = plot2Block.getBiome().name();

        plot1Block.setBiome(Biome.valueOf(plot2Biome));
        plot2Block.setBiome(Biome.valueOf(plot1Biome));

        for (int y = 0; y < w.getMaxHeight(); y++) {
          plot1Block = w.getBlockAt(new Location(w, x, y, z));
          final int plot1Type = plot1Block.getTypeId();
          final byte plot1Data = plot1Block.getData();

          plot2Block = w.getBlockAt(new Location(w, x - distanceX, y, z - distanceZ));

          final int plot2Type = plot2Block.getTypeId();
          final byte plot2Data = plot2Block.getData();

          // plot1Block.setTypeId(plot2Type);
          plot1Block.setTypeIdAndData(plot2Type, plot2Data, false);
          plot1Block.setData(plot2Data);

          // net.minecraft.server.World world = ((org.bukkit.craftbukkit.CraftWorld) w).getHandle();
          // world.setRawTypeIdAndData(plot1Block.getX(), plot1Block.getY(), plot1Block.getZ(),
          // plot2Type, plot2Data);

          // plot2Block.setTypeId(plot1Type);
          plot2Block.setTypeIdAndData(plot1Type, plot1Data, false);
          plot2Block.setData(plot1Data);
          // world.setRawTypeIdAndData(plot2Block.getX(), plot2Block.getY(), plot2Block.getZ(),
          // plot1Type, plot1Data);
        }
      }
    }

    final HashMap<String, AthionPlot> plots = getPlots(w);

    if (plots.containsKey(idFrom)) {
      if (plots.containsKey(idTo)) {
        final AthionPlot plot1 = plots.get(idFrom);
        final AthionPlot plot2 = plots.get(idTo);

        int idX = getIdX(idTo);
        int idZ = getIdZ(idTo);
        AthionSQL.deletePlot(idX, idZ, plot2.world);
        plots.remove(idFrom);
        plots.remove(idTo);
        idX = getIdX(idFrom);
        idZ = getIdZ(idFrom);
        AthionSQL.deletePlot(idX, idZ, plot1.world);

        plot2.id = "" + idX + ";" + idZ;
        AthionSQL.addPlot(plot2, idX, idZ, w);
        plots.put(idFrom, plot2);

        for (int i = 0; i < plot2.comments.size(); i++) {
          String strUUID = "";
          UUID uuid = null;

          if (plot2.comments.get(i).length >= 3) {
            strUUID = plot2.comments.get(i)[2];
            try {
              uuid = UUID.fromString(strUUID);
            } catch (final Exception e) {
            }
          }
          AthionSQL.addPlotComment(plot2.comments.get(i), i, idX, idZ, plot2.world, uuid);
        }

        for (final String player : plot2.allowed()) {
          AthionSQL.addPlotAllowed(player, idX, idZ, plot2.world);
        }

        idX = getIdX(idTo);
        idZ = getIdZ(idTo);
        plot1.id = "" + idX + ";" + idZ;
        AthionSQL.addPlot(plot1, idX, idZ, w);
        plots.put(idTo, plot1);

        for (int i = 0; i < plot1.comments.size(); i++) {
          String strUUID = "";
          UUID uuid = null;

          if (plot1.comments.get(i).length >= 3) {
            strUUID = plot1.comments.get(i)[2];
            try {
              uuid = UUID.fromString(strUUID);
            } catch (final Exception e) {
            }
          }

          AthionSQL.addPlotComment(plot1.comments.get(i), i, idX, idZ, plot1.world, uuid);
        }

        for (final String player : plot1.allowed()) {
          AthionSQL.addPlotAllowed(player, idX, idZ, plot1.world);
        }

        setOwnerSign(w, plot1);
        setSellSign(w, plot1);
        setOwnerSign(w, plot2);
        setSellSign(w, plot2);

      } else {
        final AthionPlot plot = plots.get(idFrom);

        int idX = getIdX(idFrom);
        int idZ = getIdZ(idFrom);
        AthionSQL.deletePlot(idX, idZ, plot.world);
        plots.remove(idFrom);
        idX = getIdX(idTo);
        idZ = getIdZ(idTo);
        plot.id = "" + idX + ";" + idZ;
        AthionSQL.addPlot(plot, idX, idZ, w);
        plots.put(idTo, plot);

        for (int i = 0; i < plot.comments.size(); i++) {
          String strUUID = "";
          UUID uuid = null;

          if (plot.comments.get(i).length >= 3) {
            strUUID = plot.comments.get(i)[2];
            try {
              uuid = UUID.fromString(strUUID);
            } catch (final Exception e) {
            }
          }
          AthionSQL.addPlotComment(plot.comments.get(i), i, idX, idZ, plot.world, uuid);
        }

        for (final String player : plot.allowed()) {
          AthionSQL.addPlotAllowed(player, idX, idZ, plot.world);
        }

        setOwnerSign(w, plot);
        setSellSign(w, plot);
        removeOwnerSign(w, idFrom);
        removeSellSign(w, idFrom);
      }
    } else {
      if (plots.containsKey(idTo)) {
        final AthionPlot plot = plots.get(idTo);

        int idX = getIdX(idTo);
        int idZ = getIdZ(idTo);
        AthionSQL.deletePlot(idX, idZ, plot.world);
        plots.remove(idTo);

        idX = getIdX(idFrom);
        idZ = getIdZ(idFrom);
        plot.id = "" + idX + ";" + idZ;
        AthionSQL.addPlot(plot, idX, idZ, w);
        plots.put(idFrom, plot);

        for (int i = 0; i < plot.comments.size(); i++) {
          String strUUID = "";
          UUID uuid = null;

          if (plot.comments.get(i).length >= 3) {
            strUUID = plot.comments.get(i)[2];
            try {
              uuid = UUID.fromString(strUUID);
            } catch (final Exception e) {
            }
          }
          AthionSQL.addPlotComment(plot.comments.get(i), i, idX, idZ, plot.world, uuid);
        }

        for (final String player : plot.allowed()) {
          AthionSQL.addPlotAllowed(player, idX, idZ, plot.world);
        }

        setOwnerSign(w, plot);
        setSellSign(w, plot);
        removeOwnerSign(w, idTo);
        removeSellSign(w, idTo);
      }
    }

    return true;
  }
示例#4
0
 static {
   List<Biome> temp = new ArrayList<Biome>();
   EnumSet<Biome> set = null;
   try {
     temp.add(Biome.valueOf("RIVER"));
     temp.add(Biome.valueOf("OCEAN"));
     temp.add(Biome.valueOf("DEEP_OCEAN"));
   } catch (Exception e) {
     temp.clear();
   } finally {
     try {
       set = EnumSet.copyOf(temp);
     } catch (IllegalArgumentException e) {
       mcMMO.p.getLogger().severe("Biome enum mismatch");
       ;
     }
     temp.clear();
   }
   WATER_BIOMES = set;
   set = null;
   try {
     temp.add(Biome.valueOf("FROZEN_OCEAN"));
     temp.add(Biome.valueOf("FROZEN_RIVER"));
     temp.add(Biome.valueOf("TAIGA"));
     temp.add(Biome.valueOf("TAIGA_HILLS"));
     temp.add(Biome.valueOf("TAIGA_COLD_HILLS"));
     temp.add(Biome.valueOf("TAIGA_COLD"));
     temp.add(Biome.valueOf("MUTATED_TAIGA_COLD"));
     temp.add(Biome.valueOf("ICE_MOUNTAINS"));
     temp.add(Biome.valueOf("ICE_FLATS"));
     temp.add(Biome.valueOf("MUTATED_ICE_FLATS"));
   } catch (Exception e) {
     temp.clear();
     try {
       temp.add(Biome.valueOf("FROZEN_OCEAN"));
       temp.add(Biome.valueOf("FROZEN_RIVER"));
       temp.add(Biome.valueOf("TAIGA"));
       temp.add(Biome.valueOf("TAIGA_HILLS"));
       temp.add(Biome.valueOf("TAIGA_MOUNTAINS"));
       temp.add(Biome.valueOf("COLD_TAIGA"));
       temp.add(Biome.valueOf("COLD_TAIGA_HILLS"));
       temp.add(Biome.valueOf("COLD_TAIGA_MOUNTAINS"));
       temp.add(Biome.valueOf("ICE_MOUNTAINS"));
       temp.add(Biome.valueOf("ICE_PLAINS"));
       temp.add(Biome.valueOf("ICE_PLAINS_SPIKES"));
     } catch (Exception e1) {
       temp.clear();
     }
   } finally {
     try {
       set = EnumSet.copyOf(temp);
     } catch (IllegalArgumentException e) {
       mcMMO.p.getLogger().severe("Biome enum mismatch");
       ;
     }
     temp.clear();
   }
   ICE_BIOMES = set;
 }
  private void loadGrowthConfigs(ConfigurationSection config) {

    // load names that map to lists of biomes to be used as shorthand for those biomes
    ConfigurationSection biomeAliasSection = config.getConfigurationSection("biome_aliases");
    HashMap<String, List<Biome>> biomeAliases = new HashMap<String, List<Biome>>();
    for (String alias : biomeAliasSection.getKeys(false)) {
      // convert list of strings into list of biomes
      List<String> biomeStrs = biomeAliasSection.getStringList(alias);
      List<Biome> biomes = new ArrayList<Biome>();
      for (String biomeStr : biomeStrs) {
        try {
          Biome biome = Biome.valueOf(biomeStr);
          biomes.add(biome);
        } catch (IllegalArgumentException e) {
          LOG.warning(
              "loading configs: in biome_aliases: \"" + biomeStr + "\" is not a valid biome name.");
        }
      }

      // map those biomes to an alias
      biomeAliases.put(alias, biomes);
    }

    GrowthConfig defaultConfig = new GrowthConfig();

    materialGrowth = new HashMap<Object, GrowthConfig>();
    HashMap<String, GrowthConfig> growthConfigNodes = new HashMap<String, GrowthConfig>();

    ConfigurationSection growthConfigSection = config.getConfigurationSection("growth");
    for (String materialName : growthConfigSection.getKeys(false)) {
      ConfigurationSection configSection =
          growthConfigSection.getConfigurationSection(materialName);

      GrowthConfig inheritConfig = defaultConfig;

      if (configSection.isSet("inherit")) {
        String inheritStr = configSection.getString("inherit");

        if (growthConfigNodes.containsKey(inheritStr)) {
          inheritConfig = growthConfigNodes.get(inheritStr);
        } else {
          Object inheritKey = getMaterialKey(inheritStr);
          if (materialGrowth.containsKey(inheritKey)) {
            inheritConfig = materialGrowth.get(inheritKey);
          }
        }
      }

      GrowthConfig newGrowthConfig = new GrowthConfig(inheritConfig, configSection, biomeAliases);

      Object key = getMaterialKey(materialName);
      if (key == null) {
        // if the name is partially capitalized, then warning the player that
        // the name might be a misspelling
        if (materialName.length() > 0 && materialName.matches(".*[A-Z].*"))
          LOG.warning("config material name: is \"" + materialName + "\" misspelled?");
        growthConfigNodes.put(materialName, newGrowthConfig);
      } else {
        materialGrowth.put(key, newGrowthConfig);
      }
    }
  }