Search in sources :

Example 1 with SheepDyeWoolEvent

use of org.bukkit.event.entity.SheepDyeWoolEvent in project Glowstone by GlowstoneMC.

the class GlowSheep method entityInteract.

@Override
public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) {
    super.entityInteract(player, message);
    if (!isAdult())
        return false;
    if (player.getGameMode().equals(GameMode.SPECTATOR))
        return false;
    if (player.getItemInHand() == null)
        return false;
    switch(player.getItemInHand().getType()) {
        case SHEARS:
            if (isSheared())
                return false;
            if (!player.getGameMode().equals(GameMode.CREATIVE)) {
                ItemStack shears = player.getItemInHand();
                if (shears.getDurability() < 238) {
                    shears.setDurability((short) (shears.getDurability() + 1));
                } else {
                    player.getInventory().clear(player.getInventory().getHeldItemSlot());
                }
            }
            getWorld().playSound(getLocation(), Sound.ENTITY_SHEEP_SHEAR, 1, 1);
            Random r = new Random();
            getWorld().dropItemNaturally(getLocation(), new ItemStack(Material.WOOL, r.nextInt(3) + 1, getColor().getWoolData()));
            setSheared(true);
            return true;
        case INK_SACK:
            {
                Dye dye = (Dye) player.getItemInHand().getData();
                DyeColor color = dye.getColor();
                SheepDyeWoolEvent event = new SheepDyeWoolEvent(this, color);
                if (event.isCancelled())
                    return false;
                color = event.getColor();
                if (color.equals(getColor())) {
                    return false;
                }
                if (!player.getGameMode().equals(GameMode.CREATIVE)) {
                    if (player.getItemInHand().getAmount() > 1) {
                        player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
                    } else {
                        player.getInventory().clear(player.getInventory().getHeldItemSlot());
                    }
                }
                setColor(color);
                return true;
            }
        default:
            return false;
    }
}
Also used : Dye(org.bukkit.material.Dye) SheepDyeWoolEvent(org.bukkit.event.entity.SheepDyeWoolEvent) Random(java.util.Random) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

Random (java.util.Random)1 SheepDyeWoolEvent (org.bukkit.event.entity.SheepDyeWoolEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1 Dye (org.bukkit.material.Dye)1