// A program from Chapter 23 of Sams Teach Yourself Java in 24 Hours // by Rogers Cadenhead, http://www.java24hours.com/ package com.java24hours; import java.util.List; import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class ChickenSummoner extends JavaPlugin { public static final Logger LOG = Logger.getLogger("Minecraft"); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] arguments) { if (sender instanceof Player) { if (label.equalsIgnoreCase("bokbokbok")) { find(sender, arguments); } return true; } return false; } public void find(CommandSender sender, String[] arguments) { Player me = (Player) sender; Location spot = me.getLocation(); World world = me.getWorld(); int range = 250; me.sendMessage("Looking for chickens ..."); // store the mobs in a list List current = world.getLivingEntities(); int chickenCount = 0; int distance; // loop through all the mobs found for (Entity mob : current) { if (mob.getType() == EntityType.CHICKEN) { distance = 5; while (true) { Location chickenSpot = new Location( world, spot.getX() + Math.floor(Math.random() * distance - (distance / 2)), spot.getY() + Math.floor(Math.random() * distance + 1), spot.getZ() + Math.floor(Math.random() * distance - (distance / 2)) ); if (chickenSpot.getBlock().getType() != Material.AIR) { distance++; continue; } mob.teleport(chickenSpot); chickenCount++; break; } } } me.sendMessage("Ain't nobody here but us chickens (" + chickenCount + " to be precise)"); } }