Search in sources :

Example 31 with Message

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

the class GlowFishingHook method createSpawnMessage.

/**
 * Creates the spawn messages given the shooter ID on the receiving end (which is different for
 * the shooter than for everyone else).
 *
 * @param shooterId the shooter's ID, according to the receiving client
 * @return the spawn messages
 */
private List<Message> createSpawnMessage(int shooterId) {
    List<Message> spawnMessage = super.createSpawnMessage();
    double x = location.getX();
    double y = location.getY();
    double z = location.getZ();
    int intPitch = Position.getIntPitch(location);
    int intHeadYaw = Position.getIntHeadYaw(location.getYaw());
    spawnMessage.set(0, new SpawnObjectMessage(getEntityId(), getUniqueId(), EntityNetworkUtil.getObjectId(EntityType.FISHING_HOOK), x, y, z, intPitch, intHeadYaw, shooterId, velocity));
    return spawnMessage;
}
Also used : SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) Message(com.flowpowered.network.Message) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage)

Example 32 with Message

use of com.flowpowered.network.Message 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)

Example 33 with Message

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

the class BaseProtocolTest method testProtocol.

@Test
public void testProtocol() throws Exception {
    Map<Class<? extends Message>, Codec.CodecRegistration> inboundMap = getField(inboundCodecs, CodecLookupService.class, "messages");
    Map<Class<? extends Message>, Codec.CodecRegistration> outboundMap = getField(outboundCodecs, CodecLookupService.class, "messages");
    Set<Class<? extends Message>> inboundSet = new HashSet<>(inboundMap.keySet());
    Set<Class<? extends Message>> outboundSet = new HashSet<>(outboundMap.keySet());
    for (Message message : testMessages) {
        boolean any = false;
        Class<? extends Message> clazz = message.getClass();
        // test inbound
        Codec.CodecRegistration registration = inboundCodecs.find(clazz);
        if (registration != null) {
            inboundSet.remove(clazz);
            checkCodec(registration, message);
            any = true;
        }
        // test outbound
        registration = outboundCodecs.find(clazz);
        if (registration != null) {
            outboundSet.remove(clazz);
            checkCodec(registration, message);
            any = true;
        }
        assertThat("Codec missing for: " + message, any, is(true));
    }
    // special case: HeldItemMessage is excluded from tests
    inboundSet.remove(HeldItemMessage.class);
    outboundSet.remove(HeldItemMessage.class);
    assertThat("Did not test inbound classes: " + inboundSet, inboundSet.isEmpty(), is(true));
    // todo: enable the outbound check for PlayProtocol
    if (!(protocol instanceof PlayProtocol)) {
        assertThat("Did not test outbound classes: " + outboundSet, outboundSet.isEmpty(), is(true));
    }
}
Also used : Codec(com.flowpowered.network.Codec) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage) Message(com.flowpowered.network.Message) PlayProtocol(net.glowstone.net.protocol.PlayProtocol) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 34 with Message

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

the class BaseProtocolTest method checkCodec.

private void checkCodec(Codec.CodecRegistration reg, Message message) {
    // check a message with its codec
    try {
        Codec<Message> codec = reg.getCodec();
        ByteBuf buffer = codec.encode(Unpooled.buffer(), message);
        Message decoded = codec.decode(buffer);
        buffer.release();
        assertThat("Asymmetry for " + reg.getOpcode() + "/" + message.getClass().getName(), decoded, is(message));
    } catch (IOException e) {
        throw new AssertionError("Error in I/O for " + reg.getOpcode() + "/" + message.getClass().getName(), e);
    }
}
Also used : HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage) Message(com.flowpowered.network.Message) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf)

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