Пример #1
0
  private void readObject(ObjectInputStream input) throws ClassNotFoundException, IOException {
    // Default deserialization
    input.defaultReadObject();

    // Get structure modifier
    structureModifier = StructureCache.getStructure(id);

    // Don't read NULL packets
    if (input.readBoolean()) {

      // Create a default instance of the packet
      handle = StructureCache.newPacket(id);

      // Call the read method
      try {
        getMethodLazily(readMethods, handle.getClass(), "read", DataInputStream.class)
            .invoke(handle, new DataInputStream(input));

      } catch (IllegalArgumentException e) {
        throw new IOException("Minecraft packet doesn't support DataInputStream", e);
      } catch (IllegalAccessException e) {
        throw new RuntimeException("Insufficient security privileges.", e);
      } catch (InvocationTargetException e) {
        throw new IOException("Could not deserialize Minecraft packet.", e);
      }

      // And we're done
      structureModifier = structureModifier.withTarget(handle);
    }
  }
Пример #2
0
 /**
  * Creates a packet container for an existing packet.
  *
  * @param id - ID of the given packet.
  * @param handle - contained packet.
  */
 public PacketContainer(int id, Object handle) {
   this(id, handle, StructureCache.getStructure(id).withTarget(handle));
 }
Пример #3
0
 /**
  * Creates a packet container for a new packet.
  *
  * @param id - ID of the packet to create.
  */
 public PacketContainer(int id) {
   this(id, StructureCache.newPacket(id));
 }