Search in sources :

Example 71 with Location

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;
}
Also used : Location(org.bukkit.Location)

Example 72 with Location

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);
}
Also used : net.aufdemrand.denizen.objects.dCuboid(net.aufdemrand.denizen.objects.dCuboid) Location(org.bukkit.Location)

Example 73 with Location

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();
    }
}
Also used : Player(org.bukkit.entity.Player) CommandException(net.aufdemrand.denizen.utilities.command.exceptions.CommandException) World(org.bukkit.World) Location(org.bukkit.Location)

Example 74 with Location

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()));
}
Also used : ArrayList(java.util.ArrayList) Location(org.bukkit.Location)

Example 75 with Location

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;
}
Also used : net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) TriggerTrait(net.aufdemrand.denizen.npc.traits.TriggerTrait) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)470 Player (org.bukkit.entity.Player)120 World (org.bukkit.World)63 EventHandler (org.bukkit.event.EventHandler)54 Vector (org.bukkit.util.Vector)45 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)36 Block (org.bukkit.block.Block)31 Entity (org.bukkit.entity.Entity)28 UUID (java.util.UUID)27 ItemStack (org.bukkit.inventory.ItemStack)22 LivingEntity (org.bukkit.entity.LivingEntity)20 PotionEffect (org.bukkit.potion.PotionEffect)17 User (com.earth2me.essentials.User)16 List (java.util.List)16 IOException (java.io.IOException)15 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)14 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)14 Island (com.wasteofplastic.acidisland.Island)12