ArrayList<CrystalReceiver> getNearbyReceivers(CrystalTransmitter r, CrystalElement e) {
   ArrayList<CrystalReceiver> li = new ArrayList();
   try {
     for (WorldLocation c : tiles.keySet()) {
       if (c.dimensionID == r.getWorld().provider.dimensionId) {
         CrystalNetworkTile tile = tiles.get(c);
         if (tile instanceof CrystalReceiver && r != tile) {
           CrystalReceiver te = (CrystalReceiver) tile;
           if (te.canConduct() && r.canTransmitTo(te)) {
             if (e == null || te.isConductingElement(e)) {
               double d = te.getDistanceSqTo(r.getX(), r.getY(), r.getZ());
               // ReikaJavaLibrary.pConsole(e+": "+d+": "+te);
               double send = r.getSendRange();
               double dist = te.getReceiveRange();
               if (d <= Math.min(dist * dist, send * send)) {
                 li.add(te);
               }
             }
           }
         }
       }
     }
   } catch (ConcurrentModificationException ex) {
     ex.printStackTrace();
     ChromatiCraft.logger.logError(
         "CME when trying to pathfind on the crystal network. This indicates a deeper issue.");
   }
   return li;
 }
  public Raster getFrame() {

    // lock the model so other people don't modify it while we do paint
    // calls based on it.
    synchronized (m) {
      // presumes that you instantiated Raster with a PGraphics.
      PGraphics myRaster = (PGraphics) (r.getRaster());
      myRaster.beginDraw();

      // TODO THIS SHOULD BE THE NORMAL WAY TO FIND NEW PEOPLE/CREATE NEW SPRITES
      ConcurrentHashMap<Integer, Person> people = m.getPeople();
      Iterator<Person> iter = people.values().iterator();
      while (iter.hasNext()) {
        Person p = iter.next();
        if (p.isNew()) {
          // TODO instantiate new sprites here
          Cross cross = new Cross(spriteIndex, r, p, 1, 1, sm, 3, 3); // 3x3 cross
          int[] loc = p.getLoc();
          // System.out.println(loc[0]+" "+loc[1]);
          cross.moveTo(loc[0] * tileSize, loc[1] * tileSize);
          cross.addListener(this);
          // sprites.add(cross);
          sprites.put(spriteIndex, cross);
          spriteIndex++;
        }
      }

      /*
      myRaster.background(0);		// clear the raster
      Cross cross = new Cross(r, null, 1, 1, 3, 3);		// 3x3 cross
      boolean[] sensorlist = m.getSensors();
      for(int i=0; i<sensorlist.length; i++){	// sensorlist is 16x11
      	if(sensorlist[i]){
      		int x = i % 16;			// probably shouldn't be static values
      		int y = i / 16;
      		// position is offset by 1 because of the extra column on each side
      		cross.moveTo((x+1)*tileSize, y*tileSize);	// moves instance of sprite to active tile
      		cross.draw();			// draws instance
      	}
      }
      */

      // TODO THIS SHOULD BE THE NORMAL WAY TO DRAW ALL SPRITES
      try {
        myRaster.background(0); // clear the raster
        Iterator<Sprite> spriteiter = sprites.values().iterator();
        while (spriteiter.hasNext()) {
          Sprite sprite = (Sprite) spriteiter.next();
          sprite.draw();
        }
      } catch (ConcurrentModificationException e) {
        // TODO WHY DOES IT THROW THESE ERRORS?
        e.printStackTrace();
      }

      // myRaster.background(255,0,0); // FULLY ON
      myRaster.endDraw();
    }
    return r;
  }
