use of org.lanternpowered.server.network.message.Message in project LanternServer by LanternPowered.
the class CodecPlayOutEffect method encode.
@Override
public ByteBuffer encode(CodecContext context, Message message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
if (message instanceof MessagePlayOutEffect) {
final MessagePlayOutEffect message1 = (MessagePlayOutEffect) message;
buf.writeInteger(message1.getType());
buf.write(Types.VECTOR_3_I, message1.getPosition());
buf.writeInteger(message1.getData());
buf.writeBoolean(message1.isBroadcast());
} else if (message instanceof MessagePlayOutRecord) {
final MessagePlayOutRecord message1 = (MessagePlayOutRecord) message;
buf.writeInteger(1010);
buf.write(Types.VECTOR_3_I, message1.getPosition());
buf.writeInteger(message1.getRecord().map(type -> 2256 + ((LanternRecordType) type).getInternalId()).orElse(0));
buf.writeBoolean(false);
} else {
throw new EncoderException("Unsupported message type: " + message.getClass().getName());
}
return buf;
}
use of org.lanternpowered.server.network.message.Message in project LanternServer by LanternPowered.
the class LanternWorld method sendMessage.
@Override
public void sendMessage(ChatType type, Text message) {
checkNotNull(type, "chatType");
checkNotNull(message, "message");
if (!this.players.isEmpty()) {
final Map<Locale, Message> networkMessages = new HashMap<>();
for (LanternPlayer player : this.players) {
player.getConnection().send(networkMessages.computeIfAbsent(player.getLocale(), locale -> ((LanternChatType) type).getMessageProvider().apply(message, locale)));
}
}
}
use of org.lanternpowered.server.network.message.Message in project LanternServer by LanternPowered.
the class LanternWorldBorder method broadcast.
private void broadcast(Supplier<Message> supplier) {
if (!this.players.isEmpty()) {
final Message message = supplier.get();
this.players.forEach(p -> p.getConnection().send(message));
}
}
use of org.lanternpowered.server.network.message.Message in project LanternServer by LanternPowered.
the class LanternBossBar method setPercent.
@Override
public LanternBossBar setPercent(float percent) {
checkNotNull(percent >= 0f && percent <= 1f, "Percent must be between 0 and 1, but %s is not", percent);
if (percent != this.percent && !this.viewers.isEmpty()) {
final Message message = new MessagePlayOutBossBar.UpdatePercent(this.uniqueId, percent);
this.viewers.forEach(player -> player.getConnection().send(message));
}
this.percent = percent;
return this;
}
use of org.lanternpowered.server.network.message.Message in project LanternServer by LanternPowered.
the class MessageProcessorHandler method acceptOutboundMessage.
@Override
public boolean acceptOutboundMessage(Object msg) throws Exception {
final Message message = (Message) msg;
final Protocol protocol = this.codecContext.getSession().getProtocol();
final MessageRegistration registration = protocol.outbound().findByMessageType(message.getClass()).orElse(null);
if (registration == null) {
throw new EncoderException("Message type (" + message.getClass().getName() + ") is not registered in state " + this.codecContext.getSession().getProtocolState().name() + "!");
}
final List<Processor> processors = ((MessageRegistration) protocol.outbound().findByMessageType(message.getClass()).get()).getProcessors();
// Only process if there are processors found
if (!processors.isEmpty()) {
final List<Object> messages = new ArrayList<>();
for (Processor processor : processors) {
// The processor should handle the output messages
processor.process(this.codecContext, message, messages);
}
if (message instanceof ReferenceCounted && !messages.contains(message)) {
((ReferenceCounted) message).release();
}
if (!messages.isEmpty()) {
this.messages.set(messages);
}
return true;
}
return false;
}
Aggregations