Search in sources :

Example 6 with Message

use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.

the class GlowBat method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    List<Message> result = new LinkedList<>();
    // spawn mob
    double x = location.getX();
    double y = location.getY();
    double z = location.getZ();
    int yaw = Position.getIntYaw(location);
    int pitch = Position.getIntPitch(location);
    //TODO 1.9 - Real UUID
    result.add(new SpawnMobMessage(id, UUID.randomUUID(), getType().getTypeId(), x, y, z, yaw, pitch, pitch, 0, 0, 0, metadata.getEntryList()));
    // head facing
    result.add(new EntityHeadRotationMessage(id, yaw));
    return result;
}
Also used : SpawnMobMessage(net.glowstone.net.message.play.entity.SpawnMobMessage) EntityHeadRotationMessage(net.glowstone.net.message.play.entity.EntityHeadRotationMessage) Message(com.flowpowered.network.Message) SpawnMobMessage(net.glowstone.net.message.play.entity.SpawnMobMessage) EntityHeadRotationMessage(net.glowstone.net.message.play.entity.EntityHeadRotationMessage) LinkedList(java.util.LinkedList)

Example 7 with Message

use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.

the class GlowHorse method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    List<Message> messages = super.createSpawnMessage();
    MetadataMap map = new MetadataMap(GlowHorse.class);
    map.set(MetadataIndex.HORSE_STYLE, getHorseStyleData());
    map.set(MetadataIndex.HORSE_ARMOR, getHorseArmorData());
    messages.add(new EntityMetadataMessage(id, map.getEntryList()));
    return messages;
}
Also used : MetadataMap(net.glowstone.entity.meta.MetadataMap) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) Message(com.flowpowered.network.Message) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 8 with Message

use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.

the class GlowAbstractHorse method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    List<Message> messages = super.createSpawnMessage();
    MetadataMap map = new MetadataMap(GlowHorse.class);
    map.set(MetadataIndex.ABSTRACT_HORSE_FLAGS, getHorseFlags());
    messages.add(new EntityMetadataMessage(id, map.getEntryList()));
    return messages;
}
Also used : MetadataMap(net.glowstone.entity.meta.MetadataMap) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) Message(com.flowpowered.network.Message) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 9 with Message

use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.

the class ItemItemFrame method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
    GlowItemFrame entity = new GlowItemFrame(player, target.getLocation().getBlock().getRelative(face).getLocation(), face);
    List<Message> spawnMessage = entity.createSpawnMessage();
    entity.getWorld().getRawPlayers().stream().filter(p -> p.canSeeEntity(entity)).forEach(p -> p.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
}
Also used : Vector(org.bukkit.util.Vector) GlowBlock(net.glowstone.block.GlowBlock) List(java.util.List) Message(com.flowpowered.network.Message) GlowPlayer(net.glowstone.entity.GlowPlayer) BlockFace(org.bukkit.block.BlockFace) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame) ItemStack(org.bukkit.inventory.ItemStack) Message(com.flowpowered.network.Message) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame)

Example 10 with Message

use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.

the class GlowSession method pulse.

/**
     * Pulse this session, performing any updates needed.
     */
void pulse() {
    // drop the previous placement if needed
    if (previousPlacementTicks > 0 && --previousPlacementTicks == 0) {
        previousPlacement = null;
    }
    // process messages
    Message message;
    while ((message = messageQueue.poll()) != null) {
        if (disconnected) {
            // disconnected, we are just seeing extra messages now
            break;
        }
        super.messageReceived(message);
    }
    // check if the client is disconnected
    if (disconnected) {
        connectionManager.sessionInactivated(this);
        if (player == null) {
            return;
        }
        player.remove();
        Message userListMessage = UserListItemMessage.removeOne(player.getUniqueId());
        for (GlowPlayer player : server.getRawOnlinePlayers()) {
            if (player.canSee(this.player)) {
                player.getSession().send(userListMessage);
            } else {
                player.stopHidingDisconnectedPlayer(this.player);
            }
        }
        GlowServer.logger.info(player.getName() + " [" + address + "] lost connection");
        if (player.isSleeping()) {
            player.leaveBed(false);
        }
        server.getBossBarManager().clearBossBars(player);
        String text = EventFactory.onPlayerQuit(player).getQuitMessage();
        if (online && text != null && !text.isEmpty()) {
            server.broadcastMessage(text);
        }
        // statistics
        player.incrementStatistic(Statistic.LEAVE_GAME);
        for (Player p : server.getOnlinePlayers()) {
            if (p.getUniqueId().equals(player.getUniqueId())) {
                continue;
            }
            GlowPlayer other = (GlowPlayer) p;
            if (!other.canSee(player)) {
                continue;
            }
            other.getSession().send(new DestroyEntitiesMessage(Collections.singletonList(player.getEntityId())));
        }
        // in case we are disposed twice
        player = null;
    }
}
Also used : DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) KickMessage(net.glowstone.net.message.KickMessage) Message(com.flowpowered.network.Message) PingMessage(net.glowstone.net.message.play.game.PingMessage) LoginSuccessMessage(net.glowstone.net.message.login.LoginSuccessMessage) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) SetCompressionMessage(net.glowstone.net.message.SetCompressionMessage) BlockPlacementMessage(net.glowstone.net.message.play.player.BlockPlacementMessage) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage) AsyncableMessage(com.flowpowered.network.AsyncableMessage) GlowPlayer(net.glowstone.entity.GlowPlayer)

Aggregations

Message (com.flowpowered.network.Message)20 LinkedList (java.util.LinkedList)4 GlowPlayer (net.glowstone.entity.GlowPlayer)4 MetadataMap (net.glowstone.entity.meta.MetadataMap)4 EntityHeadRotationMessage (net.glowstone.net.message.play.entity.EntityHeadRotationMessage)4 EntityMetadataMessage (net.glowstone.net.message.play.entity.EntityMetadataMessage)3 AsyncableMessage (com.flowpowered.network.AsyncableMessage)2 IOException (java.io.IOException)2 GlowBlock (net.glowstone.block.GlowBlock)2 Key (net.glowstone.chunk.GlowChunk.Key)2 SpawnObjectMessage (net.glowstone.net.message.play.entity.SpawnObjectMessage)2 HeldItemMessage (net.glowstone.net.message.play.inv.HeldItemMessage)2 ItemStack (org.bukkit.inventory.ItemStack)2 Vector (org.bukkit.util.Vector)2 Codec (com.flowpowered.network.Codec)1 MessageHandler (com.flowpowered.network.MessageHandler)1 ByteBuf (io.netty.buffer.ByteBuf)1 File (java.io.File)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1