Пример #1
0
 @Override
 public void getParameterOptions(Spell spell, String parameterKey, Collection<String> examples) {
     if (parameterKey.equals("type")) {
         for (TreeType type : TreeType.values()) {
             examples.add(type.name().toLowerCase());
         }
     } else if (parameterKey.equals("requires_sapling")) {
         examples.addAll(Arrays.asList((BaseSpell.EXAMPLE_BOOLEANS)));
     } else {
         super.getParameterOptions(spell, parameterKey, examples);
     }
 }
Пример #2
0
	public static TreeType parseTreeString(String s, TreeType defaultTreeType)
	{
		if (s.equalsIgnoreCase("big")) return TreeType.BIG_TREE;
		if (s.equalsIgnoreCase("tall")) return TreeType.TALL_REDWOOD;

		TreeType tree = defaultTreeType;
		for (TreeType t : TreeType.values())
		{
			if (t.name().equalsIgnoreCase(s))
			{
				tree = t;
			}
		}
		return tree;
	}
Пример #3
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);
             }
         }
     }
 }
Пример #4
0
  private void printTreeType(vMessage vm) {
    String _printout = "";

    boolean _delimiterHelper = true;
    for (TreeType _treeType : TreeType.values()) {
      if (_delimiterHelper) {
        _delimiterHelper = false;
      } else {
        _printout += ", ";
      }
      _printout +=
          ((_treeType.equals(this.treeType))
                  ? ChatColor.GRAY + _treeType.name().toLowerCase()
                  : ChatColor.DARK_GRAY + _treeType.name().toLowerCase())
              + ChatColor.WHITE;
    }

    vm.custom(_printout);
  }
Пример #5
0
 @Override
 public void parameters(String[] par, com.thevoxelbox.voxelsniper.vData v) {
   if (par[1].equalsIgnoreCase("info")) {
     v.sendMessage(ChatColor.GOLD + "Tree snipe brush:");
     v.sendMessage(ChatColor.AQUA + "/b t treetype");
     printTreeType(v.vm);
     return;
   }
   for (int x = 1; x < par.length; x++) {
     try {
       this.treeType = TreeType.valueOf(par[x].toUpperCase());
       printTreeType(v.vm);
     } catch (IllegalArgumentException _ex) {
       v.vm.brushMessage("No such tree type.");
     }
   }
 }
Пример #6
0
    @Override
    public SpellResult perform(CastContext context)
    {
		Block target = context.getTargetBlock();
		if (requireSapling && target.getType() != Material.SAPLING)
		{
			return SpellResult.NO_TARGET;
		}
		if (!context.hasBuildPermission(target))
        {
			return SpellResult.INSUFFICIENT_PERMISSION;
		}

        World world = context.getWorld();
		Location treeLoc = new Location(world, target.getX(), target.getY() + 1, target.getZ(), 0, 0);

        Random random = context.getRandom();
        TreeType useType = null;
        if (treeType != null)
		{
            useType = treeType;
		}
        else
        if (biomeMap != null)
        {
            Biome biome = treeLoc.getWorld().getBiome(treeLoc.getBlockX(), treeLoc.getBlockZ());
            List<TreeType> types = biomeMap.get(biome);
            if (types != null)
            {
                useType = types.get(random.nextInt(types.size()));
            }
        }
        if (useType == null)
        {
            useType = TreeType.values()[random.nextInt(TreeType.values().length)];
        }
        UndoList restoreOnFail = new UndoList(context.getMage(), context.getSpell().getName());
        Block treeBlock = treeLoc.getBlock();
        if (!context.isDestructible(treeBlock))
        {
            return SpellResult.NO_TARGET;
        }
        restoreOnFail.add(treeBlock);
        treeLoc.getBlock().setType(Material.AIR);
		boolean result = world.generateTree(treeLoc, useType);
        if (!result) {
            UndoList undoList = new UndoList(context.getMage(), context.getSpell().getName());
            for (int z = -2; z <= 2; z++) {
                for (int x = -2; x <= 2; x++) {
                    Block clearBlock = treeBlock.getRelative(x, 0, z);
                    Block lowerBlock = clearBlock.getRelative(BlockFace.DOWN);
                    if (context.isDestructible(clearBlock) && lowerBlock.getType() != target.getType())
                    {
                        undoList.add(lowerBlock);
                        lowerBlock.setType(target.getType());
                    }
                    if (x == 0 && z == 0) continue;
                    if (!context.isDestructible(clearBlock)) continue;
                    restoreOnFail.add(clearBlock);
                    clearBlock.setType(Material.AIR);
                }
            }
            result = world.generateTree(treeLoc, useType);
            context.addWork(100);
            undoList.undo(true);
        }
        if (result) {
            context.addWork(500);
        } else {
            context.addWork(100);
            restoreOnFail.undo(true);
        }
		return result ? SpellResult.CAST : SpellResult.FAIL;
	}
Пример #7
0
	public String getTreeName(TreeType treeType)
	{
		if (treeType == null || treeType.name() == null) return "Tree";
		return treeType.name().toLowerCase();
	}
  private Object getMaterialKey(String materialName) {
    boolean isMat = false, isTree = false, isEntity = false;
    // test to see if the material has a "type" specifier, record the specifier and remover it
    if (materialName.startsWith("mat_")) {
      materialName = materialName.replaceFirst("mat\\_", "");
      isMat = true;
    } else if (materialName.startsWith("tree_")) {
      materialName = materialName.replaceFirst("tree\\_", "");
      isTree = true;
    } else if (materialName.startsWith("entity_")) {
      materialName = materialName.replaceFirst("entity\\_", "");
      isEntity = true;
    }

    // match name to bukkit objects
    TreeType treeType;
    try {
      treeType = TreeType.valueOf(materialName);
    } catch (IllegalArgumentException e) {
      treeType = null;
    }

    Material material = Material.getMaterial(materialName);
    EntityType entityType;

    try {
      entityType = EntityType.valueOf(materialName);
    } catch (IllegalArgumentException e) {
      entityType = null;
    }

    // if the type was specifically specified, thenregister only for that type of object
    // warn if that object doesn't actully match anything
    if (isMat) {
      if (material != null) return material;
      LOG.warning("config: \"" + materialName + "\" specified material but does not match one.");
    }
    if (isTree) {
      if (treeType != null) return treeType;
      LOG.warning(
          "config: \"" + materialName + "\" specified tree type name but does not match one.");
    }
    if (isEntity) {
      if (entityType != null) return entityType;
      LOG.warning(
          "config: \"" + materialName + "\" specified entity type name but does not match one.");
    }

    // wanr user if they are unsing an ambiguous name
    if (material != null && entityType != null && treeType != null)
      LOG.warning(
          "config name: \""
              + materialName
              + "\" ambiguous, could be material, tree type, or entity type.");
    if (treeType != null && material != null)
      LOG.warning(
          "config name: \"" + materialName + "\" ambiguous, could be material or tree type.");
    if (material != null && entityType != null)
      LOG.warning(
          "config name: \"" + materialName + "\" ambiguous, could be material or entity type.");
    if (treeType != null && entityType != null)
      LOG.warning(
          "config name: \"" + materialName + "\" ambiguous, could be tree type or entity type.");

    // finally just match any type
    if (material != null) return material;
    if (treeType != null) return treeType;
    if (entityType != null) return entityType;

    return null;
  }