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;
}
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));
}
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));
}
}
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);
}
}
Aggregations