Search in sources :

Example 1 with Message

use of org.spongepowered.api.network.Message in project Almura by AlmuraDev.

the class ServerTitleManager method refreshSelectedTitleFor.

public void refreshSelectedTitleFor(Player player, boolean add) {
    final Message message;
    if (add) {
        message = this.createAddPlayerSelectedTitlePacket(player.getUniqueId(), this.selectedTitlesById.get(player.getUniqueId()));
    } else {
        message = this.createRemovePlayerSelectedTitlePacket(player.getUniqueId());
    }
    this.network.sendToAll(message);
}
Also used : Message(org.spongepowered.api.network.Message)

Example 2 with Message

use of org.spongepowered.api.network.Message in project LanternServer by LanternPowered.

the class LanternIndexedMessageChannel method handlePayload.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
void handlePayload(ByteBuffer buf, RemoteConnection connection) {
    final byte opcode = buf.readByte();
    final IndexedMessageRegistration registration = getRegistrations(Platform.Type.SERVER).opcodeToRegistration.get(opcode);
    if (registration == null) {
        Lantern.getLogger().warn("Received unexpected message type with id: {}" + " in the indexed message channel: {}", opcode, getName());
        return;
    }
    final Message message;
    try {
        message = registration.messageType.newInstance();
    } catch (Exception e) {
        Lantern.getLogger().error("Failed to instantiate message: {}", registration.messageType.getName(), e);
        return;
    }
    final ByteBuffer content = buf.slice();
    try {
        message.readFrom(content);
    } catch (Exception e) {
        Lantern.getLogger().error("Failed to deserialize message: {}", registration.messageType.getName(), e);
        return;
    }
    registration.handlers.forEach(handler -> ((MessageHandler) handler).handleMessage(message, connection, Platform.Type.SERVER));
}
Also used : Message(org.spongepowered.api.network.Message) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Aggregations

Message (org.spongepowered.api.network.Message)2 ByteBuffer (org.lanternpowered.server.network.buffer.ByteBuffer)1