Niek Zandt
Niek Zandt

Reputation: 1

Looking for a way to find a specific block in an are

I'm trying to make a plugin that can spawn mobs above specific block with a command. The problem is that I dont really know where to start... I am basicly looking for a function or way to cycle through all of the blocks in an area and return something when it finds 1 or more of the block type.

Upvotes: 0

Views: 342

Answers (1)

ISeal
ISeal

Reputation: 21

    if (sender instanceof Player) {
        Player p = (Player) sender;
        if (p.hasPermission(command.getPermission())) {
            Location playerLoc = p.getLocation();
            org.bukkit.World world = p.getWorld();
            double startX = playerLoc.getX();
            double startY = playerLoc.getY() - 1;
            double startZ = playerLoc.getZ() - 1;
            for (int x = 0; x < Integer.valueOf(args[0]); x++) {
                for (int z = 0; z < Integer.valueOf(args[1]); z++) {
                    for (int y = 0; y <= Integer.valueOf(args[2]); y++) {
                        Location loc = new Location(world, startX + x, startY + y, startZ + z);
                        if (loc.getBlock().equals(Material.yourmaterial)){
                            //do what you want
                        }
                    }
                }
            }
        } else {
            sender.sendMessage(ChatColor.DARK_RED+"Specify the size");
        }
    }
    return true;
}

Hope that helps!

Upvotes: 1

Related Questions