Search in sources :

Example 1 with DestroyEntitiesMessage

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

the class GlowSession method pulse.

/**
 * Pulse this session, performing any updates needed.
 */
void pulse() {
    // 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);
        }
        Collection<BossBar> bars;
        do {
            bars = player.getBossBars();
            for (BossBar bar : bars) {
                bar.removePlayer(player);
                player.removeBossBar(bar);
            }
        } while (!bars.isEmpty());
        String text = EventFactory.getInstance().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) PingMessage(net.glowstone.net.message.play.game.PingMessage) LoginSuccessMessage(net.glowstone.net.message.login.LoginSuccessMessage) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) Message(com.flowpowered.network.Message) SetCompressionMessage(net.glowstone.net.message.SetCompressionMessage) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage) AsyncableMessage(com.flowpowered.network.AsyncableMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) BossBar(org.bukkit.boss.BossBar)

Example 2 with DestroyEntitiesMessage

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

the class GlowFishingHook method setShooter.

@Override
public void setShooter(ProjectileSource shooter) {
    ProjectileSource oldShooter = getShooter();
    if (oldShooter == shooter) {
        return;
    }
    // Shooter is immutable client-side (a situation peculiar to fishing hooks), so if it
    // changes then all clients who can see this fishing hook must be told that this hook has
    // despawned and a new one has spawned.
    super.setShooter(shooter);
    World world = location.getWorld();
    if (world instanceof GlowWorld) {
        List<Message> respawnMessages = new LinkedList<>();
        DestroyEntitiesMessage destroyOldCopy = new DestroyEntitiesMessage(Collections.singletonList(getObjectId()));
        respawnMessages.add(destroyOldCopy);
        respawnMessages.addAll(createSpawnMessage(getShooterId()));
        ((GlowWorld) world).getRawPlayers().stream().filter(player -> !Objects.equal(player, shooter)).filter(player -> player.canSeeEntity(this)).forEach(player -> player.getSession().sendAll(respawnMessages.toArray(EMPTY_MESSAGE_ARRAY)));
        if (shooter instanceof GlowPlayer) {
            GlowSession session = ((GlowPlayer) shooter).getSession();
            session.send(destroyOldCopy);
            session.sendAll(createSpawnMessage(getEntityId()).toArray(EMPTY_MESSAGE_ARRAY));
        }
    }
}
Also used : DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) Setter(lombok.Setter) Getter(lombok.Getter) BoundingBox(org.bukkit.util.BoundingBox) Enchantment(org.bukkit.enchantments.Enchantment) Message(com.flowpowered.network.Message) GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) PlayerFishEvent(org.bukkit.event.player.PlayerFishEvent) InventoryUtil(net.glowstone.util.InventoryUtil) EntityNetworkUtil(net.glowstone.entity.EntityNetworkUtil) Block(org.bukkit.block.Block) GlowProjectile(net.glowstone.entity.projectile.GlowProjectile) Location(org.bukkit.Location) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) World(org.bukkit.World) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GlowSession(net.glowstone.net.GlowSession) Objects(com.google.common.base.Objects) GlowWorld(net.glowstone.GlowWorld) LinkedList(java.util.LinkedList) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Material(org.bukkit.Material) Position(net.glowstone.util.Position) Entity(org.bukkit.entity.Entity) GlowBiomeClimate(net.glowstone.constants.GlowBiomeClimate) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) EventFactory(net.glowstone.EventFactory) RewardItem(net.glowstone.entity.FishingRewardManager.RewardItem) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) List(java.util.List) MetadataIndex(net.glowstone.entity.meta.MetadataIndex) FishHook(org.bukkit.entity.FishHook) RewardCategory(net.glowstone.entity.FishingRewardManager.RewardCategory) SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) CAUGHT_FISH(org.bukkit.event.player.PlayerFishEvent.State.CAUGHT_FISH) GlowSession(net.glowstone.net.GlowSession) Message(com.flowpowered.network.Message) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) GlowWorld(net.glowstone.GlowWorld) ProjectileSource(org.bukkit.projectiles.ProjectileSource) World(org.bukkit.World) GlowWorld(net.glowstone.GlowWorld) LinkedList(java.util.LinkedList)

Example 3 with DestroyEntitiesMessage

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

the class GlowPlayer method pulse.

