// 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;
      }
    }
  }
 public void flushUnloadQueue() {
   synchronized (unloadQueue) {
     Iterator<ChunkCoordIntPair> i = unloadQueue.iterator();
     while (i.hasNext()) {
       ChunkCoordIntPair coord = i.next();
       if (activeChunks.remove(coord)) {
         super.sendPacket(new Packet50PreChunk(coord.x, coord.z, false));
       }
       i.remove();
     }
   }
 }