private static final List<List<Location>> gridWith(
     List<Location> topRow, Location topLeft, Location bottomLeft) {
   int rowCount = topLeft.equals(bottomLeft) ? 1 : topLeft.distanceFrom(bottomLeft) + 1;
   return Stream.iterate(topRow, row -> row.stream().map(Location::south).collect(toList()))
       .limit(rowCount)
       .collect(toList());
 }
Ejemplo n.º 2
0
Archivo: set.java Proyecto: wcyuan/Set
    public void mousePressed(MouseEvent e) {
      Message(null, null, 1);
      Message(null, null, 2);
      Message(null, null, 3);
      if (EODtag) {
        deal();
        update(Applet.this.getGraphics());
        return;
      }
      Location l = findloc(e);
      if (l == null) return;
      if (l == button) {
        ShowSet();
        return;
      }

      l.toggle();

      update(Applet.this.getGraphics());

      if (num_selected >= 3) {
        CheckSet();
      }

      lastloc = l;
    }
Ejemplo n.º 3
0
  private void calculateRay(int ox, int oy, int oz, Collection<BlockVector> result) {
    double x = ox / 7.5 - 1;
    double y = oy / 7.5 - 1;
    double z = oz / 7.5 - 1;
    Vector direction = new Vector(x, y, z);
    direction.normalize();
    direction.multiply(0.3f); // 0.3 blocks away with each step

    Location current = location.clone();

    float currentPower = calculateStartPower();

    while (currentPower > 0) {
      GlowBlock block = world.getBlockAt(current);

      if (block.getType() != Material.AIR) {
        double blastDurability = getBlastDurability(block) / 5d;
        blastDurability += 0.3F;
        blastDurability *= 0.3F;
        currentPower -= blastDurability;

        if (currentPower > 0) {
          result.add(new BlockVector(block.getX(), block.getY(), block.getZ()));
        }
      }

      current.add(direction);
      currentPower -= 0.225f;
    }
  }
Ejemplo n.º 4
0
 private void updateWithNewLocation(Location result) {
   haveGPS.setVisibility(View.VISIBLE);
   geoBean = new GeoBean();
   geoBean.setLatitude(result.getLatitude());
   geoBean.setLongitude(result.getLongitude());
   new GetGoogleLocationInfo(geoBean).execute();
   ((LocationManager) WriteWeiboActivity.this.getSystemService(Context.LOCATION_SERVICE))
       .removeUpdates(locationListener);
 }
Ejemplo n.º 5
0
 public static String getLocationMethodQName(@NotNull Location location) {
   StringBuilder res = new StringBuilder();
   ReferenceType type = location.declaringType();
   if (type != null) {
     res.append(type.name()).append('.');
   }
   res.append(location.method().name());
   return res.toString();
 }
Ejemplo n.º 6
0
 public static void playSound(Player to, String sound, Location loc, float volume, float data) {
   if (Storm.wConfigs.get(to.getWorld().getName()).Play__Weather__Sounds)
     ((CraftPlayer) to)
         .getHandle()
         .playerConnection
         .sendPacket(
             new Packet62NamedSoundEffect(
                 sound, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), volume, data));
 }
Ejemplo n.º 7
0
    @Override
    public void addChild(Location parent, Location newChild) {
      if (this.manager != null) {
        parent.getChildLocations().add(newChild);
        newChild.setParentLocation(parent);

        manager.persistLocation(newChild);
      }
    }
Ejemplo n.º 8
0
 /** if this line can not be current => stepOver & return true. return false on the other hand. */
 boolean resolveCanBeCurrent(ThreadReference tr) {
   try {
     Location l = tr.frame(0).location();
     if (l == null) return false;
     return resolveCanBeCurrent(
         tr, Utils.getLineForSource(l.declaringType().name(), l.sourceName(), l.lineNumber()));
   } catch (Exception e) {
   }
   return false;
 }
Ejemplo n.º 9
0
  /**
   * Checks if the location is near a block in the list on the same layer.
   *
   * @param location the location
   * @param blocks the collection of blocks to search
   * @param radius the radius to search
   * @return boolean
   */
  public static boolean isLocationNearBlock(
      Location location, Collection<Integer> blocks, int radius) {
    World world = location.getWorld();
    int x = (int) location.getX(), y = (int) location.getY(), z = (int) location.getZ();

    for (int ox = radius; ox > -radius; ox--)
      for (int oz = radius; oz > -radius; oz--)
        if (blocks.contains(world.getBlockAt(x + ox, y, z + oz).getTypeId())) return false;
    return true;
  }
