use of org.bukkit.event.player.PlayerUnleashEntityEvent in project Glowstone by GlowstoneMC.
the class GlowLivingEntity method entityInteract.
@Override
public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) {
super.entityInteract(player, message);
if (message.getAction() != Action.INTERACT.ordinal()) {
return false;
}
ItemStack handItem = InventoryUtil.itemOrEmpty(player.getInventory().getItem(message.getHandSlot()));
if (isLeashed() && player.equals(this.getLeashHolder()) && message.getHandSlot() == EquipmentSlot.HAND) {
if (EventFactory.getInstance().callEvent(new PlayerUnleashEntityEvent(this, player)).isCancelled()) {
return false;
}
setLeashHolder(null);
if (player.getGameMode() != GameMode.CREATIVE) {
world.dropItemNaturally(this.location, new ItemStack(Material.LEAD));
}
return true;
} else if (!InventoryUtil.isEmpty(handItem) && handItem.getType() == Material.LEAD) {
if (!GlowLeashHitch.isAllowedLeashHolder(this.getType()) || this.isLeashed() || EventFactory.getInstance().callEvent(new PlayerLeashEntityEvent(this, player, player)).isCancelled()) {
return false;
}
if (player.getGameMode() != GameMode.CREATIVE) {
if (handItem.getAmount() > 1) {
handItem.setAmount(handItem.getAmount() - 1);
} else {
handItem = InventoryUtil.createEmptyStack();
}
player.getInventory().setItem(message.getHandSlot(), handItem);
}
setLeashHolder(player);
return true;
}
return false;
}
Aggregations