Search in sources :

Example 1 with EntityVelocityMessage

use of net.glowstone.net.message.play.entity.EntityVelocityMessage in project Glowstone by GlowstoneMC.

the class GlowPlayer method join.

/**
 * Loads the player's state and sends the messages that are necessary on login.
 *
 * @param session the player's session
 * @param reader  the source of the player's saved state
 */
public void join(GlowSession session, PlayerReader reader) {
    String type = world.getWorldType().getName().toLowerCase();
    reader.readData(this);
    reader.close();
    int gameMode = getGameMode().getValue();
    session.send(new JoinGameMessage(getEntityId(), world.isHardcore(), gameMode, // TODO: determine previous gamemode
    -1, server.getWorlds().stream().map(World::getName).toArray(String[]::new), world.getName(), world.getSeedHash(), server.getMaxPlayers(), world.getViewDistance(), world.getGameRuleMap().getBoolean(GameRules.REDUCED_DEBUG_INFO), !world.getGameRuleMap().getBoolean(GameRules.DO_IMMEDIATE_RESPAWN), // TODO: Debug worlds
    false, world.getWorldType() == WorldType.FLAT));
    // send server brand and supported plugin channels
    Message pluginMessage = PluginMessage.fromString("minecraft:brand", server.getName());
    if (pluginMessage != null) {
        session.send(pluginMessage);
    }
    sendSupportedChannels();
    joinTime = System.currentTimeMillis();
    // Add player to list of online players
    getServer().setPlayerOnline(this, true);
    // save data back out
    saveData();
    // stream the initial set of blocks
    streamBlocks();
    sendWeather();
    sendRainDensity();
    sendSkyDarkness();
    getServer().sendPlayerAbilities(this);
    // send initial location
    session.send(new PositionRotationMessage(location));
    // send initial velocity
    session.send(new EntityVelocityMessage(getEntityId(), velocity));
    // send initial health
    sendHealth();
    // send gamemode defaults
    setGameModeDefaults();
    // send held item
    getSession().send(new HeldItemMessage(getInventory().getHeldItemSlot()));
    // send xp bar
    sendExperience();
    session.send(world.getWorldBorder().createMessage());
    sendTime();
    // set our compass target
    setCompassTarget(world.getSpawnLocation());
    scoreboard = server.getScoreboardManager().getMainScoreboard();
    scoreboard.subscribe(this);
    invMonitor = new InventoryMonitor(getOpenInventory());
    // send inventory contents
    updateInventory();
    session.send(recipeMonitor.createInitMessage());
    if (!server.getResourcePackUrl().isEmpty()) {
        setResourcePack(server.getResourcePackUrl(), server.getResourcePackHash());
    }
}
Also used : JoinGameMessage(net.glowstone.net.message.play.game.JoinGameMessage) TitleMessage(net.glowstone.net.message.play.game.TitleMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) OpenWindowMessage(net.glowstone.net.message.play.inv.OpenWindowMessage) BlockBreakAnimationMessage(net.glowstone.net.message.play.game.BlockBreakAnimationMessage) WindowPropertyMessage(net.glowstone.net.message.play.inv.WindowPropertyMessage) UpdateBlockEntityMessage(net.glowstone.net.message.play.game.UpdateBlockEntityMessage) RespawnMessage(net.glowstone.net.message.play.game.RespawnMessage) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) PositionRotationMessage(net.glowstone.net.message.play.game.PositionRotationMessage) HealthMessage(net.glowstone.net.message.play.game.HealthMessage) PluginMessage(net.glowstone.net.message.play.game.PluginMessage) SetWindowSlotMessage(net.glowstone.net.message.play.inv.SetWindowSlotMessage) PlayEffectMessage(net.glowstone.net.message.play.game.PlayEffectMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) UnloadChunkMessage(net.glowstone.net.message.play.game.UnloadChunkMessage) StateChangeMessage(net.glowstone.net.message.play.game.StateChangeMessage) SpawnPositionMessage(net.glowstone.net.message.play.game.SpawnPositionMessage) ExperienceMessage(net.glowstone.net.message.play.game.ExperienceMessage) NamedSoundEffectMessage(net.glowstone.net.message.play.game.NamedSoundEffectMessage) UserListHeaderFooterMessage(net.glowstone.net.message.play.game.UserListHeaderFooterMessage) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage) MapDataMessage(net.glowstone.net.message.play.game.MapDataMessage) StopSoundMessage(net.glowstone.net.message.play.game.StopSoundMessage) CloseWindowMessage(net.glowstone.net.message.play.inv.CloseWindowMessage) ChunkDataMessage(net.glowstone.net.message.play.game.ChunkDataMessage) TimeMessage(net.glowstone.net.message.play.game.TimeMessage) Message(com.flowpowered.network.Message) SetWindowContentsMessage(net.glowstone.net.message.play.inv.SetWindowContentsMessage) PlayParticleMessage(net.glowstone.net.message.play.game.PlayParticleMessage) ResourcePackSendMessage(net.glowstone.net.message.play.player.ResourcePackSendMessage) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) JoinGameMessage(net.glowstone.net.message.play.game.JoinGameMessage) SignEditorMessage(net.glowstone.net.message.play.game.SignEditorMessage) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) EntityAnimationMessage(net.glowstone.net.message.play.entity.EntityAnimationMessage) TextMessage(net.glowstone.util.TextMessage) UpdateSignMessage(net.glowstone.net.message.play.game.UpdateSignMessage) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) PositionRotationMessage(net.glowstone.net.message.play.game.PositionRotationMessage) InventoryMonitor(net.glowstone.inventory.InventoryMonitor) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage)

