package dk.thoerup.bukkit.hoeruputils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; public class ChestFillerAll implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (! (sender instanceof Player) ) { sender.sendMessage("this is not a console command!"); return true; } Player player = (Player) sender; World world = player.getWorld(); if ( ! world.getName().equals("creative")) { sender.sendMessage("May ONLY be used in creative"); return true; } Location loc = player.getLocation(); for (int x = loc.getBlockX()-10; x<= loc.getBlockX()+10; x++) { for (int y = loc.getBlockY()-10; y<= loc.getBlockY()+10; y++) { if (y<=0) { continue; } for (int z = loc.getBlockZ()-10; z<= loc.getBlockZ()+10; z++) { Block block = world.getBlockAt(x, y, z); handleBlock(block); } } } return true; } private void handleBlock(Block block) { Material mat = block.getType(); if (mat != Material.CHEST) { return; } Chest chest = (Chest) block.getState(); Inventory inv = chest.getInventory(); ItemStack items = new ItemStack(Material.SNOW_BALL, 16); for (int i = 0; i< inv.getSize(); i++) { inv.setItem(i, items); } } }