@Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { if (AdditionalPipes.CHANNEL.equals(packet.channel)) { DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data)); byte packetID = -1; try { packetID = data.readByte(); switch (packetID) { case ADV_WOOD_DATA: TileEntity te = getTileEntity(player, data); if (te instanceof TileGenericPipe) { PipeItemsAdvancedWood pipe = (PipeItemsAdvancedWood) ((TileGenericPipe) te).pipe; pipe.transport.exclude = !pipe.transport.exclude; } break; case DIST_PIPE_DATA: handleDistPipeData(player, data); break; case TELE_PIPE_DATA_SET: handleTelePipeData(player, data); break; case CHUNKLOAD_DATA: handleChunkLoadData(data); break; case CHUNKLOAD_REQUEST: AdditionalPipes.instance.chunkLoadViewer.sendPersistentChunksToPlayer( (EntityPlayerMP) player); break; } } catch (IOException e) { AdditionalPipes.instance.logger.log(Level.SEVERE, "Error handling packet " + packetID, e); } } else if (AdditionalPipes.CHANNELNBT.equals(packet.channel)) { NBTTagCompound tag = PacketNBTTagData.getNBTFrom(packet); switch (tag.getInteger("id")) { case TELE_PIPE_DATA: TileEntity te = ((EntityPlayer) player) .worldObj.getBlockTileEntity( tag.getInteger("xCoord"), tag.getInteger("yCoord"), tag.getInteger("zCoord")); if (te instanceof TileGenericPipe) { PipeTeleport pipe = (PipeTeleport) ((TileGenericPipe) te).pipe; pipe.owner = tag.getString("owner"); pipe.network = tag.getIntArray("network"); } break; } } }
@Override public IMessage onMessage(MessageTelePipeUpdate message, MessageContext ctx) { TileEntity te = ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.x, message.y, message.z); if (te instanceof TileGenericPipe) { PipeTeleport<?> pipe = (PipeTeleport<?>) ((TileGenericPipe) te).pipe; // only allow the owner to change pipe state EntityPlayerMP entityPlayer = (EntityPlayerMP) ctx.getServerHandler().playerEntity; if (!PipeTeleport.canPlayerModifyPipe(entityPlayer, pipe)) { entityPlayer.addChatComponentMessage( new ChatComponentText("Sorry, You may not change pipe state.")); return null; } int frequency = message._freq; if (frequency < 0) { frequency = 0; } pipe.setFrequency(frequency); pipe.state = (byte) message._state; pipe.isPublic = message._isPublic; } return null; }
private void handleTelePipeData(Player player, DataInputStream data) { try { TileEntity te = getTileEntity(player, data); if (te instanceof TileGenericPipe) { PipeTeleport pipe = (PipeTeleport) ((TileGenericPipe) te).pipe; // only allow the owner to change pipe state EntityPlayerMP entityPlayer = (EntityPlayerMP) player; if (!PipeTeleport.canPlayerModifyPipe(entityPlayer, pipe)) { entityPlayer.sendChatToPlayer( ChatMessageComponent.createFromText("You may not change pipe state.")); return; } int frequency = data.readInt(); if (frequency < 0) { frequency = 0; } pipe.setFrequency(frequency); pipe.state = (byte) data.read(); pipe.isPublic = (data.read() == 1); } } catch (IOException e) { AdditionalPipes.instance.logger.log(Level.SEVERE, "Error handling teleport pipe packet.", e); } }