Exemple #3
0
    @Override
    public void run() {
      @SuppressWarnings("rawtypes")
      List entities = null;

      try {
        switch (TYPE) {
          case 0:
            entities = etc.getServer().getPlayerList();
            break;
          case 1:
            entities = this.WORLD.getMobList();
            break;
          case 2:
            entities = this.WORLD.getAnimalList();
            break;
          case 3:
            entities = this.WORLD.getLivingEntityList();
            break;
          case 4:
            entities = entitiesExceptPlayers(this.WORLD.getWorld());
            break;
          case 5:
            entities = entitiesExceptPlayersItems(this.WORLD.getWorld());
            break;
        }
      } catch (ConcurrentModificationException e) {
        e.printStackTrace();
        return;
      }

      if (entities == null) return;

      boolean found = false;

      for (Object obj : entities) {
        BaseEntity entity = (BaseEntity) obj;
        if (entity.getWorld().getType().getId() != WORLD.getType().getId()) continue;

        double diffX = BLOCK.getBlockX() - entity.getX();
        double diffY = BLOCK.getBlockY() - entity.getY();
        double diffZ = BLOCK.getBlockZ() - entity.getZ();

        if (diffX * diffX + diffY * diffY + diffZ * diffZ < DISTANCE) {
          boolean result = entityInRange(entity);
          if (result) {
            found = true;
            if (DESTROY) {
              entity.destroy();
            } else {
              break;
            }
          }
        }
      }

      Redstone.setOutput(CraftBook.getCBWorld(WORLD), LEVER, found);
    }
  public void stop() {
    try {
      lock.lock();

      if (networkJob != null && !networkJob.isCancelled()) {
        networkJob.cancel(true);
        networkJob = null;
      }

      try {
        if (selector != null) {

          selector.wakeup();

          boolean isContinue = true;
          while (isContinue) {
            try {
              for (SelectionKey selectionKey : selector.keys()) {
                selectionKey.channel().close();
                selectionKey.cancel();
              }
              isContinue = false; // continue till all keys are cancelled
            } catch (ConcurrentModificationException e) {
              logger.warn(
                  "An exception occurred while closing a selector key : '{}'", e.getMessage());
            }
          }

          selector.close();
        }
      } catch (IOException e) {
        logger.warn("An exception occurred while closing the selector : '{}'", e.getMessage());
      }

      if (broadcastKey != null) {
        try {
          broadcastKey.channel().close();
        } catch (IOException e) {
          logger.warn(
              "An exception occurred while closing the broadcast channel : '{}'", e.getMessage());
        }
      }

      if (unicastKey != null) {
        try {
          unicastKey.channel().close();
        } catch (IOException e) {
          logger.warn(
              "An exception occurred while closing the unicast channel : '{}'", e.getMessage());
        }
      }

      ipAddress = null;
    } finally {
      lock.unlock();
    }
  }
 public CrystalSource getConnectivity(CrystalElement e, CrystalReceiver r) {
   EntityPlayer ep =
       r.getPlacerUUID() != null ? r.getWorld().func_152378_a(r.getPlacerUUID()) : null;
   try {
     CrystalPath p = new PylonFinder(e, r, ep).findPylon();
     return p != null && p.canTransmit() ? p.transmitter : null;
   } catch (ConcurrentModificationException ex) {
     ex.printStackTrace();
     ChromatiCraft.logger.logError("CME during pathfinding!");
     return null;
   }
 }
