Search in sources :

Example 86 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class PushableTrait method NPCCompleteDestination.

// <--[action]
// @Actions
// push return
//
// @Triggers when the NPC returns to its center after being pushed by a player.
//
// @Context
// None
//
// -->
/**
     * Fires a 'On Push Return:' action upon return after being pushed.
     */
@EventHandler
public void NPCCompleteDestination(NavigationCompleteEvent event) {
    if (event.getNPC() == npc && pushed) {
        Entity npcEntity = npc.getEntity();
        Location location = npcEntity.getLocation();
        location.setYaw(returnLocation.getYaw());
        location.setPitch(returnLocation.getPitch());
        NMS.setHeadYaw(npcEntity, returnLocation.getYaw());
        pushed = false;
        // Push Return action
        DenizenAPI.getDenizenNPC(npc).action("push return", null);
    }
}
Also used : Entity(org.bukkit.entity.Entity) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 87 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class dChunk method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <ch@chunk.add[<#>,<#>]>
    // @returns dChunk
    // @description
    // Returns the chunk with the specified coordinates added to it.
    // -->
    registerTag("add", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            if (!attribute.hasContext(1)) {
                dB.echoError("The tag ch@chunk.add[<#>,<#>] must have a value.");
                return null;
            }
            List<String> coords = CoreUtilities.split(attribute.getContext(1), ',');
            if (coords.size() < 2) {
                dB.echoError("The tag ch@chunk.add[<#>,<#>] requires two values!");
                return null;
            }
            double x = aH.getDoubleFrom(coords.get(0)) * 16;
            double z = aH.getDoubleFrom(coords.get(1)) * 16;
            return new dChunk(((dChunk) object).getCenter().clone().add(x, 0, z).getChunk()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.sub[<#>,<#>]>
    // @returns dChunk
    // @description
    // Returns the chunk with the specified coordinates subtracted from it.
    // -->
    registerTag("sub", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            if (!attribute.hasContext(1)) {
                dB.echoError("The tag ch@chunk.add[<#>,<#>] must have a value.");
                return null;
            }
            List<String> coords = CoreUtilities.split(attribute.getContext(1), ',');
            if (coords.size() < 2) {
                dB.echoError("The tag ch@chunk.sub[<#>,<#>] requires two values!");
                return null;
            }
            double x = aH.getDoubleFrom(coords.get(0)) * 16;
            double z = aH.getDoubleFrom(coords.get(1)) * 16;
            return new dChunk(((dChunk) object).getCenter().clone().subtract(x, 0, z).getChunk()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.is_loaded>
    // @returns Element(Boolean)
    // @description
    // Returns true if the chunk is currently loaded into memory.
    // -->
    registerTag("is_loaded", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dChunk) object).chunk.isLoaded()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.x>
    // @returns Element(Number)
    // @description
    // Returns the x coordinate of the chunk.
    // -->
    registerTag("x", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dChunk) object).chunk.getX()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.z>
    // @returns Element(Number)
    // @description
    // Returns the z coordinate of the chunk.
    // -->
    registerTag("z", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dChunk) object).chunk.getZ()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.world>
    // @returns dWorld
    // @description
    // Returns the world associated with the chunk.
    // -->
    registerTag("world", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return dWorld.mirrorBukkitWorld(((dChunk) object).chunk.getWorld()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.cuboid>
    // @returns dCuboid
    // @description
    // Returns a cuboid of this chunk.
    // -->
    registerTag("cuboid", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dChunk chunk = (dChunk) object;
            return new dCuboid(new Location(chunk.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16), new Location(chunk.getWorld(), chunk.getX() * 16 + 15, 255, chunk.getZ() * 16 + 15)).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.entities>
    // @returns dList(dEntity)
    // @description
    // Returns a list of entities in the chunk.
    // -->
    registerTag("entities", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dList entities = new dList();
            for (Entity ent : ((dChunk) object).chunk.getEntities()) {
                entities.add(new dEntity(ent).identify());
            }
            return entities.getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.living_entities>
    // @returns dList(dEntity)
    // @description
    // Returns a list of living entities in the chunk. This includes Players, mobs, NPCs, etc., but excludes
    // dropped items, experience orbs, etc.
    // -->
    registerTag("living_entities", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dList entities = new dList();
            for (Entity ent : ((dChunk) object).chunk.getEntities()) {
                if (ent instanceof LivingEntity) {
                    entities.add(new dEntity(ent).identify());
                }
            }
            return entities.getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.players>
    // @returns dList(dPlayer)
    // @description
    // Returns a list of players in the chunk.
    // -->
    registerTag("players", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dList entities = new dList();
            for (Entity ent : ((dChunk) object).chunk.getEntities()) {
                if (dEntity.isPlayer(ent)) {
                    entities.add(new dEntity(ent).identify());
                }
            }
            return entities.getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.height_map>
    // @returns dList(Element)
    // @description
    // Returns a list of the height of each block in the chunk.
    // -->
    registerTag("height_map", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            int[] heightMap = ((dChunk) object).getHeightMap();
            List<String> height_map = new ArrayList<String>(heightMap.length);
            for (int i : heightMap) {
                height_map.add(String.valueOf(i));
            }
            return new dList(height_map).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.average_height>
    // @returns Element(Decimal)
    // @description
    // Returns the average height of the blocks in the chunk.
    // -->
    registerTag("average_height", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            int sum = 0;
            int[] heightMap = ((dChunk) object).getHeightMap();
            for (int i : heightMap) {
                sum += i;
            }
            return new Element(((double) sum) / heightMap.length).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.is_flat[#]>
    // @returns Element(Boolean)
    // @description
    // scans the heights of the blocks to check variance between them. If no number is supplied, is_flat will return
    // true if all the blocks are less than 2 blocks apart in height. Specifying a number will modify the number
    // criteria for determining if it is flat.
    // -->
    registerTag("is_flat", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            int tolerance = attribute.hasContext(1) && aH.matchesInteger(attribute.getContext(1)) ? Integer.valueOf(attribute.getContext(1)) : 2;
            int[] heightMap = ((dChunk) object).getHeightMap();
            int x = heightMap[0];
            for (int i : heightMap) {
                if (Math.abs(x - i) > tolerance) {
                    return Element.FALSE.getAttribute(attribute.fulfill(1));
                }
            }
            return Element.TRUE.getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.surface_blocks>
    // @returns dList(dLocation)
    // @description
    // Returns a list of the highest non-air surface blocks in the chunk.
    // -->
    registerTag("surface_blocks", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dList surface_blocks = new dList();
            for (int x = 0; x < 16; x++) {
                for (int z = 0; z < 16; z++) {
                    surface_blocks.add(new dLocation(((dChunk) object).chunk.getBlock(x, ((dChunk) object).getSnapshot().getHighestBlockYAt(x, z) - 1, z).getLocation()).identify());
                }
            }
            return surface_blocks.getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.spawn_slimes>
    // @returns dList(dLocation)
    // @description
    // Returns whether the chunk is a specially located 'slime spawner' chunk.
    // -->
    registerTag("spawn_slimes", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dChunk chunk = (dChunk) object;
            Random random = new Random(chunk.getWorld().getSeed() + chunk.getX() * chunk.getX() * 4987142 + chunk.getX() * 5947611 + chunk.getZ() * chunk.getZ() * 4392871L + chunk.getZ() * 389711 ^ 0x3AD8025F);
            return new Element(random.nextInt(10) == 0).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.type>
    // @returns Element
    // @description
    // Always returns 'Chunk' for dChunk objects. All objects fetchable by the Object Fetcher will return the
    // type of object that is fulfilling this attribute.
    // -->
    registerTag("type", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element("Chunk").getAttribute(attribute.fulfill(1));
        }
    });
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Attribute(net.aufdemrand.denizencore.tags.Attribute) LivingEntity(org.bukkit.entity.LivingEntity) Location(org.bukkit.Location)

Example 88 with Location

use of org.bukkit.Location in project Bukkit by Bukkit.

the class PlaySoundCommand method execute.

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) {
        return true;
    }
    if (args.length < 2) {
        sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
        return false;
    }
    final String soundArg = args[0];
    final String playerArg = args[1];
    final Player player = Bukkit.getPlayerExact(playerArg);
    if (player == null) {
        sender.sendMessage(ChatColor.RED + "Can't find player " + playerArg);
        return false;
    }
    final Location location = player.getLocation();
    double x = Math.floor(location.getX());
    double y = Math.floor(location.getY() + 0.5D);
    double z = Math.floor(location.getZ());
    double volume = 1.0D;
    double pitch = 1.0D;
    double minimumVolume = 0.0D;
    switch(args.length) {
        default:
        case 8:
            minimumVolume = getDouble(sender, args[7], 0.0D, 1.0D);
        case 7:
            pitch = getDouble(sender, args[6], 0.0D, 2.0D);
        case 6:
            volume = getDouble(sender, args[5], 0.0D, Float.MAX_VALUE);
        case 5:
            z = getRelativeDouble(z, sender, args[4]);
        case 4:
            y = getRelativeDouble(y, sender, args[3]);
        case 3:
            x = getRelativeDouble(x, sender, args[2]);
        case 2:
    }
    final double fixedVolume = volume > 1.0D ? volume * 16.0D : 16.0D;
    final Location soundLocation = new Location(player.getWorld(), x, y, z);
    if (location.distanceSquared(soundLocation) > fixedVolume * fixedVolume) {
        if (minimumVolume <= 0.0D) {
            sender.sendMessage(ChatColor.RED + playerArg + " is too far away to hear the sound");
            return false;
        }
        final double deltaX = x - location.getX();
        final double deltaY = y - location.getY();
        final double deltaZ = z - location.getZ();
        final double delta = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / 2.0D;
        if (delta > 0.0D) {
            location.add(deltaX / delta, deltaY / delta, deltaZ / delta);
        }
        player.playSound(location, soundArg, (float) minimumVolume, (float) pitch);
    } else {
        player.playSound(soundLocation, soundArg, (float) volume, (float) pitch);
    }
    sender.sendMessage(String.format("Played '%s' to %s", soundArg, playerArg));
    return true;
}
Also used : Player(org.bukkit.entity.Player) Location(org.bukkit.Location)

Example 89 with Location

use of org.bukkit.Location in project Bukkit by Bukkit.

the class SpreadPlayersCommand method spread.

private double spread(World world, List<Player> list, Location[] locations, boolean teams) {
    double distance = 0.0D;
    int i = 0;
    Map<Team, Location> hashmap = Maps.newHashMap();
    for (int j = 0; j < list.size(); ++j) {
        Player player = list.get(j);
        Location location;
        if (teams) {
            Team team = player.getScoreboard().getPlayerTeam(player);
            if (!hashmap.containsKey(team)) {
                hashmap.put(team, locations[i++]);
            }
            location = hashmap.get(team);
        } else {
            location = locations[i++];
        }
        player.teleport(new Location(world, Math.floor(location.getX()) + 0.5D, world.getHighestBlockYAt((int) location.getX(), (int) location.getZ()), Math.floor(location.getZ()) + 0.5D));
        double value = Double.MAX_VALUE;
        for (int k = 0; k < locations.length; ++k) {
            if (location != locations[k]) {
                double d = location.distanceSquared(locations[k]);
                value = Math.min(d, value);
            }
        }
        distance += value;
    }
    distance /= list.size();
    return distance;
}
Also used : Player(org.bukkit.entity.Player) Team(org.bukkit.scoreboard.Team) Location(org.bukkit.Location)

Example 90 with Location

use of org.bukkit.Location in project xAuth by CypherX.

the class xAuthPlayerListener method onPlayerMove.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
    xAuthPlayer p = plyrMngr.getPlayer(event.getPlayer());
    if (plyrMngr.isRestricted(p, event)) {
        World w = p.getPlayer().getWorld();
        Location loc = plugin.getConfig().getBoolean("guest.protect-location") ? plugin.getLocMngr().getLocation(w) : p.getPlayerData().getLocation();
        Location testLoc = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ());
        while ((w.getBlockAt(testLoc).isEmpty() || w.getBlockAt(testLoc).isLiquid()) && testLoc.getY() >= 0) testLoc.setY((int) testLoc.getY() - 1);
        if (testLoc.getY() > 0)
            loc.setY(testLoc.getY() + 1);
        event.setTo(loc);
        plyrMngr.sendNotice(p);
    }
}
Also used : com.cypherx.xauth.xAuthPlayer(com.cypherx.xauth.xAuthPlayer) World(org.bukkit.World) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

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