@Override
public void pulse() {
    super.pulse();
    incrementStatistic(Statistic.TIME_SINCE_DEATH);
    if (usageItem != null) {
        if (usageItem.equals(getItemInHand())) {
            // todo: implement offhand
            if (--usageTime == 0) {
                ItemType item = ItemTable.instance().getItem(usageItem.getType());
                if (item instanceof ItemFood) {
                    ((ItemFood) item).eat(this, usageItem);
                }
            }
        } else {
            usageItem = null;
            usageTime = 0;
        }
    }
    if (digging != null) {
        pulseDigging();
    }
    if (exhaustion > 4.0f) {
        exhaustion -= 4.0f;
        if (saturation > 0f) {
            saturation = Math.max(saturation - 1f, 0f);
            sendHealth();
        } else if (world.getDifficulty() != Difficulty.PEACEFUL) {
            FoodLevelChangeEvent event = EventFactory.getInstance().callEvent(new FoodLevelChangeEvent(this, Math.max(foodLevel - 1, 0)));
            if (!event.isCancelled()) {
                foodLevel = event.getFoodLevel();
            }
            sendHealth();
        }
    }
    if (getHealth() < getMaxHealth() && !isDead()) {
        if (foodLevel >= 18 && ticksLived % 80 == 0 || world.getDifficulty() == Difficulty.PEACEFUL) {
            EntityUtils.heal(this, 1, EntityRegainHealthEvent.RegainReason.SATIATED);
            exhaustion = Math.min(exhaustion + 3.0f, 40.0f);
            saturation -= 3;
        }
    }
    // Process food level and starvation based on difficulty.
    switch(world.getDifficulty()) {
        case PEACEFUL:
            {
                if (foodLevel < 20 && ticksLived % 20 == 0) {
                    foodLevel++;
                }
                break;
            }
        case EASY:
            {
                if (foodLevel == 0 && getHealth() > 10 && ticksLived % 80 == 0) {
                    damage(1, DamageCause.STARVATION);
                }
                break;
            }
        case NORMAL:
            {
                if (foodLevel == 0 && getHealth() > 1 && ticksLived % 80 == 0) {
                    damage(1, DamageCause.STARVATION);
                }
                break;
            }
        case HARD:
            {
                if (foodLevel == 0 && ticksLived % 80 == 0) {
                    damage(1, DamageCause.STARVATION);
                }
                break;
            }
        default:
            {
            // Do nothing when there are other game difficulties.
            }
    }
    // process ender pearl cooldown, decrease by 1 every game tick.
    if (enderPearlCooldown > 0) {
        enderPearlCooldown--;
    }
    // stream world
    streamBlocks();
    processBlockChanges();
    // add to playtime (despite inaccurate name, this counts ticks rather than minutes)
    incrementStatistic(Statistic.PLAY_ONE_MINUTE);
    if (isSneaking()) {
        incrementStatistic(Statistic.SNEAK_TIME);
    }
    // update inventory
    for (InventoryMonitor.Entry entry : invMonitor.getChanges()) {
        sendItemChange(entry.slot, entry.item);
    }
    // send changed metadata
    List<MetadataMap.Entry> changes = metadata.getChanges();
    if (!changes.isEmpty()) {
        session.send(new EntityMetadataMessage(getEntityId(), changes));
    }
    // Entity IDs are only unique per world, so we can't spawn or teleport between worlds while
    // updating them.
    worldLock.writeLock().lock();
    try {
        // update or remove entities
        List<GlowEntity> destroyEntities = new LinkedList<>();
        for (Iterator<GlowEntity> it = knownEntities.iterator(); it.hasNext(); ) {
            GlowEntity entity = it.next();
            if (!isWithinDistance(entity) || entity.isRemoved()) {
                destroyEntities.add(entity);
            } else {
                entity.createUpdateMessage(session).forEach(session::send);
            }
        }
        if (!destroyEntities.isEmpty()) {
            List<Integer> destroyIds = new ArrayList<>(destroyEntities.size());
            for (GlowEntity entity : destroyEntities) {
                knownEntities.remove(entity);
                destroyIds.add(entity.getEntityId());
            }
            session.send(new DestroyEntitiesMessage(destroyIds));
        }
        // add entities
        knownChunks.forEach(key -> world.getChunkAt(key.getX(), key.getZ()).getRawEntities().stream().filter(entity -> this != entity && isWithinDistance(entity) && !entity.isDead() && !knownEntities.contains(entity) && !hiddenEntities.contains(entity.getUniqueId())).forEach((entity) -> Bukkit.getScheduler().runTaskAsynchronously(null, () -> {
            worldLock.readLock().lock();
            try {
                knownEntities.add(entity);
            } finally {
                worldLock.readLock().unlock();
            }
            entity.createSpawnMessage().forEach(session::send);
            entity.createAfterSpawnMessage(session).forEach(session::send);
        })));
    } finally {
        worldLock.writeLock().unlock();
    }
    if (passengerChanged) {
        session.send(new SetPassengerMessage(getEntityId(), getPassengers().stream().mapToInt(Entity::getEntityId).toArray()));
    }
    getAttributeManager().sendMessages(session);
    GlowFishingHook hook = currentFishingHook.get();
    if (hook != null) {
        // bobber, or if the player stops holding a fishing rod.
        if (getInventory().getItemInMainHand().getType() != Material.FISHING_ROD && getInventory().getItemInOffHand().getType() != Material.FISHING_ROD) {
            setCurrentFishingHook(null);
        }
        if (hook.location.distanceSquared(location) > HOOK_MAX_DISTANCE * HOOK_MAX_DISTANCE) {
            setCurrentFishingHook(null);
        }
    }
}
Also used : DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) GlowBlock(net.glowstone.block.GlowBlock) PlayerPortalEvent(org.bukkit.event.player.PlayerPortalEvent) GlowTeam(net.glowstone.scoreboard.GlowTeam) PlayerStatisticIncrementEvent(org.bukkit.event.player.PlayerStatisticIncrementEvent) Entry(net.glowstone.net.message.play.game.UserListItemMessage.Entry) TitleMessage(net.glowstone.net.message.play.game.TitleMessage) MaterialData(org.bukkit.material.MaterialData) Location(org.bukkit.Location) Map(java.util.Map) PlayerToggleSneakEvent(org.bukkit.event.player.PlayerToggleSneakEvent) EntityAnimation(org.bukkit.EntityAnimation) GlowWorld(net.glowstone.GlowWorld) GlowInventory(net.glowstone.inventory.GlowInventory) Position(net.glowstone.util.Position) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) Entity(org.bukkit.entity.Entity) GlowEffect(net.glowstone.constants.GlowEffect) MainHand(org.bukkit.inventory.MainHand) OpenWindowMessage(net.glowstone.net.message.play.inv.OpenWindowMessage) BlockVector(org.bukkit.util.BlockVector) Advancement(org.bukkit.advancement.Advancement) InventoryView(org.bukkit.inventory.InventoryView) InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) ChunkLock(net.glowstone.chunk.ChunkManager.ChunkLock) PlayerUnregisterChannelEvent(org.bukkit.event.player.PlayerUnregisterChannelEvent) Convert(net.glowstone.util.Convert) BoundingBox(org.bukkit.util.BoundingBox) 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) EntityUtils(net.glowstone.util.EntityUtils) GameRules(net.glowstone.constants.GameRules) PlayerLocaleChangeEvent(org.bukkit.event.player.PlayerLocaleChangeEvent) SoundCategory(org.bukkit.SoundCategory) EventFactory(net.glowstone.EventFactory) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) BossBar(org.bukkit.boss.BossBar) PlayerLevelChangeEvent(org.bukkit.event.player.PlayerLevelChangeEvent) PlayerResourcePackStatusEvent(org.bukkit.event.player.PlayerResourcePackStatusEvent) PositionRotationMessage(net.glowstone.net.message.play.game.PositionRotationMessage) HealthMessage(net.glowstone.net.message.play.game.HealthMessage) PluginMessage(net.glowstone.net.message.play.game.PluginMessage) Preconditions(com.google.common.base.Preconditions) Plugin(org.bukkit.plugin.Plugin) StatusFlags(net.glowstone.entity.meta.MetadataIndex.StatusFlags) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) SetWindowSlotMessage(net.glowstone.net.message.play.inv.SetWindowSlotMessage) Player(org.bukkit.entity.Player) PlayEffectMessage(net.glowstone.net.message.play.game.PlayEffectMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) Unpooled(io.netty.buffer.Unpooled) GlowWorldBorder(net.glowstone.GlowWorldBorder) Scoreboard(org.bukkit.scoreboard.Scoreboard) Merchant(org.bukkit.inventory.Merchant) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Locale(java.util.Locale) Instrument(org.bukkit.Instrument) Recipe(org.bukkit.inventory.Recipe) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) GlowChunk(net.glowstone.chunk.GlowChunk) Collection(java.util.Collection) Property(org.bukkit.inventory.InventoryView.Property) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BanList(org.bukkit.BanList) Reason(net.glowstone.net.message.play.game.StateChangeMessage.Reason) UUID(java.util.UUID) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) UnloadChunkMessage(net.glowstone.net.message.play.game.UnloadChunkMessage) EntityType(org.bukkit.entity.EntityType) Collectors(java.util.stream.Collectors) StateChangeMessage(net.glowstone.net.message.play.game.StateChangeMessage) Villager(org.bukkit.entity.Villager) Objects(java.util.Objects) ComponentSerializer(net.md_5.bungee.chat.ComponentSerializer) PlayerExpChangeEvent(org.bukkit.event.player.PlayerExpChangeEvent) Queue(java.util.Queue) BlockBed(net.glowstone.block.blocktype.BlockBed) Title(com.destroystokyo.paper.Title) GlowServer.logger(net.glowstone.GlowServer.logger) InventoryUtil(net.glowstone.util.InventoryUtil) Level(java.util.logging.Level) HashSet(java.util.HashSet) GameMode(org.bukkit.GameMode) Environment(org.bukkit.World.Environment) ImmutableList(com.google.common.collect.ImmutableList) TickUtil(net.glowstone.util.TickUtil) ClientSettings(net.glowstone.entity.meta.ClientSettings) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) MapView(org.bukkit.map.MapView) LinkedList(java.util.LinkedList) SpawnPositionMessage(net.glowstone.net.message.play.game.SpawnPositionMessage) WeatherType(org.bukkit.WeatherType) ExperienceMessage(net.glowstone.net.message.play.game.ExperienceMessage) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) GlowParticle(net.glowstone.constants.GlowParticle) NamedSoundEffectMessage(net.glowstone.net.message.play.game.NamedSoundEffectMessage) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Particle(org.bukkit.Particle) ItemFood(net.glowstone.block.itemtype.ItemFood) ChatColor(org.bukkit.ChatColor) GlowFishingHook(net.glowstone.entity.passive.GlowFishingHook) UserListHeaderFooterMessage(net.glowstone.net.message.play.game.UserListHeaderFooterMessage) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage) ItemTable(net.glowstone.block.ItemTable) GlowBoss(net.glowstone.entity.monster.GlowBoss) PlayerVelocityEvent(org.bukkit.event.player.PlayerVelocityEvent) MapDataMessage(net.glowstone.net.message.play.game.MapDataMessage) PlayerBedLeaveEvent(org.bukkit.event.player.PlayerBedLeaveEvent) StopSoundMessage(net.glowstone.net.message.play.game.StopSoundMessage) World(org.bukkit.World) CloseWindowMessage(net.glowstone.net.message.play.inv.CloseWindowMessage) ChunkDataMessage(net.glowstone.net.message.play.game.ChunkDataMessage) Material(org.bukkit.Material) GlowInventoryView(net.glowstone.inventory.GlowInventoryView) BlockData(org.bukkit.block.data.BlockData) Set(java.util.Set) DelegateDeserialization(org.bukkit.configuration.serialization.DelegateDeserialization) ToolType(net.glowstone.inventory.ToolType) StandardCharsets(java.nio.charset.StandardCharsets) ItemStack(org.bukkit.inventory.ItemStack) ClientOption(com.destroystokyo.paper.ClientOption) MetadataIndex(net.glowstone.entity.meta.MetadataIndex) Action(net.glowstone.net.message.play.game.TitleMessage.Action) GlowOfflinePlayer(net.glowstone.GlowOfflinePlayer) InventoryMonitor(net.glowstone.inventory.InventoryMonitor) PlayerChangedMainHandEvent(org.bukkit.event.player.PlayerChangedMainHandEvent) Tag(org.bukkit.Tag) TimeMessage(net.glowstone.net.message.play.game.TimeMessage) Message(com.flowpowered.network.Message) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) ArrayList(java.util.ArrayList) PlayerRegisterChannelEvent(org.bukkit.event.player.PlayerRegisterChannelEvent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ProfileCache(net.glowstone.entity.meta.profile.ProfileCache) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) SetWindowContentsMessage(net.glowstone.net.message.play.inv.SetWindowContentsMessage) PlayParticleMessage(net.glowstone.net.message.play.game.PlayParticleMessage) Nullable(javax.annotation.Nullable) ResourcePackSendMessage(net.glowstone.net.message.play.player.ResourcePackSendMessage) TeleportCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause) EntityRegainHealthEvent(org.bukkit.event.entity.EntityRegainHealthEvent) PlayerToggleSprintEvent(org.bukkit.event.player.PlayerToggleSprintEvent) Vector(org.bukkit.util.Vector) DyeColor(org.bukkit.DyeColor) Firework(org.bukkit.entity.Firework) PlayerProfile(com.destroystokyo.paper.profile.PlayerProfile) Enchantment(org.bukkit.enchantments.Enchantment) Statistic(org.bukkit.Statistic) Projectile(org.bukkit.entity.Projectile) PlayerBedEnterEvent(org.bukkit.event.player.PlayerBedEnterEvent) BlockFace(org.bukkit.block.BlockFace) Conversation(org.bukkit.conversations.Conversation) StatisticMap(net.glowstone.util.StatisticMap) Block(org.bukkit.block.Block) Difficulty(org.bukkit.Difficulty) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) PlayerReader(net.glowstone.io.PlayerDataService.PlayerReader) PlayerInventory(org.bukkit.inventory.PlayerInventory) SignEntity(net.glowstone.block.entity.SignEntity) Bukkit(org.bukkit.Bukkit) AdvancementProgress(org.bukkit.advancement.AdvancementProgress) JoinGameMessage(net.glowstone.net.message.play.game.JoinGameMessage) MaterialTags(com.destroystokyo.paper.MaterialTags) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) ChatMessageType(net.md_5.bungee.api.ChatMessageType) Sound(org.bukkit.Sound) InetSocketAddress(java.net.InetSocketAddress) List(java.util.List) JSONObject(org.json.simple.JSONObject) Key(net.glowstone.chunk.GlowChunk.Key) NotNull(org.jetbrains.annotations.NotNull) CompoundTag(net.glowstone.util.nbt.CompoundTag) ConversationAbandonedEvent(org.bukkit.conversations.ConversationAbandonedEvent) PlayerGameModeChangeEvent(org.bukkit.event.player.PlayerGameModeChangeEvent) PlayerRecipeMonitor(net.glowstone.inventory.crafting.PlayerRecipeMonitor) SignEditorMessage(net.glowstone.net.message.play.game.SignEditorMessage) Setter(lombok.Setter) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) GlowBlockEntity(net.glowstone.constants.GlowBlockEntity) Getter(lombok.Getter) MetadataMap(net.glowstone.entity.meta.MetadataMap) EntityAnimationMessage(net.glowstone.net.message.play.entity.EntityAnimationMessage) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Effect(org.bukkit.Effect) ByteBuf(io.netty.buffer.ByteBuf) Component(net.kyori.adventure.text.Component) GlowSession(net.glowstone.net.GlowSession) PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) GlowItem(net.glowstone.entity.objects.GlowItem) GlowMapCanvas(net.glowstone.map.GlowMapCanvas) GlowScoreboard(net.glowstone.scoreboard.GlowScoreboard) TextMessage(net.glowstone.util.TextMessage) Type(org.bukkit.Effect.Type) UpdateSignMessage(net.glowstone.net.message.play.game.UpdateSignMessage) StandardMessenger(org.bukkit.plugin.messaging.StandardMessenger) NamespacedKey(org.bukkit.NamespacedKey) Iterator(java.util.Iterator) ItemType(net.glowstone.block.itemtype.ItemType) GlowPlayerProfile(net.glowstone.entity.meta.profile.GlowPlayerProfile) PlayerDropItemEvent(org.bukkit.event.player.PlayerDropItemEvent) WorldType(org.bukkit.WorldType) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage) Note(org.bukkit.Note) FoodLevelChangeEvent(org.bukkit.event.entity.FoodLevelChangeEvent) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) GlowSound(net.glowstone.constants.GlowSound) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) Collections(java.util.Collections) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) GlowFishingHook(net.glowstone.entity.passive.GlowFishingHook) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) ItemType(net.glowstone.block.itemtype.ItemType) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ItemFood(net.glowstone.block.itemtype.ItemFood) Entry(net.glowstone.net.message.play.game.UserListItemMessage.Entry) InventoryMonitor(net.glowstone.inventory.InventoryMonitor) FoodLevelChangeEvent(org.bukkit.event.entity.FoodLevelChangeEvent) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 4 with DestroyEntitiesMessage

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

