Search in sources :

Example 6 with DestroyEntitiesMessage

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

the class EntityUtils method refresh.

/**
 * Refreshes the entity for nearby clients.
 *
 * <p>This will first destroy, and then spawn the painting again using its current art and
 * facing value.
 *
 * @param entity the entity to refresh.
 */
public static void refresh(@NotNull GlowEntity entity) {
    final DestroyEntitiesMessage destroyMessage = new DestroyEntitiesMessage(Collections.singletonList(entity.getEntityId()));
    final List<Message> spawnMessages = entity.createSpawnMessage();
    final Message[] messages = new Message[] { destroyMessage, spawnMessages.get(0) };
    entity.getWorld().getRawPlayers().stream().filter(p -> p.canSeeEntity(entity)).forEach(p -> p.getSession().sendAll(messages));
}
Also used : DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) Attribute(org.bukkit.attribute.Attribute) AttributeInstance(org.bukkit.attribute.AttributeInstance) EventFactory(net.glowstone.EventFactory) EntityRegainHealthEvent(org.bukkit.event.entity.EntityRegainHealthEvent) Message(com.flowpowered.network.Message) GlowEntity(net.glowstone.entity.GlowEntity) LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect) List(java.util.List) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) PotionEffectType(org.bukkit.potion.PotionEffectType) Message(com.flowpowered.network.Message) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage)

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