Ejemplo n.º 10
0
 public Location getSurfaceAt(Location origin) {
   Chunk chunky = origin.getChunk();
   int x = origin.getBlockX(),
       z = origin.getBlockZ(),
       surface = 0,
       envid = origin.getWorld().getEnvironment().getId();
   Set dimmap =
       Sets.newHashSet(envid == 0 ? new int[] {1, 2, 3, 7, 15, 16} : envid == -1 ? 87 : 121);
   for (int y = 0; y != 256; y++)
     if (dimmap.contains(chunky.getBlock(x, y, z).getTypeId())) surface = y;
   return chunky.getBlock(x, surface, z).getLocation();
 }
  public void move() {
    if (last_move_time == null || last_move_time.doubleValue() < world.time) {
      last_move_time = new Double(world.time);
      double max_dist, dist_right, dist_left, theta, x, y, dist_diff;
      double delta_theta, turn_radius, new_theta, new_x, new_y;
      Location location;
      Orientation orientation;

      orientation = orientation();
      location = location();

      max_dist = max_speed / world.ticks_per_second;
      dist_right = right_motor.output() * max_dist;
      dist_left = left_motor.output() * max_dist;
      theta = orientation.theta;
      x = location.x;
      y = location.y;
      old_location.x = x;
      old_location.y = y;
      dist_diff = dist_right - dist_left;

      //			System.out.println("dist_diff: " + dist_diff);

      delta_theta = dist_diff / wheel_base;
      if (Math.abs(dist_diff) < .0001) {
        turn_radius = 0.0;
      } else {
        turn_radius = (dist_right / delta_theta) - (wheel_base / 2);
      }

      //			System.out.println("turn_radius: " + turn_radius);

      new_theta = theta + delta_theta;
      if (turn_radius == 0.0) {

        //				System.out.println("turn_radius == 0");

        new_x = x + Math.cos(theta) * dist_left;
        new_y = y + Math.sin(theta) * dist_left;
      } else {

        //				System.out.println("new_theta= " + new_theta + " theta= " + theta);

        new_x = x + ((Math.sin(new_theta) - Math.sin(theta)) * turn_radius);
        new_y = y - ((Math.cos(new_theta) - Math.cos(theta)) * turn_radius);
      }
      orientation.theta = new_theta;
      location.x = new_x;
      location.y = new_y;

      maybe_fire_guns();
    }
  }
Ejemplo n.º 12
0
  /**
   * Creates a new explosion
   *
   * @param source The entity causing this explosion
   * @param location The location this explosion is occuring at. Must contain a GlowWorld
   * @param power The power of the explosion
   * @param incendiary Whether or not blocks should be set on fire
   * @param breakBlocks Whether blocks should break through this explosion
   */
  public Explosion(
      Entity source, Location location, float power, boolean incendiary, boolean breakBlocks) {
    if (!(location.getWorld() instanceof GlowWorld)) {
      throw new IllegalArgumentException("Supplied location does not have a valid GlowWorld");
    }

    this.source = source;
    this.location = location.clone();
    this.power = power;
    this.incendiary = incendiary;
    this.breakBlocks = breakBlocks;
    this.world = (GlowWorld) location.getWorld();
  }
Ejemplo n.º 13
0
 public WorldEditorException(final String msg, final Location loc) {
   super(
       msg
           + " at "
           + loc.getWorld().getName()
           + ":"
           + loc.getBlockX()
           + ":"
           + loc.getBlockY()
           + ":"
           + loc.getBlockZ());
   this.loc = loc;
 }
Ejemplo n.º 14
0
    @Override
    public boolean removeChild(Location child) {
      if (child.getParentLocation() != null && manager != null) {
        child.getParentLocation().getChildLocations().remove(child);
        child.setParentLocation(null);

        manager.cascadeDeleteLocation(child.getId());

        return true;
      }

      return false;
    }
Ejemplo n.º 15
0
 /** Gets a Location entity by its exact name. */
 public static Location getLocationByName(String locationName, Location parent) {
   LocationService locationService = Context.getLocationService();
   Location location = locationService.getLocation(locationName);
   if (location == null) {
     location = new Location();
     location.setName(locationName);
     location.setDescription(locationName);
     if (parent != null) {
       location.setParentLocation(parent);
     }
     locationService.saveLocation(location);
   }
   return location;
 }
