List of usage examples for com.google.common.io ByteArrayDataInput readUTF
@Override String readUTF();
From source file:de.bl4ckskull666.afkbukkit.AFKBukkit.java
@Override public void onPluginMessageReceived(String c, Player p, byte[] m) { if (!c.equalsIgnoreCase("BungeeCord")) return;/* w w w . j av a2 s .c o m*/ ByteArrayDataInput in = ByteStreams.newDataInput(m); String sub = in.readUTF(); if (!sub.equalsIgnoreCase("AFKB")) return; String cat = in.readUTF(); if (cat.equalsIgnoreCase("Player")) { UUID uuid = UUID.fromString(in.readUTF()); boolean bol = in.readBoolean(); debugMe("Receive " + uuid.toString() + " with " + bol); AFKBukkit.checkSwitchPlayer(uuid, bol); } else if (cat.equalsIgnoreCase("Config")) { debugMe("Receive Configuration"); String conf = in.readUTF(); String val = in.readUTF().replace("__--__", " "); if (conf != null && val != null) { AFKBukkit.getPlugin().getConfig().set(conf, val); debugMe("Receive " + conf + " Configuration from Bungee and set " + val + " it."); } saveConfig(); } }
From source file:cpw.mods.fml.common.network.ModMissingPacket.java
@Override public FMLPacket consumePacket(byte[] data) { ByteArrayDataInput dat = ByteStreams.newDataInput(data); int missingLen = dat.readInt(); missing = Lists.newArrayListWithCapacity(missingLen); for (int i = 0; i < missingLen; i++) { ModData md = new ModData(); md.modId = dat.readUTF(); md.modVersion = dat.readUTF();/*from w w w . j ava 2s. c o m*/ missing.add(md); } int badVerLength = dat.readInt(); badVersion = Lists.newArrayListWithCapacity(badVerLength); for (int i = 0; i < badVerLength; i++) { ModData md = new ModData(); md.modId = dat.readUTF(); md.modVersion = dat.readUTF(); badVersion.add(md); } return this; }
From source file:com.demigodsrpg.chitchat.bungee.BungeeChitchat.java
@EventHandler(priority = EventPriority.HIGHEST) public void onMessage(final PluginMessageEvent event) { if (event.getTag().equals("BungeeCord")) { // Get origin server ServerInfo origin = Iterables.find(getProxy().getServers().values(), new Predicate<ServerInfo>() { @Override//from ww w. j a v a2s . co m public boolean apply(ServerInfo serverInfo) { return serverInfo.getAddress().equals(event.getSender().getAddress()); } }, null); // If origin doesn't exist (impossible?) throw an exception if (origin == null) { throw new NullPointerException("Origin server for a chat message was null."); } // Get the data ByteArrayDataInput in = ByteStreams.newDataInput(event.getData()); // Needed for it to work because whynot String messageType = in.readUTF(); String targetServer = in.readUTF(); // Ignore messages that aren't the correct type if (!"Forward".equals(messageType)) { return; } // Get the chat channel and speaking player String chatChannelRaw = in.readUTF(); // Don't continue if this message isn't from chitchat if (!chatChannelRaw.startsWith("chitchat")) { return; } // Grab the speaking player and clean up the chat channel name String speakingPlayerName = chatChannelRaw.split("\\$")[1]; String chatChannel = chatChannelRaw.split("\\$")[2]; // Is this a mute update? if (chatChannelRaw.startsWith("chatchatmute$")) { MUTED_PLAYERS.put(chatChannel, speakingPlayerName.toLowerCase()); return; } // Is this an unmute update? if (chatChannelRaw.startsWith("chatchatunmute$")) { MUTED_PLAYERS.remove(chatChannel, speakingPlayerName.toLowerCase()); return; } // Ignore muted players if (MUTED_PLAYERS.containsEntry(chatChannel, speakingPlayerName.toLowerCase())) { return; } // Is this a valid chat channel? if (!CHAT_CHANNELS.containsEntry(chatChannel, origin.getName())) { CHAT_CHANNELS.put(chatChannel, origin.getName()); } // Process the data short len = in.readShort(); byte[] msgbytes = new byte[len]; in.readFully(msgbytes); DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes)); try { // Finally get the message String message = msgin.readUTF(); // Send the message to appropriate servers for (ServerInfo server : getProxy().getServers().values()) { // Continue from invalid targets if (origin.getName().equals(server.getName()) || !CHAT_CHANNELS.containsEntry(chatChannel, server.getName())) { continue; } // Send the message to the appropriate players for (ProxiedPlayer player : server.getPlayers()) { player.sendMessage(message); } } } catch (IOException oops) { oops.printStackTrace(); } } }
From source file:cpw.mods.fml.common.network.ModListResponsePacket.java
@Override public FMLPacket consumePacket(byte[] data) { ByteArrayDataInput dat = ByteStreams.newDataInput(data); int versionListSize = dat.readInt(); modVersions = Maps.newHashMapWithExpectedSize(versionListSize); for (int i = 0; i < versionListSize; i++) { String modName = dat.readUTF(); String modVersion = dat.readUTF(); modVersions.put(modName, modVersion); }/*from ww w . ja v a 2 s . c o m*/ int missingModSize = dat.readInt(); missingMods = Lists.newArrayListWithExpectedSize(missingModSize); for (int i = 0; i < missingModSize; i++) { missingMods.add(dat.readUTF()); } return this; }
From source file:net.minecraftforge.gradle.user.patcherUser.TaskApplyBinPatches.java
private ClassPatch readPatch(JarEntry patchEntry, JarInputStream jis) throws IOException { log("\t%s", patchEntry.getName()); ByteArrayDataInput input = ByteStreams.newDataInput(ByteStreams.toByteArray(jis)); String name = input.readUTF(); String sourceClassName = input.readUTF(); String targetClassName = input.readUTF(); boolean exists = input.readBoolean(); int inputChecksum = 0; if (exists) { inputChecksum = input.readInt(); }/*from w w w . j a v a 2 s. c o m*/ int patchLength = input.readInt(); byte[] patchBytes = new byte[patchLength]; input.readFully(patchBytes); return new ClassPatch(name, sourceClassName, targetClassName, exists, inputChecksum, patchBytes); }
From source file:micdoodle8.mods.galacticraft.core.tile.GCCoreTileEntityAirLockController.java
@Override public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput data) { try {/*ww w .ja v a 2 s . c om*/ this.active = data.readBoolean(); this.ownerName = data.readUTF(); this.redstoneActivation = data.readBoolean(); this.playerDistanceActivation = data.readBoolean(); this.playerDistanceSelection = data.readInt(); this.playerNameMatches = data.readBoolean(); this.playerToOpenFor = data.readUTF(); this.invertSelection = data.readBoolean(); this.horizontalModeEnabled = data.readBoolean(); } catch (final Exception e) { e.printStackTrace(); } }
From source file:com.yogpc.qp.TileBasic.java
@Override protected void S_recievePacket(final byte id, final byte[] data, final EntityPlayer ep) { final ByteArrayDataInput badi = ByteStreams.newDataInput(data); switch (id) { case PacketHandler.CtS_REMOVE_FORTUNE: this.fortuneList.remove(new BlockData(badi.readUTF(), badi.readInt())); break;/*from w w w .ja va2 s .co m*/ case PacketHandler.CtS_REMOVE_SILKTOUCH: this.silktouchList.remove(new BlockData(badi.readUTF(), badi.readInt())); break; case PacketHandler.CtS_TOGGLE_FORTUNE: this.fortuneInclude = !this.fortuneInclude; break; case PacketHandler.CtS_TOGGLE_SILKTOUCH: this.silktouchInclude = !this.silktouchInclude; break; } }
From source file:com.yogpc.qp.tile.TileBasic.java
@Override public void S_recievePacket(final byte id, final byte[] data, final EntityPlayer ep) { final ByteArrayDataInput badi = ByteStreams.newDataInput(data); switch (id) { case PacketHandler.CtS_REMOVE_FORTUNE: this.fortuneList.remove(new BlockData(badi.readUTF(), badi.readInt())); break;/*from w ww . j a v a 2 s . c om*/ case PacketHandler.CtS_REMOVE_SILKTOUCH: this.silktouchList.remove(new BlockData(badi.readUTF(), badi.readInt())); break; case PacketHandler.CtS_TOGGLE_FORTUNE: this.fortuneInclude = !this.fortuneInclude; break; case PacketHandler.CtS_TOGGLE_SILKTOUCH: this.silktouchInclude = !this.silktouchInclude; break; } }
From source file:de.paleocrafter.pmfw.tileentity.TileEntityWithData.java
public void readPacketToClass(ByteArrayDataInput in, Class<?> clazz, int iteration) { try {/*from www . j a v a2 s .c o m*/ int fieldCount = in.readInt(); for (int i = 0; i < fieldCount; i++) { try { String fieldName = in.readUTF(); Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); String className = field.getType().getSimpleName(); className = Character.toUpperCase(className.charAt(0)) + className.substring(1); if (field.getType().isAssignableFrom(String.class)) className = "UTF"; if (className != null) { if (IDataObject.class.isAssignableFrom(field.getType())) { IDataObject data = (IDataObject) field.getType().newInstance(); data.readFromPacket(in); field.set(this, data); } else { Method method = in.getClass().getMethod("read" + className); method.setAccessible(true); field.set(this, method.invoke(in)); } } } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } catch (Exception e) { } }
From source file:de.emc.plugin.Plugin.java
@Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { if (!channel.equals("BungeeCord")) { return;//from ww w .j a v a2 s .c o m } ByteArrayDataInput in = ByteStreams.newDataInput(message); String subchannel = in.readUTF(); if (subchannel.equals("GetMotd")) { String server = in.readUTF(); ArrayList<org.bukkit.block.Sign> list = signs.get(server); String motd = in.readUTF(); String players = in.readUTF(); String max = in.readUTF(); String line0 = Store.getString("signline0"); line0 = line0.replaceAll("%motd%", motd); line0 = line0.replaceAll("%players%", players); line0 = line0.replaceAll("%max%", max); String line1 = Store.getString("signline1"); line1 = line1.replaceAll("%motd%", motd); line1 = line1.replaceAll("%players%", players); line1 = line1.replaceAll("%max%", max); String line2 = Store.getString("signline2"); line2 = line2.replaceAll("%motd%", motd); line2 = line2.replaceAll("%players%", players); line2 = line2.replaceAll("%max%", max); String line3 = Store.getString("signline3"); line3 = line3.replaceAll("%motd%", motd); line3 = line3.replaceAll("%players%", players); line3 = line3.replaceAll("%max%", max); for (org.bukkit.block.Sign s : list) { if (line0 == "") { line0 = s.getLine(0); } s.setLine(0, line0); if (line1 == "") { line1 = s.getLine(0); } s.setLine(1, line1); if (line2 == "") { line2 = s.getLine(0); } s.setLine(2, line2); if (line3 == "") { line3 = s.getLine(0); } s.setLine(3, line3); s.update(); } } if (subchannel.equals("Broadcast")) { String from = in.readUTF(); String msg = in.readUTF(); String conf = Store.getString("bcmsg"); conf = conf.replaceAll("%msg%", msg); conf = conf.replaceAll("%from%", from); this.getServer().broadcastMessage(conf); } if (subchannel.equals("GBroadcast")) { String from = in.readUTF(); String msg = in.readUTF(); String conf = Store.getString("gbcmsg"); conf = conf.replaceAll("%msg%", msg); conf = conf.replaceAll("%from%", from); this.getServer().broadcastMessage(conf); } }