List of usage examples for com.google.common.io ByteArrayDataInput readInt
@Override
int readInt();
From source file:cpw.mods.fml.common.network.ModIdMapPacket.java
@Override public FMLPacket consumePacket(byte[] data) { ByteArrayDataInput bdi = ByteStreams.newDataInput(data); int chunkIdx = UnsignedBytes.toInt(bdi.readByte()); int chunkTotal = UnsignedBytes.toInt(bdi.readByte()); int chunkLength = bdi.readInt(); if (partials == null) { partials = new byte[chunkTotal][]; }//w ww . j a v a 2 s. c o m partials[chunkIdx] = new byte[chunkLength]; bdi.readFully(partials[chunkIdx]); for (int i = 0; i < partials.length; i++) { if (partials[i] == null) { return null; } } return this; }
From source file:com.yogpc.mc_lib.PacketHandler.java
@Override protected void channelRead0(final ChannelHandlerContext ctx, final YogpstopPacket packet) throws Exception { if (packet.getChannel() == NBT) setNBTFromPacket(packet);//from w ww. j a v a 2 s .c o m else if (packet.getChannel() == WINPROP) { final Container container = packet.getPlayer().openContainer; if (container instanceof IPacketContainer && container.windowId == packet.getHeader()[0]) ((IPacketContainer) container).receivePacket(packet.getData()); } else if (packet.getChannel() == Tile) { final ByteArrayDataInput hdr = ByteStreams.newDataInput(packet.getHeader()); final TileEntity t = packet.getPlayer().worldObj.getTileEntity(hdr.readInt(), hdr.readInt(), hdr.readInt()); if (t instanceof APacketTile) { final APacketTile tb = (APacketTile) t; if (tb.getWorldObj().isRemote) tb.C_recievePacket(hdr.readByte(), packet.getData(), packet.getPlayer()); else tb.S_recievePacket(hdr.readByte(), packet.getData(), packet.getPlayer()); } } else if (packet.getChannel() == STATIC) { final ByteArrayDataInput hdr = ByteStreams.newDataInput(packet.getHeader()); ReflectionHelper.invoke(registeredStaticHandlers.get(hdr.readUTF()), null, packet.getData()); } else if (packet.getChannel() == KEY) YogpstopLib.proxy.setKeys(packet.getPlayer(), packet.getData()[0] << 24 | packet.getData()[1] << 16 | packet.getData()[2] << 8 | packet.getData()[3]); }
From source file:de.paleocrafter.pmfw.tileentity.TileEntityWithData.java
public void readFromPacket(ByteArrayDataInput in) { int superClassCount = in.readInt(); for (int i = 0; i <= superClassCount; i++) { Class<?> clazz = this.getClass(); for (int j = 0; j < i; j++) { if (clazz != null) clazz = clazz.getSuperclass(); }//from w w w . ja va 2 s . c o m readPacketToClass(in, clazz, i); } }
From source file:Trevi.Machinilorum.Packet.PacketManager.java
@Override public void onPacketData(INetworkManager INetworkManager, Packet250CustomPayload Packet, Player Player) { try {/*from w w w. ja v a 2 s. c o m*/ ByteArrayDataInput Data = ByteStreams.newDataInput(Packet.data); DataInputStream DataInput = new DataInputStream((InputStream) Data); int Var1 = Data.readInt(); int Var2 = Data.readInt(); int Var3 = Data.readInt(); World World = ((EntityPlayer) Player).worldObj; if (World != null) { TileEntity TileEntity = World.getBlockTileEntity(Var1, Var2, Var3); if (TileEntity != null) { if (TileEntity instanceof PacketReciever) { ((PacketReciever) TileEntity).handlePacketData(INetworkManager, Packet.channel, Data); TileEntity.readFromNBT(Packet.readNBTTagCompound(DataInput)); } } } } catch (Exception Exception) { LogHandler.Print("Could Not Sent Tag Compound Packet: " + Exception); } }
From source file:buildcraft.core.EntityRobot.java
@Override public void readSpawnData(ByteArrayDataInput data) { box = new Box(); box.xMin = data.readInt(); box.yMin = data.readInt();//w ww .j av a 2s . co m box.zMin = data.readInt(); box.xMax = data.readInt(); box.yMax = data.readInt(); box.zMax = data.readInt(); init(); }
From source file:net.pocketpixels.hubmanager.HubManager.java
@Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { if (!channel.equals("RedisBungee")) { return;/* ww w. j ava 2 s . c o m*/ } ByteArrayDataInput in = ByteStreams.newDataInput(message); String subchannel = in.readUTF(); if (subchannel.equals("PlayerCount")) { try { ServerCount.put(in.readUTF(), in.readInt()); } catch (Exception ex) { } } }
From source file:de.papaharni.amcbungee.events.PluginMessage.java
@EventHandler(priority = EventPriority.LOW) public void onPluginMessage(PluginMessageEvent e) { if (!e.getTag().equalsIgnoreCase("BungeeCord")) return;// ww w.j av a 2 s . co m ByteArrayDataInput in = ByteStreams.newDataInput(e.getData()); String sub = in.readUTF(); if (!sub.equalsIgnoreCase("MyBungee")) return; String cat = in.readUTF(); UUID uuid = UUID.fromString(in.readUTF()); if (cat.equalsIgnoreCase("age")) { int age = in.readInt(); AMCBungee.getInstance().getLogger().log(Level.INFO, "Found {0} with UUID {1} and Age of {2}", new Object[] { cat, uuid.toString(), age }); AMCBungee.getPlayerAge().put(uuid, age); } else if (cat.equalsIgnoreCase("gender")) { String gender = in.readUTF(); AMCBungee.getInstance().getLogger().log(Level.INFO, "Found {0} with UUID {1} and Gender {2}", new Object[] { cat, uuid.toString(), gender }); AMCBungee.getPlayerGender().put(uuid, gender); } else if (cat.equalsIgnoreCase("verify")) { boolean bol = in.readBoolean(); if (bol) AMCBungee.getPlayerVerification().add(uuid); else AMCBungee.getPlayerVerification().remove(uuid); AMCBungee.getInstance().getLogger().log(Level.INFO, "Found {0} with UUID {1} is Verify? {2}", new Object[] { cat, uuid.toString(), bol }); } else if (cat.equalsIgnoreCase("chat")) { String ignore = in.readUTF(); String msg = in.readUTF().replace("__", " "); for (Map.Entry<String, ServerInfo> me : ProxyServer.getInstance().getServers().entrySet()) { if (me.getKey().equalsIgnoreCase(ignore) || me.getValue().getName().equalsIgnoreCase(ignore)) continue; for (ProxiedPlayer pp : me.getValue().getPlayers()) pp.sendMessage(Language.convertString(ChatColor.WHITE + "[" + ChatColor.BLUE + Language.getMsg(AMCBungee.getInstance(), pp.getUniqueId(), "server." + ignore, ignore) + ChatColor.WHITE + "]" + msg)); } } }
From source file:micdoodle8.mods.galacticraft.core.tile.GCCoreTileEntityElectricIngotCompressor.java
@Override public void readPacket(ByteArrayDataInput data) { try {//from w w w . j a va 2 s . c om this.processTicks = data.readInt(); this.setEnergyStored(data.readFloat()); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.paleocrafter.pmfw.tileentity.TileEntityWithData.java
public void readPacketToClass(ByteArrayDataInput in, Class<?> clazz, int iteration) { try {/*from w w w. jav a 2 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:micdoodle8.mods.galacticraft.core.tile.GCCoreTileEntityElectricFurnace.java
@Override public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { try {// www . j a v a 2s . com this.processTicks = dataStream.readInt(); } catch (Exception e) { e.printStackTrace(); } }