Exemple #6
0
 public void addLinkFrom(Link<N> link) {
   linksFrom.add(link);
   try {
     span.addAll(link.to.span);
     span.add(link.to);
   } catch (ConcurrentModificationException ex) {
     ex.printStackTrace();
     System.out.println("This was while trying to link from " + link + " to " + this);
     System.out.println("That link was from " + link.from + " to " + link.to);
     System.out.println("This is quite possibly some kind of circular dependency");
   }
 }
    /**
     * Synch.
     *
     * @throws SearchException the search exception
     */
    public void synch() throws SearchException {

      if (__suppliedCriteria == __sessionCriteria) {
        return;
      }
      try {
        __sessionCriteria.loadSearchCriteria(__suppliedCriteria.toDom());
      } catch (ConcurrentModificationException e) {
        // This sometimes occurs especially when the user presesses the search
        // button multiple times at a very fast pace
        LOG.fine("Saving session failed" + e.getMessage());
      }
    }
  @EventHandler
  public void move(PlayerMoveEvent event) {
    if (worldGuard == null) return;

    Player player = event.getPlayer();

    if (!regionsVisited.containsKey(player.getUniqueId()))
      regionsVisited.put(player.getUniqueId(), new ArrayList<>());

    RegionContainer container = worldGuard.getWorldGuard().getRegionContainer();
    RegionManager manager = container.get(player.getWorld());
    if (manager == null) return;

    ApplicableRegionSet regions = manager.getApplicableRegions(event.getTo());
    List<ProtectedRegion> visited = regionsVisited.get(player.getUniqueId());

    try {
      for (ProtectedRegion region : regions.getRegions()) {
        if (!visited.contains(region)) {
          // i've never seen this place before in my life... or maybe in 30 seconds
          visited.add(region);
          Bukkit.getScheduler()
              .runTaskLaterAsynchronously(
                  JavaPlugin.getPlugin(Tyrant.class), () -> enter(player, region), 1);
        }
      }

      Bukkit.getScheduler()
          .runTaskLater(
              JavaPlugin.getPlugin(Tyrant.class),
              () -> {
                for (ProtectedRegion region2 : visited) {
                  if (!regions.getRegions().contains(region2)) {
                    // leaving the tavern
                    visited.remove(region2);
                    Bukkit.getScheduler()
                        .runTaskLaterAsynchronously(
                            JavaPlugin.getPlugin(Tyrant.class), () -> exit(player), 1);
                  }
                }
              },
              1);
    } catch (ConcurrentModificationException e) {
      e.printStackTrace();
    }
  }