Ejemplo n.º 16
0
  static synchronized String sourceLine(Location location, int lineNumber) throws IOException {
    if (lineNumber == -1) {
      throw new IllegalArgumentException();
    }

    try {
      String fileName = location.sourceName();

      Iterator<SourceCode> iter = sourceCache.iterator();
      SourceCode code = null;
      while (iter.hasNext()) {
        SourceCode candidate = iter.next();
        if (candidate.fileName().equals(fileName)) {
          code = candidate;
          iter.remove();
          break;
        }
      }
      if (code == null) {
        BufferedReader reader = sourceReader(location);
        if (reader == null) {
          throw new FileNotFoundException(fileName);
        }
        code = new SourceCode(fileName, reader);
        if (sourceCache.size() == SOURCE_CACHE_SIZE) {
          sourceCache.remove(sourceCache.size() - 1);
        }
      }
      sourceCache.add(0, code);
      return code.sourceLine(lineNumber);
    } catch (AbsentInformationException e) {
      throw new IllegalArgumentException();
    }
  }
Ejemplo n.º 17
0
 private Vector distanceToHead(LivingEntity entity) {
   return entity
       .getLocation()
       .clone()
       .subtract(location.clone().subtract(0, entity.getEyeHeight(), 0))
       .toVector();
 }
