Search in sources :

Example 21 with Message

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

the class GlowSession method setPlayer.

/**
     * Sets the player associated with this session.
     *
     * @param profile The player's profile with name and UUID information.
     * @throws IllegalStateException if there is already a player associated
     *                               with this session.
     */
public void setPlayer(PlayerProfile profile) {
    if (player != null) {
        throw new IllegalStateException("Cannot set player twice");
    }
    // isActive check here in case player disconnected during authentication
    if (!isActive()) {
        // no need to call onDisconnect() since it only does anything if there's a player set
        return;
    }
    // initialize the player
    PlayerReader reader = server.getPlayerDataService().beginReadingData(profile.getUniqueId());
    player = new GlowPlayer(this, profile, reader);
    finalizeLogin(profile);
    // but before the GlowPlayer initialization was completed
    if (!isActive()) {
        reader.close();
        onDisconnect();
        return;
    }
    // Kick other players with the same UUID
    for (GlowPlayer other : getServer().getRawOnlinePlayers()) {
        if (other != player && other.getUniqueId().equals(player.getUniqueId())) {
            other.getSession().disconnect("You logged in from another location.", true);
            break;
        }
    }
    // login event
    PlayerLoginEvent event = EventFactory.onPlayerLogin(player, hostname);
    if (event.getResult() != Result.ALLOWED) {
        disconnect(event.getKickMessage(), true);
        return;
    }
    //joins the player
    player.join(this, reader);
    player.getWorld().getRawPlayers().add(player);
    online = true;
    GlowServer.logger.info(player.getName() + " [" + address + "] connected, UUID: " + player.getUniqueId());
    // message and user list
    String message = EventFactory.onPlayerJoin(player).getJoinMessage();
    if (message != null && !message.isEmpty()) {
        server.broadcastMessage(message);
    }
    Message addMessage = new UserListItemMessage(Action.ADD_PLAYER, player.getUserListEntry());
    List<Entry> entries = new ArrayList<>();
    for (GlowPlayer other : server.getRawOnlinePlayers()) {
        if (other != player && other.canSee(player)) {
            other.getSession().send(addMessage);
        }
        if (player.canSee(other)) {
            entries.add(other.getUserListEntry());
        }
    }
    send(new UserListItemMessage(Action.ADD_PLAYER, entries));
}
Also used : Entry(net.glowstone.net.message.play.game.UserListItemMessage.Entry) 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) PlayerReader(net.glowstone.io.PlayerDataService.PlayerReader) GlowPlayer(net.glowstone.entity.GlowPlayer) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage)

Example 22 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, EquipmentSlot hand) {
    GlowItemFrame entity = new GlowItemFrame(player, target.getRelative(face).getLocation(), face);
    if (EventFactory.getInstance().callEvent(new HangingPlaceEvent(entity, player, target, face)).isCancelled()) {
        return;
    }
    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) EventFactory(net.glowstone.EventFactory) Message(com.flowpowered.network.Message) GlowPlayer(net.glowstone.entity.GlowPlayer) BlockFace(org.bukkit.block.BlockFace) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame) HangingPlaceEvent(org.bukkit.event.hanging.HangingPlaceEvent) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) ItemStack(org.bukkit.inventory.ItemStack) HangingPlaceEvent(org.bukkit.event.hanging.HangingPlaceEvent) Message(com.flowpowered.network.Message) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame)

Example 23 with Message

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

the class GlowEntity method playEffectKnownAndSelf.