Exemple #9
0
 public void addFolder(Object parentFolder, String folderName) {
   if (parentFolder == null) {
     parentFolder = rootDir;
   }
   try {
     File fParentFolder = (File) ((DefaultMutableTreeNode) parentFolder).getUserObject();
     File f = new File(fParentFolder.getAbsolutePath() + File.separator + folderName);
     if (!f.exists()) f.mkdir();
     for (int i = 0; i < listeners.size(); i++) {
       listeners.get(i).treeNodesInserted(null);
     }
   } catch (ConcurrentModificationException cme) {
     cme.printStackTrace();
   } catch (Exception e) {
     throw new IllegalArgumentException(PluginServices.getText(this, "invalid_folder_name"), e);
   }
 }
 @SubscribeEvent
 public void clearOnUnload(WorldEvent.Unload evt) {
   PylonFinder.stopAllSearches();
   int dim = evt.world.provider.dimensionId;
   ChromatiCraft.logger.debug("Unloading dimension " + dim + ", clearing crystal network.");
   try {
     this.clear(dim);
     for (WorldLocation c : tiles.keySet()) {
       CrystalNetworkTile te = tiles.get(c);
       PylonFinder.removePathsWithTile(te);
       if (te instanceof CrystalTransmitter) ((CrystalTransmitter) te).clearTargets(true);
     }
     tiles.removeWorld(evt.world);
     for (TileEntityCache c : pylons.values()) c.removeWorld(evt.world);
   } catch (ConcurrentModificationException e) {
     ChromatiCraft.logger.logError(
         "Clearing the crystal network on world unload caused a CME. This is indicative of a deeper problem.");
     e.printStackTrace();
   }
 }
  public void realizeViews(TiUIView view) {
    setModelListener(view);

    // Use a copy so bundle can be modified as it passes up the inheritance
    // tree. Allows defaults to be added and keys removed.
    if (children != null) {
      try {
        for (TiViewProxy p : children) {
          TiUIView cv = p.getOrCreateView();
          view.add(cv);
        }
      } catch (ConcurrentModificationException e) {
        Log.e(LCAT, e.getMessage(), e);
      }
    }

    synchronized (pendingAnimationLock) {
      if (pendingAnimation != null) {
        handlePendingAnimation(true);
      }
    }
  }
 @Override
 public void run() {
   while (true) {
     if (Server.isRunning() == false) {
       Server.setLock(true);
       try {
         serverSocket.close();
         if (Server.getClients() > 0) {
           try {
             for (MiniServer subClient : util.clients()) {
               synchronized (subClient) {
                 System.out.println(util.getDate() + subClient.getCId() + " disconnected.");
                 subClient.sendMessage("Server Closed");
                 subClient.close();
               }
             }
             util.clients().clear();
           } catch (ConcurrentModificationException e) {
             e.printStackTrace();
           }
         }
       } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
       Server.setLock(false);
       break;
     }
     try {
       Thread.sleep(10);
     } catch (InterruptedException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
Exemple #13
0
      private boolean getNext() {
        java.lang.Throwable $yieldException;
        while (true) {
          try {
            switch ($state) {
              case 0:
                $state = 1;
              case 1:
                b = true;
              case 2:
                $yieldException1 = null;
                $state1 = 2;
                $state = 3;
              case 3:
                if (b) {
                  throw new RuntimeException();
                }
                $next = "bar";
                $state = 5;
                return true;
              case 4:
                $next = "foo";
                $state = 5;
                return true;
              case 5:
                {
                  b = !b;
                }
                if ($yieldException1 != null) {
                  $yieldException = $yieldException1;
                  break;
                }
                $state = $state1;
                continue;

              case 6:

              default:
                return false;
            }
          } catch (final java.lang.Throwable $yieldExceptionCaught) {
            $yieldException = $yieldExceptionCaught;
          }
          switch ($state) {
            case 3:
              if ($yieldException instanceof RuntimeException) {
                e = (RuntimeException) $yieldException;
                $state = 4;
                continue;
              }
            case 4:
              $yieldException1 = $yieldException;
              $state = 5;
              continue;
            default:
              $state = 6;
              java.util.ConcurrentModificationException $yieldExceptionUnhandled =
                  new java.util.ConcurrentModificationException();
              $yieldExceptionUnhandled.initCause($yieldException);
              throw $yieldExceptionUnhandled;
          }
        }
      }
  /** This method draws the image and repaint the selection square of the mouse listener. */
  public synchronized void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    // Graphics2D g2d3 = (Graphics2D) g;
    Rectangle2D rectangle = null;

    g.drawImage(image, 0, 0, null);

    w = image.getWidth(null);
    h = image.getHeight(null);

    if (selection.getX() < 0) {
      coorX = 0;
      width = selection.getWidth() + selection.getX();
    } else {
      coorX = selection.getX();
      width = selection.getWidth();
    }

    if ((selection.getX() + selection.getWidth()) >= w) {
      coorX = selection.getX();
      width = w - selection.getX() - 1;
    }

    if (selection.getY() < 0) {
      coorY = 0;

      height = selection.getHeight() + selection.getY();
    } else {
      coorY = selection.getY();
      height = selection.getHeight();
    }

    if ((selection.getY() + selection.getHeight()) >= h) {
      coorY = selection.getY();
      height = h - selection.getY() - 1;
    }

    if (ended == false) {

      rectangle = new Rectangle2D.Double(coorX, coorY, width, height);
      g2d.setColor(Color.yellow);

      g2d.draw(rectangle);

      if (window != null) {
        g2d.setColor(Color.yellow);
        g2d.draw(window);
      }

      try {
        for (Rectangle2D.Double rect : rectangleList) {
          g2d.setColor(Color.green);
          g2d.draw(rect);
        }
      } catch (ConcurrentModificationException e) {
        MyLogHandler.writeException(e);
        e.printStackTrace();
      }

    } else {
      coorX = 0;
      coorY = 0;
      width = 0;
      height = 0;
      window = null;
      ended = false;

      selection.width = 0;
      selection.x = 0;
      selection.height = 0;
      selection.y = 0;
    }
  }
Exemple #15
0
  @Background
  public void updatePOIs(LatLng loc) {
    double lat = loc.latitude;
    double lon = loc.longitude;
    Log.d(TAG, "Camera center: Lat: " + lat + " Long: " + lon);
    ViewMapFragment frag = (ViewMapFragment) mMapFragment;
    List<OSMNode> NodesList = null;
    boolean fountain = false;
    boolean toilet = false;
    boolean rest = false;
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("show_fountain", true)) {
      fountain = true;
    }

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("show_toilet", true)) {
      toilet = true;
    }

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("show_rest", false)) {
      rest = true;
    }

    try {
      NodesList = OSMWrapperAPI.fetch(lon, lat, 0.005, fountain, toilet, rest);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    Iterator<OSMNode> geolistIterator;
    try {
      geolistIterator = NodesList.iterator();
    }
    // If the list is empty...
    catch (NullPointerException e) {
      stopProgressbar();
      return;
    }

    try {
      while (geolistIterator.hasNext()) {
        // Log.d(MapActivity.tag,"Adding GeoPoint");
        OSMNode osmNode = geolistIterator.next();
        Map<String, String> tag = osmNode.getTags();

        // Remove duplicates
        // TODO: move this into a method
        boolean tapExists = false;
        boolean toiletExists = false;
        boolean foodExists = false;

        Iterator<OSMNode> tapItemIterator = allTapItem.iterator();
        while (tapItemIterator.hasNext()) {
          OSMNode item = tapItemIterator.next();
          if (item.getId().equals(osmNode.getId())) {
            tapExists = true;
            //	Log.d(TAG, item.getId() + ": Node Exists");
          }
          tapItemIterator.remove();
        }

        Iterator<OSMNode> toiletItemIterator = allToiletItem.iterator();
        while (toiletItemIterator.hasNext()) {
          OSMNode item = toiletItemIterator.next();
          if (item.getId().equals(osmNode.getId())) {
            toiletExists = true;
            //	Log.d(TAG, item.getId() + ": Node Exists");
          }
          toiletItemIterator.remove();
        }

        Iterator<OSMNode> foodItemIterator = allFoodItem.iterator();
        while (foodItemIterator.hasNext()) {
          OSMNode item = foodItemIterator.next();
          if (item.getId().equals(osmNode.getId())) {
            foodExists = true;
            //	Log.d(TAG, item.getId() + ": Node Exists");
          }
          foodItemIterator.remove();
        }

        if (tag.containsValue("drinking_water") && !tapExists) {
          allTapItem.add(osmNode);
        } else if (tag.containsValue("toilets") && !toiletExists) {
          allToiletItem.add(osmNode);
        } else if ((tag.containsValue("fast_food")
                || tag.containsValue("cafe")
                || tag.containsValue("food_court")
                || tag.containsValue("restaurant"))
            && !foodExists) {
          allFoodItem.add(osmNode);
        }
        frag.addMarker(osmNode);
        geolistIterator.remove();
      }
      Log.d(
          TAG,
          "Tap Overlay Size: "
              + allTapItem.size()
              + "\nToilet Overlay Size: "
              + allToiletItem.size()
              + "\nFood Overlay Size: "
              + allFoodItem.size());
    } catch (ConcurrentModificationException e) {
      Log.e(TAG, "ConcurrentModificationException has occured " + e.getStackTrace());
    }
    stopProgressbar();
  }