Example 2 with EntityVelocityMessage

use of net.glowstone.net.message.play.entity.EntityVelocityMessage in project Glowstone by GlowstoneMC.

the class GlowProjectile method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    double x = location.getX();
    double y = location.getY();
    double z = location.getZ();
    int yaw = Position.getIntYaw(location);
    int pitch = Position.getIntPitch(location);
    return Arrays.asList(new SpawnObjectMessage(entityId, getUniqueId(), getObjectId(), x, y, z, pitch, yaw), new EntityMetadataMessage(entityId, metadata.getEntryList()), new EntityVelocityMessage(entityId, getVelocity()));
}
Also used : SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 3 with EntityVelocityMessage

use of net.glowstone.net.message.play.entity.EntityVelocityMessage in project Glowstone by GlowstoneMC.

the class GlowEntity method createUpdateMessage.

/**
 * Creates a {@link Message} which can be sent to a client to update this entity.
 *
 * @param session Session to update this entity for
 * @return A message which can update this entity.
 */
public List<Message> createUpdateMessage(GlowSession session) {
    double x = location.getX();
    double y = location.getY();
    double z = location.getZ();
    double dx = x * 32 - previousLocation.getX() * 32;
    double dy = y * 32 - previousLocation.getY() * 32;
    double dz = z * 32 - previousLocation.getZ() * 32;
    dx *= 128;
    dy *= 128;
    dz *= 128;
    boolean teleport = dx > Short.MAX_VALUE || dy > Short.MAX_VALUE || dz > Short.MAX_VALUE || dx < Short.MIN_VALUE || dy < Short.MIN_VALUE || dz < Short.MIN_VALUE;
    List<Message> result = new LinkedList<>();
    boolean moved = hasMoved();
    boolean rotated = hasRotated();
    if (teleported || moved && teleport) {
        result.add(new EntityTeleportMessage(entityId, location));
    } else if (rotated) {
        int yaw = Position.getIntYaw(location);
        int pitch = Position.getIntPitch(location);
        if (moved) {
            result.add(new RelativeEntityPositionRotationMessage(entityId, (short) dx, (short) dy, (short) dz, yaw, pitch));
        } else {
            result.add(new EntityRotationMessage(entityId, yaw, pitch));
        }
    } else if (moved) {
        result.add(new RelativeEntityPositionMessage(entityId, (short) dx, (short) dy, (short) dz));
    }
    // send changed metadata
    List<Entry> changes = metadata.getChanges();
    if (!changes.isEmpty()) {
        result.add(new EntityMetadataMessage(entityId, changes));
    }
    // send velocity if needed
    if (velocityChanged) {
        result.add(new EntityVelocityMessage(entityId, velocity));
    }
    if (passengerChanged) {
        // A player can be a passenger of any arbitrary entity, e.g. a boat
        // In case the current session belongs to this player passenger
        // We need to send the self_id
        List<Integer> passengerIds = new ArrayList<>();
        getPassengers().forEach(e -> passengerIds.add(e.getEntityId()));
        result.add(new SetPassengerMessage(getEntityId(), passengerIds.stream().mapToInt(Integer::intValue).toArray()));
        passengerChanged = false;
    }
    if (leashHolderChanged) {
        int attached = isLeashed() && session.getPlayer().getEntityId() == leashHolder.getEntityId() ? 0 : this.getEntityId();
        int holder = !isLeashed() ? -1 : leashHolder.getEntityId();
        // createAfterSpawnMessage()
        if (!isLeashed() || session.getPlayer().canSeeEntity(leashHolder)) {
            result.add(new AttachEntityMessage(attached, holder));
        }
    }
    return result;
}
Also used : EntityRotationMessage(net.glowstone.net.message.play.entity.EntityRotationMessage) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) InteractEntityMessage(net.glowstone.net.message.play.player.InteractEntityMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) EntityTeleportMessage(net.glowstone.net.message.play.entity.EntityTeleportMessage) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) Message(com.flowpowered.network.Message) TextMessage(net.glowstone.util.TextMessage) RelativeEntityPositionMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionMessage) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) AttachEntityMessage(net.glowstone.net.message.play.entity.AttachEntityMessage) RelativeEntityPositionRotationMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionRotationMessage) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) ArrayList(java.util.ArrayList) EntityRotationMessage(net.glowstone.net.message.play.entity.EntityRotationMessage) LinkedList(java.util.LinkedList) RelativeEntityPositionRotationMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionRotationMessage) RelativeEntityPositionMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionMessage) Entry(net.glowstone.entity.meta.MetadataMap.Entry) AttachEntityMessage(net.glowstone.net.message.play.entity.AttachEntityMessage) EntityTeleportMessage(net.glowstone.net.message.play.entity.EntityTeleportMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 4 with EntityVelocityMessage

use of net.glowstone.net.message.play.entity.EntityVelocityMessage in project Glowstone by GlowstoneMC.

the class GlowPlayer method setVelocity.

@Override
public void setVelocity(Vector velocity) {
    PlayerVelocityEvent event = EventFactory.getInstance().callEvent(new PlayerVelocityEvent(this, velocity));
    if (!event.isCancelled()) {
        velocity = event.getVelocity();
        super.setVelocity(velocity);
        if (hasJoined()) {
            session.send(new EntityVelocityMessage(getEntityId(), velocity));
        }
    }
}
Also used : PlayerVelocityEvent(org.bukkit.event.player.PlayerVelocityEvent) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage)

