use of org.bukkit.event.entity.PlayerLeashEntityEvent in project Glowstone by GlowstoneMC.
the class BlockFence method blockInteract.
@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
super.blockInteract(player, block, face, clickedLoc);
if (!player.getLeashedEntities().isEmpty()) {
LeashHitch leashHitch = GlowLeashHitch.getLeashHitchAt(block);
ImmutableList.copyOf(player.getLeashedEntities()).stream().filter(e -> !(EventFactory.getInstance().callEvent(new PlayerLeashEntityEvent(e, leashHitch, player)).isCancelled())).forEach(e -> e.setLeashHolder(leashHitch));
return true;
}
return false;
}
use of org.bukkit.event.entity.PlayerLeashEntityEvent 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