Search in sources :

Example 1 with GlowSession

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();
}
Also used : GlowSession(net.glowstone.net.GlowSession) Channel(io.netty.channel.Channel)

Example 2 with GlowSession

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));
    }
}
Also used : EventFactory(net.glowstone.EventFactory) PlayerAnimationEvent(org.bukkit.event.player.PlayerAnimationEvent) Message(com.flowpowered.network.Message) Set(java.util.Set) GlowPlayer(net.glowstone.entity.GlowPlayer) Result(org.bukkit.event.Event.Result) Action(org.bukkit.event.block.Action) MessageHandler(com.flowpowered.network.MessageHandler) Block(org.bukkit.block.Block) GlowSession(net.glowstone.net.GlowSession) PlayerSwingArmMessage(net.glowstone.net.message.play.player.PlayerSwingArmMessage) Material(org.bukkit.Material) AnimateEntityMessage(net.glowstone.net.message.play.entity.AnimateEntityMessage) AnimateEntityMessage(net.glowstone.net.message.play.entity.AnimateEntityMessage) Set(java.util.Set) Message(com.flowpowered.network.Message) PlayerSwingArmMessage(net.glowstone.net.message.play.player.PlayerSwingArmMessage) AnimateEntityMessage(net.glowstone.net.message.play.entity.AnimateEntityMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) Block(org.bukkit.block.Block) PlayerAnimationEvent(org.bukkit.event.player.PlayerAnimationEvent)

Aggregations

GlowSession (net.glowstone.net.GlowSession)2 Message (com.flowpowered.network.Message)1 MessageHandler (com.flowpowered.network.MessageHandler)1 Channel (io.netty.channel.Channel)1 Set (java.util.Set)1 EventFactory (net.glowstone.EventFactory)1 GlowPlayer (net.glowstone.entity.GlowPlayer)1 AnimateEntityMessage (net.glowstone.net.message.play.entity.AnimateEntityMessage)1 PlayerSwingArmMessage (net.glowstone.net.message.play.player.PlayerSwingArmMessage)1 Material (org.bukkit.Material)1 Block (org.bukkit.block.Block)1 Result (org.bukkit.event.Event.Result)1 Action (org.bukkit.event.block.Action)1 PlayerAnimationEvent (org.bukkit.event.player.PlayerAnimationEvent)1