Aggregations

EntityVelocityMessage (net.glowstone.net.message.play.entity.EntityVelocityMessage)4 EntityMetadataMessage (net.glowstone.net.message.play.entity.EntityMetadataMessage)3 Message (com.flowpowered.network.Message)2 SetPassengerMessage (net.glowstone.net.message.play.entity.SetPassengerMessage)2 TextMessage (net.glowstone.util.TextMessage)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Entry (net.glowstone.entity.meta.MetadataMap.Entry)1 InventoryMonitor (net.glowstone.inventory.InventoryMonitor)1 AttachEntityMessage (net.glowstone.net.message.play.entity.AttachEntityMessage)1 DestroyEntitiesMessage (net.glowstone.net.message.play.entity.DestroyEntitiesMessage)1 EntityAnimationMessage (net.glowstone.net.message.play.entity.EntityAnimationMessage)1 EntityRotationMessage (net.glowstone.net.message.play.entity.EntityRotationMessage)1 EntityStatusMessage (net.glowstone.net.message.play.entity.EntityStatusMessage)1 EntityTeleportMessage (net.glowstone.net.message.play.entity.EntityTeleportMessage)1 RelativeEntityPositionMessage (net.glowstone.net.message.play.entity.RelativeEntityPositionMessage)1 RelativeEntityPositionRotationMessage (net.glowstone.net.message.play.entity.RelativeEntityPositionRotationMessage)1 SpawnObjectMessage (net.glowstone.net.message.play.entity.SpawnObjectMessage)1 BlockBreakAnimationMessage (net.glowstone.net.message.play.game.BlockBreakAnimationMessage)1 BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)1