Exemple #16
0
  void drawObjects(
      Graphics g,
      java.util.List<DrawObject> points,
      java.util.List<DrawObject> lines,
      java.util.List<DrawObject> ovals,
      java.util.List<DrawObject> rectangles,
      java.util.List<DrawObject> images,
      java.util.List<DrawObject> labels,
      java.util.List<DrawObject> eqnLines) {
    try {
      // Images
      synchronized (images) {
        for (DrawObject I : images) {
          drawImage(g, I);
        }
      }

      // Labels
      synchronized (labels) {
        for (DrawObject L : labels) {
          drawLabel(g, L);
        }
      }

      // Eqn Lines
      synchronized (eqnLines) {
        for (DrawObject L : eqnLines) {
          g.setColor(L.color);
          drawEqnLine(g, L);
        }
      }

      // Lines
      synchronized (lines) {
        for (DrawObject L : lines) {
          g.setColor(L.color);
          drawLine(g, L);
        }
      }

      // Rectangles
      synchronized (rectangles) {
        for (DrawObject R : rectangles) {
          g.setColor(R.color);
          drawOvalOrRectangle(g, R, true);
        }
      }

      // Ovals
      synchronized (ovals) {
        for (DrawObject R : ovals) {
          g.setColor(R.color);
          drawOvalOrRectangle(g, R, false);
        }
      }

      // Points.
      synchronized (points) {
        for (DrawObject p : points) {
          g.setColor(p.color);
          drawPoint(g, p);
        }
      }
    } catch (ConcurrentModificationException e) {
      e.printStackTrace();
      System.exit(0);
    }
  }
  @Override
  public void onDrawFrame(GL10 gl) {
    try {
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glLoadIdentity();

      if (positionBuffer != null) {
        gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, positionBuffer);
      }

      synchronized (camera) {
        PointF c = getCameraLocation();
        if (c == camera) {
          GLU.gluLookAt(gl, c.x, c.y, zoom, camera.x, camera.y, 0.0f, 0.0f, 1.0f, 0.0f);
        } else {
          GLU.gluLookAt(
              gl,
              c.x,
              c.y,
              zoom / followHeightFactor,
              camera.x,
              camera.y,
              -FOLLOW_LOOK_AT_HEIGHT,
              0.0f,
              0.0f,
              -1.0f);
        }
      }

      synchronized (areas) {
        for (SimArea area : areas.values()) {
          if (!onlySeenAreas || seenAreas.contains(area.getID())) {
            area.draw(gl);
          }
        }
      }

      if (drawWalls) {
        synchronized (walls) {
          for (SimWall wall : walls) {
            wall.draw(gl);
          }
        }

        synchronized (wallTops) {
          for (SimWallTop wallTop : wallTops) {
            wallTop.draw(gl);
          }
        }
      }

      synchronized (objects) {
        for (SimObject obj : objects.values()) {
          obj.draw(gl);
        }
      }

      synchronized (robots) {
        for (SimRobot robot : robots.values()) {
          robot.draw(gl, drawRedLidar, drawBlueLidar, drawYellowWaypoint);
        }
      }

      synchronized (lastFloorTouch) {
        GLUtil.drawRect(
            gl,
            lastFloorTouch.x - 0.05f,
            lastFloorTouch.y - 0.25f,
            -0.01f,
            0.1f,
            0.5f,
            GLUtil.GRAY);
        GLUtil.drawRect(
            gl,
            lastFloorTouch.x - 0.25f,
            lastFloorTouch.y - 0.05f,
            -0.01f,
            0.5f,
            0.1f,
            GLUtil.GRAY);
      }

    } catch (ConcurrentModificationException e) {
      e.printStackTrace();
    }
  }
