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;
}
}
Aggregations