use of org.bukkit.event.player.PlayerAnimationEvent in project Glowstone by GlowstoneMC.
the class PlayerSwingArmHandler method handle.
@Override
public void handle(GlowSession session, PlayerSwingArmMessage message) {
GlowPlayer player = session.getPlayer();
Block block;
try {
block = player.getTargetBlock((Set<Material>) null, 6);
} catch (IllegalStateException ex) {
// getTargetBlock failed to find any block at all
block = null;
}
if (block == null || block.isEmpty()) {
if (EventFactory.onPlayerInteract(player, Action.LEFT_CLICK_AIR).useItemInHand() == Result.DENY)
return;
// todo: item interactions with air
}
if (!EventFactory.callEvent(new PlayerAnimationEvent(player)).isCancelled()) {
// play the animation to others
Message toSend = new AnimateEntityMessage(player.getEntityId(), message.getHand() == 1 ? AnimateEntityMessage.SWING_OFF_HAND : AnimateEntityMessage.SWING_MAIN_HAND);
player.getWorld().getRawPlayers().stream().filter(observer -> observer != player && observer.canSeeEntity(player)).forEach(observer -> observer.getSession().send(toSend));
}
}
Aggregations