use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.
the class ProximityTrigger method isCloseEnough.
/**
* Checks if the Player in Proximity is close enough to be calculated.
*
* @param player the Player
* @param npc the NPC
* @return true if within maxProximityDistance in all directions
*/
private boolean isCloseEnough(Player player, dNPC npc) {
Location pLoc = player.getLocation();
Location nLoc = npc.getLocation();
if (Math.abs(pLoc.getX() - nLoc.getX()) > maxProximityDistance) {
return false;
}
if (Math.abs(pLoc.getY() - nLoc.getY()) > maxProximityDistance) {
return false;
}
if (Math.abs(pLoc.getZ() - nLoc.getZ()) > maxProximityDistance) {
return false;
}
return true;
}
use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.
the class CuboidBlockSet method getCuboid.
public dCuboid getCuboid(Location loc) {
Location low = loc.clone().subtract(center_x, center_y, center_z);
Location high = low.clone().add(x_width, y_length, z_height);
return new dCuboid(low, high);
}
use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.
the class CommandContext method parseLocation.
public static Location parseLocation(Location currentLocation, String flag) throws CommandException {
boolean denizen = flag.startsWith("l@");
String[] parts = flag.replaceFirst("l@", "").split("[,]|[:]");
if (parts.length > 0) {
String worldName = currentLocation != null ? currentLocation.getWorld().getName() : "";
double x = 0, y = 0, z = 0;
float yaw = 0F, pitch = 0F;
switch(parts.length) {
case 6:
if (denizen) {
worldName = parts[5].replaceFirst("w@", "");
} else {
pitch = Float.parseFloat(parts[5]);
}
case 5:
if (denizen) {
pitch = Float.parseFloat(parts[4]);
} else {
yaw = Float.parseFloat(parts[4]);
}
case 4:
if (denizen && parts.length > 4) {
yaw = Float.parseFloat(parts[3]);
} else {
worldName = parts[3].replaceFirst("w@", "");
}
case 3:
x = Double.parseDouble(parts[0]);
y = Double.parseDouble(parts[1]);
z = Double.parseDouble(parts[2]);
break;
default:
throw new CommandException("Location could not be parsed or was not found.");
}
World world = Bukkit.getWorld(worldName);
if (world == null) {
throw new CommandException("Location could not be parsed or was not found.");
}
return new Location(world, x, y, z, yaw, pitch);
} else {
Player search = Bukkit.getPlayerExact(flag);
if (search == null) {
throw new CommandException("No player could be found by that name.");
}
return search.getLocation();
}
}
use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.
the class Utilities method getWalkableLocationNear.
/**
* Gets a Location within a range that an entity can walk in.
*
* @param location the Location to check with
* @param range the range around the Location
* @return a random Location within range, or null if no Location within range is safe
*/
public static Location getWalkableLocationNear(Location location, int range) {
List<Location> locations = new ArrayList<Location>();
location = location.getBlock().getLocation();
// Loop through each location within the range
for (double x = -(range); x <= range; x++) {
for (double y = -(range); y <= range; y++) {
for (double z = -(range); z <= range; z++) {
// Add each block location within range
Location loc = location.clone().add(x, y, z);
if (checkLocation(location, loc, range) && isWalkable(loc)) {
locations.add(loc);
}
}
}
}
// No safe Locations found
if (locations.isEmpty()) {
return null;
}
// Return a random Location from the list
return locations.get(CoreUtilities.getRandom().nextInt(locations.size()));
}
use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.
the class Utilities method getClosestNPC_ChatTrigger.
/**
* Finds the closest NPC to a particular location.
*
* @param location The location to find the closest NPC to.
* @param range The maximum range to look for the NPC.
* @return The closest NPC to the location, or null if no NPC was found
* within the range specified.
*/
public static dNPC getClosestNPC_ChatTrigger(Location location, int range) {
dNPC closestNPC = null;
double closestDistance = Math.pow(range, 2);
// TODO: Why is this manually iterating?
Iterator<dNPC> it = DenizenAPI.getSpawnedNPCs().iterator();
while (it.hasNext()) {
dNPC npc = it.next();
Location loc = npc.getLocation();
if (npc.getCitizen().hasTrait(TriggerTrait.class) && npc.getTriggerTrait().hasTrigger("CHAT") && loc.getWorld().equals(location.getWorld()) && loc.distanceSquared(location) < closestDistance) {
closestNPC = npc;
closestDistance = npc.getLocation().distanceSquared(location);
}
}
return closestNPC;
}
Aggregations