use of net.glowstone.net.GlowSession in project Glowstone by GlowstoneMC.
the class MessageHandler method channelActive.
@Override
public void channelActive(ChannelHandlerContext ctx) {
Channel c = ctx.channel();
GlowSession s = connectionManager.newSession(c);
if (!session.compareAndSet(null, s)) {
throw new IllegalStateException("Session may not be set more than once");
}
s.onReady();
}
use of net.glowstone.net.GlowSession 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