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;
  }
예제 #2
0
 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;
 }
예제 #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);
    }
예제 #4
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");
   }
 }
예제 #5
0
 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;
   }
 }
예제 #6
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);
   }
 }
예제 #7
0
  @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();
    }
  }
예제 #8
0
 @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();
   }
 }
예제 #9
0
 @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();
     }
   }
 }
예제 #10
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);
    }
  }
예제 #11
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);
    }
  }
예제 #12
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();
    }
  }
  /** 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;
    }
  }