public static DataKey<?> readDataKey(DataInput input, DataKeyRegistry registry) throws IOException { return readDataKey(input, registry, null); }
@Override public Icon read(DataInput input) throws IOException { UUID uuid = null; if (input.readBoolean()) { uuid = DataStreamUtils.readUUID(input); } String value = input.readUTF(); String signature = input.readUTF(); return new Icon(uuid, new String[][]{{"textures", value, signature}}); }
@Override public void write(DataOutput output, Icon icon) throws IOException { UUID uuid = icon.getPlayer(); output.writeBoolean(uuid != null); if (uuid != null) { DataStreamUtils.writeUUID(output, uuid); } for (String[] property : icon.getProperties()) { if (property.length == 3 && "textures".equals(property[0])) { output.writeUTF(property[1]); output.writeUTF(property[2]); return; } } output.writeUTF(""); output.writeUTF(""); } }
ByteArrayDataInput input = ByteStreams.newDataInput(Base64.getDecoder().decode(event.getMessage())); try { UUID uuid = DataStreamUtils.readUUID(input); DataKey<?> key = DataStreamUtils.readDataKey(input, keyRegistry, missingDataKeyLogger); ByteArrayDataInput input = ByteStreams.newDataInput(Base64.getDecoder().decode(event.getMessage())); try { UUID uuid = DataStreamUtils.readUUID(input); DataKey<?> key = DataStreamUtils.readDataKey(input, keyRegistry, missingDataKeyLogger);
public <T> void request(UUID uuid, DataKey<T> key) { try { ByteArrayDataOutput data = ByteStreams.newDataOutput(); DataStreamUtils.writeUUID(data, uuid); DataStreamUtils.writeDataKey(data, key); RedisBungee.getApi().sendChannelMessage(CHANNEL_DATA_REQUEST, Base64.getEncoder().encodeToString(data.toByteArray())); redisBungeeAPIError = false; } catch (RuntimeException ex) { if (!redisBungeeAPIError) { logger.log(Level.WARNING, "Error using RedisBungee API", ex); redisBungeeAPIError = true; } } catch (Throwable th) { BungeeTabListPlus.getInstance().getLogger().log(Level.SEVERE, "Failed to request data", th); } }
void requestMissingData() throws IOException { synchronized (this) { if (requestAll) { Server connection = getConnection(); if (connection != null) { List<DataKey<?>> keys = new ArrayList<>(getQueriedKeys()); ByteArrayDataOutput data = ByteStreams.newDataOutput(); data.writeByte(this instanceof PlayerBridgeDataCache ? BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA : BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA_SERVER); data.writeInt(connectionId); data.writeInt(nextOutgoingMessageId++); data.writeInt(keys.size()); for (DataKey<?> key : keys) { DataStreamUtils.writeDataKey(data, key); data.writeInt(idMap.getNetId(key)); } byte[] message = data.toByteArray(); messagesPendingConfirmation.add(message); lastMessageSent = System.currentTimeMillis(); connection.sendData(BridgeProtocolConstants.CHANNEL, message); } requestAll = false; } } } }
private <T> void updateData(UUID uuid, DataKey<T> key, T value) { try { ByteArrayDataOutput data = ByteStreams.newDataOutput(); DataStreamUtils.writeUUID(data, uuid); DataStreamUtils.writeDataKey(data, key); data.writeBoolean(value == null); if (value != null) { typeRegistry.getTypeAdapter(key.getType()).write(data, value); } RedisBungee.getApi().sendChannelMessage(CHANNEL_DATA_UPDATE, Base64.getEncoder().encodeToString(data.toByteArray())); } catch (RuntimeException ex) { BungeeTabListPlus.getInstance().getLogger().log(Level.WARNING, "RedisBungee Error", ex); } catch (Throwable th) { BungeeTabListPlus.getInstance().getLogger().log(Level.SEVERE, "Failed to send data", th); } }
@Override protected <V> void onMissingData(DataKey<V> key) { super.onMissingData(key); try { synchronized (this) { Server connection = getConnection(); if (connection != null) { ByteArrayDataOutput data = ByteStreams.newDataOutput(); data.writeByte(this instanceof PlayerBridgeDataCache ? BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA : BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA_SERVER); data.writeInt(connectionId); data.writeInt(nextOutgoingMessageId++); data.writeInt(1); DataStreamUtils.writeDataKey(data, key); data.writeInt(idMap.getNetId(key)); byte[] message = data.toByteArray(); messagesPendingConfirmation.add(message); lastMessageSent = System.currentTimeMillis(); connection.sendData(BridgeProtocolConstants.CHANNEL, message); } else { requestAll = true; } } } catch (Throwable th) { rlExecutor.execute(() -> { plugin.getLogger().log(Level.SEVERE, "Unexpected exception", th); }); requestAll = true; } }
DataKey<?> key = DataStreamUtils.readDataKey(input, dataKeyRegistry); int keyNetId = input.readInt();