public void playEffectKnownAndSelf(EntityEffect type) {
    if (type.getApplicable().isInstance(this)) {
        EntityStatusMessage message = new EntityStatusMessage(entityId, type);
        if (this instanceof GlowPlayer) {
            ((GlowPlayer) this).getSession().send(message);
        }
        world.getRawPlayers().stream().filter(player -> player.canSeeEntity(this)).forEach(player -> player.getSession().send(message));
    }
}
Also used : Plugin(org.bukkit.plugin.Plugin) EntityEffect(org.bukkit.EntityEffect) EntityUnleashEvent(org.bukkit.event.entity.EntityUnleashEvent) StatusFlags(net.glowstone.entity.meta.MetadataIndex.StatusFlags) UuidUtils(net.glowstone.util.UuidUtils) Projectile(org.bukkit.entity.Projectile) BlockFace(org.bukkit.block.BlockFace) Player(org.bukkit.entity.Player) EntityMountEvent(org.spigotmc.event.entity.EntityMountEvent) EntityPortalExitEvent(org.bukkit.event.entity.EntityPortalExitEvent) Block(org.bukkit.block.Block) Location(org.bukkit.Location) EntityRotationMessage(net.glowstone.net.message.play.entity.EntityRotationMessage) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) World(org.bukkit.World) InteractEntityMessage(net.glowstone.net.message.play.player.InteractEntityMessage) Chunk(org.bukkit.Chunk) BoundingBox(net.glowstone.entity.physics.BoundingBox) GlowWorld(net.glowstone.GlowWorld) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame) Material(org.bukkit.Material) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Position(net.glowstone.util.Position) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PersistentDataContainer(org.bukkit.persistence.PersistentDataContainer) PistonMoveReaction(org.bukkit.block.PistonMoveReaction) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) Entity(org.bukkit.entity.Entity) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) GlowChunk(net.glowstone.chunk.GlowChunk) Set(java.util.Set) UUID(java.util.UUID) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) ItemStack(org.bukkit.inventory.ItemStack) EntityTeleportMessage(net.glowstone.net.message.play.entity.EntityTeleportMessage) Objects(java.util.Objects) EntityBoundingBox(net.glowstone.entity.physics.EntityBoundingBox) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) MetadataIndex(net.glowstone.entity.meta.MetadataIndex) MetadataValue(org.bukkit.metadata.MetadataValue) Entry(net.glowstone.entity.meta.MetadataMap.Entry) VehicleExitEvent(org.bukkit.event.vehicle.VehicleExitEvent) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) PlayerInitialSpawnEvent(com.destroystokyo.paper.event.player.PlayerInitialSpawnEvent) Setter(lombok.Setter) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) VehicleEnterEvent(org.bukkit.event.vehicle.VehicleEnterEvent) Getter(lombok.Getter) MetadataMap(net.glowstone.entity.meta.MetadataMap) Message(com.flowpowered.network.Message) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) EntityDismountEvent(org.spigotmc.event.entity.EntityDismountEvent) Lists(com.google.common.collect.Lists) Environment(org.bukkit.World.Environment) PermissionAttachment(org.bukkit.permissions.PermissionAttachment) ImmutableList(com.google.common.collect.ImmutableList) GlowLeashHitch(net.glowstone.entity.objects.GlowLeashHitch) Component(net.kyori.adventure.text.Component) Vehicle(org.bukkit.entity.Vehicle) GlowSession(net.glowstone.net.GlowSession) GlowServer(net.glowstone.GlowServer) LinkedList(java.util.LinkedList) TextMessage(net.glowstone.util.TextMessage) RelativeEntityPositionMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionMessage) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) MetadataStore(org.bukkit.metadata.MetadataStore) PlayerSpawnLocationEvent(org.spigotmc.event.player.PlayerSpawnLocationEvent) GlowPainting(net.glowstone.entity.objects.GlowPainting) EntityPortalEvent(org.bukkit.event.entity.EntityPortalEvent) TeleportCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause) UnleashReason(org.bukkit.event.entity.EntityUnleashEvent.UnleashReason) EventFactory(net.glowstone.EventFactory) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PermissionAttachmentInfo(org.bukkit.permissions.PermissionAttachmentInfo) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) Permission(org.bukkit.permissions.Permission) Vector(org.bukkit.util.Vector) AttachEntityMessage(net.glowstone.net.message.play.entity.AttachEntityMessage) Pose(org.bukkit.entity.Pose) Preconditions(com.google.common.base.Preconditions) RelativeEntityPositionRotationMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionRotationMessage) EntityPortalEnterEvent(org.bukkit.event.entity.EntityPortalEnterEvent) MetadataStoreBase(org.bukkit.metadata.MetadataStoreBase) Collections(java.util.Collections) ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage)

Example 24 with Message

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

the class GlowAgeable method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    List<Message> messages = super.createSpawnMessage();
    MetadataMap map = new MetadataMap(GlowAgeable.class);
    map.set(MetadataIndex.AGE_ISBABY, !isAdult());
    messages.add(new EntityMetadataMessage(entityId, 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) InteractEntityMessage(net.glowstone.net.message.play.player.InteractEntityMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 25 with Message

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

the class GlowCreature method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    List<Message> result = new LinkedList<>();
    // spawn mob
    result.add(new SpawnMobMessage(entityId, getUniqueId(), EntityNetworkUtil.getMobId(type), location, metadata.getEntryList()));
    // head facing
    result.add(new EntityHeadRotationMessage(entityId, Position.getIntYaw(location)));
    // result.add(createEquipmentMessage());
    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)

Aggregations

Message (com.flowpowered.network.Message)34 LinkedList (java.util.LinkedList)13 EntityMetadataMessage (net.glowstone.net.message.play.entity.EntityMetadataMessage)11 List (java.util.List)10 DestroyEntitiesMessage (net.glowstone.net.message.play.entity.DestroyEntitiesMessage)10 ItemStack (org.bukkit.inventory.ItemStack)10 Vector (org.bukkit.util.Vector)10 ArrayList (java.util.ArrayList)9 Collections (java.util.Collections)8 Getter (lombok.Getter)8 Setter (lombok.Setter)8 EventFactory (net.glowstone.EventFactory)8 EntityVelocityMessage (net.glowstone.net.message.play.entity.EntityVelocityMessage)8 SetPassengerMessage (net.glowstone.net.message.play.entity.SetPassengerMessage)8 TextMessage (net.glowstone.util.TextMessage)8 NotNull (org.jetbrains.annotations.NotNull)8 GlowBlock (net.glowstone.block.GlowBlock)7 GlowPlayer (net.glowstone.entity.GlowPlayer)7 EntityAnimationMessage (net.glowstone.net.message.play.entity.EntityAnimationMessage)7 UserListItemMessage (net.glowstone.net.message.play.game.UserListItemMessage)7