Ejemplo n.º 1
0
  // Called from the main thread only
  private void syncedSendPacket(Packet packet, MCCraftPacket[] packetWrappers) {
    int packetId = -1;
    try {
      packetId = packet.b();
    } catch (Exception e) {
      return;
    }

    try {
      if (!PacketListeners.canSend(getPlayer(), packet, packetWrappers, packetId)) {
        return;
      } else {
        if (packet instanceof Packet51MapChunk) {
          Packet51MapChunk chunk = (Packet51MapChunk) packet;
          if (chunk.buffer == null) {
            ChunkCompressionThread.sendPacket(player, packet);
            return;
          }
        }
        super.sendPacket(packet);
      }
    } catch (NullPointerException npe) {
      if (packet != null) {
        throw new RuntimeException(
            "Null pointer exception thrown when trying to process packet of type "
                + packet.getClass().getName(),
            npe);
      } else {
        throw npe;
      }
    }
  }
Ejemplo n.º 2
0
 private Packet getFastPacket51(int cx, int cz) {
   World world = getPlayer().getWorld();
   if (!world.isChunkLoaded(cx, cz)) {
     world.loadChunk(cx, cz);
   }
   Packet packet = new Packet51MapChunk(cx << 4, 0, cz << 4, 16, 128, 16, this.player.world);
   try {
     packet.lowPriority = false;
     Field g = Packet51MapChunk.class.getDeclaredField("buffer");
     g.setAccessible(true);
     byte[] compressedData = (byte[]) g.get(packet);
     if (compressedData == null) {
       MCPacket.setPacket(packet, 51);
       if (!PacketListeners.canSendUncompressedPacket(getPlayer(), MCPacket)) {
         return null;
       }
       AtomicInteger size = new AtomicInteger(0);
       Field rawData;
       try {
         rawData = Packet51MapChunk.class.getDeclaredField("rawData");
       } catch (NoSuchFieldException e) {
         rawData = Packet51MapChunk.class.getDeclaredField("buffer");
       }
       Field h = Packet51MapChunk.class.getDeclaredField("size");
       rawData.setAccessible(true);
       h.setAccessible(true);
       byte[] rawBytes = (byte[]) rawData.get(packet);
       if (rawBytes != null) {
         g.set(packet, compressData(rawBytes, size));
         h.set(packet, size.get());
       }
     }
   } catch (NoSuchFieldException e) {
     return null;
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   }
   return packet;
 }