the class GlowPlayer method hidePlayer.

@Override
public void hidePlayer(Player player) {
    checkNotNull(player, "player cannot be null");
    if (equals(player) || !player.isOnline() || !session.isActive()) {
        return;
    }
    if (hiddenEntities.contains(player.getUniqueId())) {
        return;
    }
    hiddenEntities.add(player.getUniqueId());
    worldLock.writeLock().lock();
    try {
        if (knownEntities.remove(player)) {
            session.send(new DestroyEntitiesMessage(Collections.singletonList(player.getEntityId())));
        }
    } finally {
        worldLock.writeLock().unlock();
    }
    session.send(UserListItemMessage.removeOne(player.getUniqueId()));
}
Also used : DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage)

Example 5 with DestroyEntitiesMessage

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

the class GlowPlayer method respawn.

/**
 * Respawn the player after they have died.
 */
public void respawn() {
    if (!isDead()) {
        return;
    }
    // restore health
    setHealth(getMaxHealth());
    setFoodLevel(20);
    // reset fire ticks
    setFireTicks(0);
    worldLock.writeLock().lock();
    try {
        // determine spawn destination
        boolean spawnAtBed = true;
        Location dest = getBedSpawnLocation();
        if (dest == null) {
            dest = world.getSpawnLocation();
            spawnAtBed = false;
            if (bedSpawn != null) {
                setBedSpawnLocation(null);
                sendMessage("Your home bed was missing or obstructed");
            }
        }
        if (!spawnAtBed) {
            dest = findSafeSpawnLocation(dest);
        }
        // fire event and perform spawn
        PlayerRespawnEvent event = new PlayerRespawnEvent(this, dest, spawnAtBed);
        EventFactory.getInstance().callEvent(event);
        if (event.getRespawnLocation().getWorld().equals(getWorld()) && !knownEntities.isEmpty()) {
            // we need to manually reset all known entities if the player respawns in the
            // same world
            List<Integer> entityIds = new ArrayList<>(knownEntities.size());
            entityIds.addAll(knownEntities.stream().map(GlowEntity::getEntityId).collect(Collectors.toList()));
            session.send(new DestroyEntitiesMessage(entityIds));
            knownEntities.clear();
        }
        active = true;
        deathTicks = 0;
        setStatistic(Statistic.TIME_SINCE_DEATH, 0);
        spawnAt(event.getRespawnLocation());
    } finally {
        worldLock.writeLock().unlock();
    }
    // just in case any items are left in their inventory after they respawn
    updateInventory();
}
Also used : DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) ArrayList(java.util.ArrayList) Location(org.bukkit.Location)

Aggregations

DestroyEntitiesMessage (net.glowstone.net.message.play.entity.DestroyEntitiesMessage)6 Message (com.flowpowered.network.Message)4 Collections (java.util.Collections)3 List (java.util.List)3 EventFactory (net.glowstone.EventFactory)3 Location (org.bukkit.Location)3 Player (org.bukkit.entity.Player)3 NotNull (org.jetbrains.annotations.NotNull)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 Getter (lombok.Getter)2 Setter (lombok.Setter)2 GlowWorld (net.glowstone.GlowWorld)2 GlowPlayer (net.glowstone.entity.GlowPlayer)2 MetadataIndex (net.glowstone.entity.meta.MetadataIndex)2 GlowSession (net.glowstone.net.GlowSession)2 UserListItemMessage (net.glowstone.net.message.play.game.UserListItemMessage)2 InventoryUtil (net.glowstone.util.InventoryUtil)2 Position (net.glowstone.util.Position)2