Java Code Examples for com.google.common.io.ByteArrayDataInput#readShort()
The following examples show how to use
com.google.common.io.ByteArrayDataInput#readShort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BungeeCordImpl.java From helper with MIT License | 5 votes |
@Override public boolean acceptResponse(Player receiver, ByteArrayDataInput in) { short len = in.readShort(); byte[] data = new byte[len]; in.readFully(data); return this.callback.test(data); }
Example 2
Source File: SkyWarsReloaded.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
public void onPluginMessageReceived(String channel, Player player, byte[] message) { if (!channel.equals("BungeeCord")) { return; } ByteArrayDataInput in = ByteStreams.newDataInput(message); String subchannel = in.readUTF(); if (subchannel.equals("GetServer")) { servername = in.readUTF(); } if (subchannel.equals("SWRMessaging")) { short len = in.readShort(); byte[] msgbytes = new byte[len]; in.readFully(msgbytes); DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes)); try { String header = msgin.readUTF(); if (header.equalsIgnoreCase("RequestUpdate")) { String sendToServer = msgin.readUTF(); String playerCount = "" + GameMap.getMaps().get(0).getAlivePlayers().size(); String maxPlayers = "" + GameMap.getMaps().get(0).getMaxPlayers(); String gameStarted = "" + GameMap.getMaps().get(0).getMatchState().toString(); ArrayList<String> messages = new ArrayList<>(); messages.add("ServerUpdate"); messages.add(servername); messages.add(playerCount); messages.add(maxPlayers); messages.add(gameStarted); sendSWRMessage(player, sendToServer, messages); } } catch (IOException e) { e.printStackTrace(); } } }
Example 3
Source File: BungeeReceiver.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
/** * Processes the given data input and attempts to translate it to a message for the "AuthMe.v2.Broadcast" channel. * * @param in the input to handle */ private void handleBroadcast(final ByteArrayDataInput in) { // Read data byte array final short dataLength = in.readShort(); final byte[] dataBytes = new byte[dataLength]; in.readFully(dataBytes); final ByteArrayDataInput dataIn = ByteStreams.newDataInput(dataBytes); // Parse type final String typeId = dataIn.readUTF(); final Optional<MessageType> type = MessageType.fromId(typeId); if (!type.isPresent()) { logger.debug("Received unsupported forwarded bungeecord message type! ({0})", typeId); return; } // Parse argument final String argument; try { argument = dataIn.readUTF(); } catch (IllegalStateException e) { logger.warning("Received invalid forwarded plugin message of type " + type.get().name() + ": argument is missing!"); return; } // Handle type switch (type.get()) { case UNREGISTER: dataSource.invalidateCache(argument); break; case REFRESH_PASSWORD: case REFRESH_QUITLOC: case REFRESH_EMAIL: case REFRESH: dataSource.refreshCache(argument); break; default: } }