Exemple #18
0
  /**
   * It removes the card from the players hand.
   *
   * @param card
   */
  public void removeCard(Card card) {
    synchronized (this) {
      LinkedList<Tractor> postadd = new LinkedList<Tractor>();

      if (this.triples.contains(card)) {
        this.triples.remove(card);
        this.pairs.add(card);

        for (Iterator<Tractor> i = this.tractors.iterator(); i.hasNext(); ) {
          Tractor tractor = i.next();
          int index = tractor.getCards().indexOf(card);
          if (index > -1) {
            if (tractor.getType() == 3) {
              // TODO: tractors might be out of order if there's a pair tractor with cards larger
              // than the triple tractor
              // ^ but does it ever matter that the tractors in the hand are sorted?
              tractor.tripleToPair();
              if (tractor.getLength() > 2) {
                Iterator<Card> it = tractor.getCards().iterator();
                Card current = it.next();
                if (current == card) current = it.next();

                while (it.hasNext()) {
                  Card previous;
                  List<Card> tractorcards = new LinkedList<Card>();
                  do {
                    tractorcards.add(current);
                    previous = current;
                    current = it.next();
                    if (current == card) {
                      if (it.hasNext()) {
                        current = it.next();
                      } else {
                        current = null;
                        break;
                      }
                    }
                  } while (it.hasNext() && this.cc.gameCompare(current, previous) == 1);
                  if (this.cc.gameCompare(current, previous) == 1) tractorcards.add(current);

                  if (tractorcards.size() >= 2) {
                    postadd.add(new Tractor(3, tractorcards));
                  }
                  tractorcards.clear();
                }
              }
            }
            // break;
          }
        }

        for (Iterator<Tractor> i = postadd.iterator(); i.hasNext(); ) {
          tractors.add(i.next());
          i.remove();
        }

        // can't be any mixed tractors of type 3

      } else if (this.pairs.contains(card)) {
        this.pairs.remove(card);

        for (Iterator<Tractor> i = this.tractors.iterator(); i.hasNext(); ) {
          Tractor tractor = null;
          try {
            tractor = i.next();
          } catch (ConcurrentModificationException e) {
            System.out.println("shit @PlayerHand.188");
            e.printStackTrace(System.out);
            break;
          }

          int index = tractor.getCards().indexOf(card);
          if (index > -1) {
            if (tractor.getType() == 2) {
              i.remove();

              if (tractor.getLength() > 2) {
                Iterator<Card> it = tractor.getCards().iterator();
                Card current = it.next();
                if (current == card) current = it.next();

                while (it.hasNext()) {
                  Card previous;
                  List<Card> tractorcards = new LinkedList<Card>();
                  do {
                    tractorcards.add(current);
                    previous = current;
                    current = it.next();
                    if (current == card) {
                      if (it.hasNext()) {
                        current = it.next();
                      } else {
                        current = null;
                        break;
                      }
                    }
                  } while (it.hasNext() && this.cc.gameCompare(current, previous) == 1);
                  if (this.cc.gameCompare(current, previous) == 1) tractorcards.add(current);

                  if (tractorcards.size() >= 2) {
                    postadd.add(new Tractor(2, tractorcards));
                  }
                  tractorcards.clear();
                }
              }
            }
            // break;
          }
        }

        for (Iterator<Tractor> i = postadd.iterator(); i.hasNext(); ) {
          tractors.add(i.next());
          i.remove();
        }

        // TODO: combine for statements to optimize
        for (Iterator<Tractor> i = this.mixed.iterator(); i.hasNext(); ) {
          Tractor tractor = i.next();
          int index = tractor.getCards().indexOf(card);
          if (index > -1) {
            if (tractor.getType() == 2) {
              i.remove();

              if (tractor.getLength() > 2) {
                Iterator<Card> it = tractor.getCards().iterator();
                Card current = it.next();
                if (current == card) current = it.next();

                while (it.hasNext()) {
                  Card previous;
                  List<Card> tractorcards = new LinkedList<Card>();
                  do {
                    tractorcards.add(current);
                    previous = current;
                    current = it.next();
                    if (current == card) {
                      if (it.hasNext()) {
                        current = it.next();
                      } else {
                        current = null;
                        break;
                      }
                    }
                  } while (it.hasNext() && this.cc.gameCompare(current, previous) == 1);
                  if (this.cc.gameCompare(current, previous) == 1) tractorcards.add(current);

                  if (tractorcards.size() >= 2) {
                    tractors.add(new Tractor(2, tractorcards));
                  }
                  tractorcards.clear();
                }
              }
            }
            // break;
          }
        }
      }

      this.cards.remove(card);
    }
  }