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