Ejemplo n.º 18
0
  public static void main(String[] args) {
    try {
      JSObject js1 = new JSObject();
      JSObject js2 = new JSObject();
      JSObject js3 = new JSObject();

      js1.put("x", new ObjectValue("Y"));

      js2.put(new String("a"), new SecurityType(SecurityType.high, null));
      js2.put(new String("u"), null);

      js3.put(new String("b"), null);

      // Testing the alloc function
      Heap h = new Heap();
      Location l0 = h.alloc(Location.generateLocString(), js1);
      Location l1 = h.alloc("0", js1);
      Location l2 = h.alloc("10", js2);
      System.out.println("loc 1: " + l1);
      System.out.println("loc 2: " + l2);
      System.out.println("Heap : " + h);

      Heap h0 = h.deepClone();
      Heap h1 = h.clone();
      // Location l3 = h.alloc("5", js3);

      System.out.println("Heap comparison: " + h.equals(h0));
      System.out.println("Heap comparison: " + h.equals(h1));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public BreakpointRequest createBreakpointRequest(Location location) {
   // validateMirror(location);
   if (location.codeIndex() == -1) {
     throw new NativeMethodException("Cannot set breakpoints on native methods");
   }
   return new BreakpointRequestImpl(location);
 }
 private static Class<?> type(Location location) {
   try {
     return Class.forName(location.getClassName());
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
  /**
   * Sends image as an URL to IE 8 & 9, base64 data for others
   *
   * @param url
   * @param bufferedImage
   * @param bbox
   * @param isTiled
   */
  protected void sendWFSImage(
      String url,
      BufferedImage bufferedImage,
      Double[] bbox,
      boolean isTiled,
      boolean isboundaryTile) {
    if (bufferedImage == null) {
      log.warn("Failed to send image");
      return;
    }

    Map<String, Object> output = new HashMap<String, Object>();
    output.put(OUTPUT_LAYER_ID, this.layerId);

    Location location = this.session.getLocation();

    Tile tileSize = null;
    if (isTiled) {
      tileSize = this.session.getTileSize();
    } else {
      tileSize = this.session.getMapSize();
    }

    output.put(OUTPUT_IMAGE_SRS, location.getSrs());
    output.put(OUTPUT_IMAGE_BBOX, bbox);
    output.put(OUTPUT_IMAGE_ZOOM, location.getZoom());
    output.put(OUTPUT_IMAGE_TYPE, this.type.toString()); // "normal" | "highlight"
    output.put(OUTPUT_KEEP_PREVIOUS, this.session.isKeepPrevious());
    output.put(OUTPUT_BOUNDARY_TILE, isboundaryTile);
    output.put(OUTPUT_IMAGE_WIDTH, tileSize.getWidth());
    output.put(OUTPUT_IMAGE_HEIGHT, tileSize.getHeight());
    output.put(OUTPUT_IMAGE_URL, url);

    byte[] byteImage = WFSImage.imageToBytes(bufferedImage);
    String base64Image = WFSImage.bytesToBase64(byteImage);
    int base64Size = (base64Image.length() * 2) / 1024;

    // IE6 & IE7 doesn't support base64, max size in base64 for IE8 is 32KB
    if (!(this.session.getBrowser().equals(BROWSER_MSIE) && this.session.getBrowserVersion() < 8
        || this.session.getBrowser().equals(BROWSER_MSIE)
            && this.session.getBrowserVersion() == 8
            && base64Size >= 32)) {
      output.put(OUTPUT_IMAGE_DATA, base64Image);
    }

    this.service.addResults(this.session.getClient(), ResultProcessor.CHANNEL_IMAGE, output);
  }
  public boolean runHighlightJob() {
    if (!this.sendHighlight) {
      // highlight job with a flag for not sending images, what is going on in here?
      return true;
    }
    if (!this.requestHandler(null)) {
      return false;
    }
    this.featuresHandler();
    if (!goNext()) {
      return false;
    }
    // Send geometries, if requested as well
    if (this.session.isGeomRequest()) {
      this.sendWFSFeatureGeometries(
          this.geomValuesList, ResultProcessor.CHANNEL_FEATURE_GEOMETRIES);
    }
    log.debug("highlight image handling", this.features.size());
    // IMAGE HANDLING
    log.debug("sending");
    Location location = this.session.getLocation();
    if (this.image == null) {
      this.image =
          new WFSImage(
              this.layer,
              this.session.getClient(),
              this.session.getLayers().get(this.layerId).getStyleName(),
              JobType.HIGHLIGHT.toString());
    }
    BufferedImage bufferedImage =
        this.image.draw(this.session.getMapSize(), location, this.features);
    if (bufferedImage == null) {
      this.imageParsingFailed();
      throw new RuntimeException("Image parsing failed!");
    }

    Double[] bbox = location.getBboxArray();

    // cache (non-persistant)
    setImageCache(
        bufferedImage, JobType.HIGHLIGHT.toString() + "_" + this.session.getSession(), bbox, false);

    String url = createImageURL(JobType.HIGHLIGHT.toString(), bbox);
    this.sendWFSImage(url, bufferedImage, bbox, false, false);
    return true;
  }
Ejemplo n.º 23
0
 public Module setTestMethod(final Location<PsiMethod> methodLocation) {
   final PsiMethod method = methodLocation.getPsiElement();
   METHOD_NAME = method.getName();
   TEST_OBJECT = TEST_METHOD;
   return setMainClass(
       methodLocation instanceof MethodLocation
           ? ((MethodLocation) methodLocation).getContainingClass()
           : method.getContainingClass());
 }
 private List<Location> neighboursOf(Location location) {
   return asList(
       location.northWest(),
       location.north(),
       location.northEast(),
       location.west(), /*  location  */
       location.east(),
       location.southWest(),
       location.south(),
       location.southEast());
 }
Ejemplo n.º 25
0
  /*
   *  getMSG (String id, [char color1, char color2], Object param1, Object param2, Object param3... )
   */
  public String getMSG(Object... s) {
    String str = "&4Unknown message";
    String color1 = "&" + this.c1;
    String color2 = "&" + this.c2;
    if (s.length > 0) {
      String id = s[0].toString();
      str = "&4Unknown message (" + id + ")";
      if (msg.containsKey(id)) {
        int px = 1;
        if ((s.length > 1) && (s[1] instanceof Character)) {
          px = 2;
          color1 = "&" + s[1];
          if ((s.length > 2) && (s[2] instanceof Character)) {
            px = 3;
            color2 = "&" + s[2];
          }
        }
        str = color1 + msg.get(id);
        if (px < s.length)
          for (int i = px; i < s.length; i++) {
            String f = s[i].toString();
            if (s[i] instanceof Location) {
              Location loc = (Location) s[i];
              f =
                  loc.getWorld().getName()
                      + "["
                      + loc.getBlockX()
                      + ", "
                      + loc.getBlockY()
                      + ", "
                      + loc.getBlockZ()
                      + "]";
            }
            str = str.replace("%" + Integer.toString(i - px + 1) + "%", color2 + f + color1);
          }

      } else if (this.savelng) {
        addMSG(id, str);
        SaveMSG();
      }
    }
    return ChatColor.translateAlternateColorCodes('&', str);
  }
Ejemplo n.º 26
0
  public void zoneCrystalCreation(Player player, Location blockLocation) {

    World world = player.getWorld();

    Location centerBlock = new CenterBlock().variable(player, blockLocation, 0.475);

    centerBlock.getBlock().setType(Material.AIR);
    world.spawn(centerBlock, EnderCrystal.class);

    int cBX = centerBlock.getBlockX();
    int cBY = centerBlock.getBlockY();
    int cBZ = centerBlock.getBlockZ();

    List<String> zoneList = RocketInit.getPlugin().getConfig().getStringList("zones");
    String activeZone =
        player.getUniqueId().toString() + "|" + world.getName() + "|" + cBX + "|" + cBY + "|" + cBZ;
    zoneList.add(activeZone);

    RocketInit.getPlugin().getConfig().set("zones", zoneList);
    RocketInit.getPlugin().saveConfig();

    reloadFlyZones(false);

    Location particleLocation = new Location(world, cBX + 0.5, cBY + 1.2, cBZ + 0.5);

    world.playSound(centerBlock, Sound.ENTITY_WITHER_AMBIENT, 1.25f, 0.55f);

    PacketPlayOutWorldParticles packet =
        new PacketPlayOutWorldParticles(
            EnumParticle.PORTAL,
            false,
            particleLocation.getBlockX(),
            particleLocation.getBlockY(),
            particleLocation.getBlockZ(),
            0.0f,
            0.0f,
            0.0f,
            2,
            2500,
            null);

    for (Player serverPlayer : player.getWorld().getPlayers())
      ((CraftPlayer) serverPlayer).getHandle().playerConnection.sendPacket(packet);

    commonString.messageSend(RocketInit.getPlugin(), player, true, RocketLanguage.RB_FZ_SUCCESS);
  }
Ejemplo n.º 27
0
  /**
   * <b>Method: </b>destinations</br> <b>Usage: </b>{@code piece.destinations()}</br>
   * -------------------------------</br> Pawns can choose one of following moves: </br>
   *
   * <ul>
   *   <li>One step forward - any circumstance
   *   <li>Two steps forward - has not been moved
   *   <li>One step diagonal - enemy Piece at diagonal location
   * </ul>
   *
   * @return iterator to set of possible destinations
   */
  public Iterator<Location> destinations() {
    Set<Location> set = new TreeSet<Location>();
    Location current = getLocation();

    // pawns can always move 1 step ahead
    Location oneAhead = current.getAdjacentLocation(getDirection() + Location.AHEAD);
    if (this.isValidDestination(oneAhead)) set.add(oneAhead);

    // if 2nd row from top or from bottom and two steps ahead is valid
    int row = getLocation().getRow();
    Location twoAhead = oneAhead.getAdjacentLocation(getDirection());
    if (this.isValidDestination(oneAhead) && !wasMoved() && this.isValidDestination(twoAhead))
      set.add(twoAhead);

    for (int dir = -45; dir <= 45; dir += 90) {
      Location diagonal = current.getAdjacentLocation(getDirection() + dir);
      if (isValidAttack(diagonal)) set.add(diagonal);
    }

    return set.iterator();
  }
Ejemplo n.º 28
0
    public int compareTo(Object other) {
      int thisLoc = mStart.getLocation();
      int thatLoc = ((Entry) other).mStart.getLocation();

      if (thisLoc < thatLoc) {
        return -1;
      } else if (thisLoc > thatLoc) {
        return 1;
      } else {
        return 0;
      }
    }
Ejemplo n.º 29
0
 public void testLocation() throws Exception {
   JSONArray array = getJSONArrayFromClassPath("/dao/trends-available.json");
   ResponseList<Location> locations =
       LocationJSONImpl.createLocationList(array, conf.isJSONStoreEnabled());
   Assert.assertEquals(23, locations.size());
   Location location = locations.get(0);
   Assert.assertEquals("GB", location.getCountryCode());
   Assert.assertEquals("United Kingdom", location.getCountryName());
   Assert.assertEquals("United Kingdom", location.getName());
   Assert.assertEquals(12, location.getPlaceCode());
   Assert.assertEquals("Country", location.getPlaceName());
   Assert.assertEquals("http://where.yahooapis.com/v1/place/23424975", location.getURL());
   Assert.assertEquals(23424975, location.getWoeid());
 }
Ejemplo n.º 30
0
 public void setProperty(final String path, final Location loc) {
   set((path == null ? "" : path + ".") + "world", loc.getWorld().getName());
   set((path == null ? "" : path + ".") + "x", loc.getX());
   set((path == null ? "" : path + ".") + "y", loc.getY());
   set((path == null ? "" : path + ".") + "z", loc.getZ());
   set((path == null ? "" : path + ".") + "yaw", loc.getYaw());
   set((path == null ? "" : path + ".") + "pitch", loc.getPitch());
 }