/** * Returns the current block along the line of vision * * @return block position */ public Location getCurrentBlock() { if (curDistance > maxDistance) { return null; } else { return targetPos.toLocation(world); } }
/** * Set the location of the item and put it on the right place on the block * * @param location The location of the item/shop block */ private void setLocation(Location location) { this.location = location.getBlock().getLocation(); // simply clear everything after the comma. Vector vec = this.location.toVector(); vec.add(new Vector(0.5, 0.6, 0.5)); this.location = vec.toLocation(this.location.getWorld()); if (getItem() != null) { getItem().teleport(this.location); } }
/** * Find a suitable location for a player to teleport to in the given world. This method uses * WorldBorder as the configuration source. * * @param world World to teleport to * @return Location to teleport to */ private Location findSuitableLocationWB(World world) { BorderData borderData = WorldBorder.plugin.GetWorldBorder(world.getName()); if (borderData == null) { // throw new IllegalStateException(String.format("World %1$s isn't configured in // WorldBorder.", world.getName())); return null; } for (int i = 0; i < 100; i++) { Vector position = new Vector(borderData.getX(), 0.0, borderData.getZ()); // Get a uniform-area random position within the world border's geometry boolean isRound = (borderData.getShape() == null) ? true : borderData.getShape(); if (isRound) { position.add( getRandomPointInEllipse(random, borderData.getRadiusX(), borderData.getRadiusZ())); } else { position.add( getRandomPointInRectangle(random, borderData.getRadiusX(), borderData.getRadiusZ())); } // Ensure there's a solid block to stand on Block highestBlock = world.getHighestBlockAt(position.getBlockX(), position.getBlockZ()); if (highestBlock == null) continue; highestBlock = highestBlock.getRelative(0, -1, 0); // Because the javadocs are wrong. if (highestBlock == null) continue; if (highestBlock.getY() < 1 || highestBlock.getY() >= world.getMaxHeight() - 2) continue; if (highestBlock.isLiquid()) continue; position.setX((double) position.getBlockX() + 0.5); position.setY(highestBlock.getY() + 2); position.setZ((double) position.getBlockZ() + 0.5); return position.toLocation(world, getRandomYaw(), 0.0f); } return null; }
/** * Returns the previous block in the aimed path * * @return block position */ public Location getPreviousBlock() { return prevPos.toLocation(world); }