public static DataWriter getWriter(PacketId id) { DataWriter dw = new DataWriter(); dw.writeByte( 1); // amount of packets, defaults to 1. Hast obe a byte so it's easy to modify afterwards dw.writeData(id.getId(), DataBitHelper.PACKET_ID); return dw; }
private void onPacketData(byte[] incomingData, EntityPlayer player, boolean onServer) { DataReader dr = null; try { dr = getDataReaderForPacket(incomingData); if (dr == null) { return; } // read the packet count that was manually read before the creation of the data reader dr.readByte(); PacketId id = PacketId.getFromId((byte) dr.readData(DataBitHelper.PACKET_ID)); switch (id) { case OPEN_INTERFACE: boolean isOpBook = dr.readBoolean(); if (isOpBook) { String openName = dr.readString(DataBitHelper.NAME_LENGTH); clientNameOverride = openName.equals(player.getGameProfile().getName()) ? null : openName; } QuestingData.getQuestingData(player).receiveDataFromServer(dr); GuiQuestBook.displayGui(player, isOpBook); break; case QUEST_DATA: handleQuestData(player, dr); break; case TASK_REQUEST: handleTaskRequest(player, dr); break; case CLAIM_REWARD: handleRewardClaim(player, dr); break; case SELECT_TASK: handleSelectTask(player, dr); break; case SOUND: SoundHandler.handleSoundPacket(dr); break; case LORE: SoundHandler.handleLorePacket(player, dr); break; case TEAM: Team.handlePacket(player, dr, onServer); break; case REFRESH_INTERFACE: QuestingData.getQuestingData(player).receiveDataFromServer(dr); break; case CLOSE_INTERFACE: remove(player); break; case REFRESH_TEAM: QuestingData.getQuestingData(player).getTeam().onPacket(dr); break; case OP_BOOK: OPBookHelper.handlePacket(player, dr); break; case QUEST_SYNC: QuestLine.receiveServerSync(dr); GuiEditMenuItem.Search.initItems(); break; case BAG_INTERFACE: GuiReward.open(player, dr); break; case DEATH_STATS_UPDATE: DeathStats.handlePacket(player, dr); break; case TEAM_STATS_UPDATE: TeamStats.handlePacket(player, dr); break; case TRACKER_ACTIVATE: TileEntityTracker.openInterface(player, dr); break; case TRACKER_RESPONSE: TileEntityTracker.saveToServer(player, dr); break; case BLOCK_SYNC: handleBlockSync(player, dr); } } catch (Throwable ex) { ex.printStackTrace(); } finally { if (dr != null) { dr.close(); } } }