Search in sources :

Example 6 with Location

use of org.bukkit.Location in project Prism-Bukkit by prism.

the class Preview method moveEntitiesToSafety.

/**
	 * 
	 */
protected void moveEntitiesToSafety() {
    if (parameters.getWorld() != null && player != null) {
        final List<Entity> entities = player.getNearbyEntities(parameters.getRadius(), parameters.getRadius(), parameters.getRadius());
        entities.add(player);
        for (final Entity entity : entities) {
            if (entity instanceof LivingEntity) {
                int add = 0;
                if (EntityUtils.inCube(parameters.getPlayerLocation(), parameters.getRadius(), entity.getLocation())) {
                    final Location l = entity.getLocation();
                    while (!EntityUtils.playerMayPassThrough(l.getBlock().getType())) {
                        add++;
                        if (l.getY() >= 256)
                            break;
                        l.setY(l.getY() + 1);
                    }
                    if (add > 0) {
                        entities_moved.put(entity, add);
                        entity.teleport(l);
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Location(org.bukkit.Location)

Example 7 with Location

use of org.bukkit.Location in project Prism-Bukkit by prism.

the class PrismWorldEditLogger method onBlockChange.

@Override
protected void onBlockChange(Vector pt, BaseBlock newBlock) {
    if (!Prism.config.getBoolean("prism.tracking.world-edit"))
        return;
    BaseBlock oldBlock = getBlock(pt);
    Location loc = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
    RecordingQueue.addToQueue(ActionFactory.createBlockChange("world-edit", loc, oldBlock.getId(), (byte) oldBlock.getData(), newBlock.getId(), (byte) newBlock.getData(), player.getName()));
}
Also used : BaseBlock(com.sk89q.worldedit.blocks.BaseBlock) Location(org.bukkit.Location)

Example 8 with Location

use of org.bukkit.Location in project Prism-Bukkit by prism.

the class BlockUtils method removeMaterialsFromRadius.

/**
     * 
     * @param materials
     * @param loc
     * @param radius
     */
public static ArrayList<BlockStateChange> removeMaterialsFromRadius(Material[] materials, Location loc, int radius) {
    final ArrayList<BlockStateChange> blockStateChanges = new ArrayList<BlockStateChange>();
    if (loc != null && radius > 0 && materials != null && materials.length > 0) {
        final int x1 = loc.getBlockX();
        final int y1 = loc.getBlockY();
        final int z1 = loc.getBlockZ();
        final World world = loc.getWorld();
        for (int x = x1 - radius; x <= x1 + radius; x++) {
            for (int y = y1 - radius; y <= y1 + radius; y++) {
                for (int z = z1 - radius; z <= z1 + radius; z++) {
                    loc = new Location(world, x, y, z);
                    final Block b = loc.getBlock();
                    if (b.getType().equals(Material.AIR))
                        continue;
                    if (Arrays.asList(materials).contains(loc.getBlock().getType())) {
                        final BlockState originalBlock = loc.getBlock().getState();
                        loc.getBlock().setType(Material.AIR);
                        final BlockState newBlock = loc.getBlock().getState();
                        blockStateChanges.add(new BlockStateChange(originalBlock, newBlock));
                    }
                }
            }
        }
    }
    return blockStateChanges;
}
Also used : BlockStateChange(me.botsko.prism.events.BlockStateChange) BlockState(org.bukkit.block.BlockState) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) World(org.bukkit.World) Location(org.bukkit.Location)

Example 9 with Location

use of org.bukkit.Location in project Prism-Bukkit by prism.

the class PrismInventoryEvents method onInventoryClick.

/**
     * Handle inventory transfers
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent event) {
    if (!plugin.getConfig().getBoolean("prism.tracking.item-insert") && !plugin.getConfig().getBoolean("prism.tracking.item-remove"))
        return;
    Location containerLoc = null;
    // Store some info
    final Player player = (Player) event.getWhoClicked();
    final ItemStack currentitem = event.getCurrentItem();
    final ItemStack cursoritem = event.getCursor();
    // Get location
    if (event.getInventory().getHolder() instanceof BlockState) {
        final BlockState b = (BlockState) event.getInventory().getHolder();
        containerLoc = b.getLocation();
    } else if (event.getInventory().getHolder() instanceof Entity) {
        final Entity e = (Entity) event.getInventory().getHolder();
        containerLoc = e.getLocation();
    } else if (event.getInventory().getHolder() instanceof DoubleChest) {
        final DoubleChest chest = (DoubleChest) event.getInventory().getHolder();
        containerLoc = chest.getLocation();
    }
    // Double chests report 27 default size, though they actually
    // have 6 rows of 9 for 54 slots
    int defaultSize = event.getView().getType().getDefaultSize();
    if (event.getInventory().getHolder() instanceof DoubleChest) {
        defaultSize = event.getView().getType().getDefaultSize() * 2;
    }
    // slot count of the inventory. At that point, they represent the player inv.
    if (event.getSlot() == event.getRawSlot() && event.getRawSlot() <= defaultSize) {
        ItemStack addStack = null;
        ItemStack removeStack = null;
        if (currentitem != null && !currentitem.getType().equals(Material.AIR) && cursoritem != null && !cursoritem.getType().equals(Material.AIR)) {
            if (currentitem.isSimilar(cursoritem)) {
                // Items are similar enough to stack
                int amount = cursoritem.getAmount();
                if (event.isRightClick()) {
                    amount = 1;
                }
                int remaining = (currentitem.getMaxStackSize() - currentitem.getAmount());
                int inserted = (amount <= remaining) ? amount : remaining;
                if (inserted > 0) {
                    addStack = cursoritem.clone();
                    addStack.setAmount(inserted);
                }
            } else {
                // Items are not similar
                addStack = cursoritem.clone();
                removeStack = currentitem.clone();
            }
        } else if (currentitem != null && !currentitem.getType().equals(Material.AIR)) {
            removeStack = currentitem.clone();
        } else if (cursoritem != null && !cursoritem.getType().equals(Material.AIR)) {
            addStack = cursoritem.clone();
        }
        // Record events
        if (addStack != null) {
            recordInvAction(player, containerLoc, addStack, event.getRawSlot(), "item-insert", event);
        }
        if (removeStack != null) {
            recordInvAction(player, containerLoc, removeStack, event.getRawSlot(), "item-remove", event);
        }
        return;
    }
    if (event.isShiftClick() && cursoritem != null && cursoritem.getType().equals(Material.AIR)) {
        recordInvAction(player, containerLoc, currentitem, -1, "item-insert", event);
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) BlockState(org.bukkit.block.BlockState) ItemStack(org.bukkit.inventory.ItemStack) DoubleChest(org.bukkit.block.DoubleChest) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 10 with Location

use of org.bukkit.Location in project Prism-Bukkit by prism.

the class PrismInventoryMoveItemEvent method onInventoryMoveItem.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryMoveItem(final InventoryMoveItemEvent event) {
    // Hopper inserted
    if (Prism.getIgnore().event("item-insert") && event.getDestination() != null) {
        // Get container
        final InventoryHolder ih = event.getDestination().getHolder();
        Location containerLoc = null;
        if (ih instanceof BlockState) {
            final BlockState eventChest = (BlockState) ih;
            containerLoc = eventChest.getLocation();
        }
        if (containerLoc == null)
            return;
        if (event.getSource().getType().equals(InventoryType.HOPPER)) {
            RecordingQueue.addToQueue(ActionFactory.createItemStack("item-insert", event.getItem(), event.getItem().getAmount(), 0, null, containerLoc, "hopper"));
        }
    }
    // Hopper removed
    if (Prism.getIgnore().event("item-remove") && event.getSource() != null) {
        // Get container
        final InventoryHolder ih = event.getSource().getHolder();
        Location containerLoc = null;
        if (ih instanceof BlockState) {
            final BlockState eventChest = (BlockState) ih;
            containerLoc = eventChest.getLocation();
        }
        if (containerLoc == null)
            return;
        if (event.getDestination().getType().equals(InventoryType.HOPPER)) {
            RecordingQueue.addToQueue(ActionFactory.createItemStack("item-remove", event.getItem(), event.getItem().getAmount(), 0, null, containerLoc, "hopper"));
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) InventoryHolder(org.bukkit.inventory.InventoryHolder) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Location (org.bukkit.Location)351 Player (org.bukkit.entity.Player)90 World (org.bukkit.World)56 EventHandler (org.bukkit.event.EventHandler)43 Test (org.junit.Test)43 Vector (org.bukkit.util.Vector)38 ArrayList (java.util.ArrayList)29 Block (org.bukkit.block.Block)18 Entity (org.bukkit.entity.Entity)17 User (com.earth2me.essentials.User)16 ItemStack (org.bukkit.inventory.ItemStack)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 List (java.util.List)12 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)11 BlockState (org.bukkit.block.BlockState)11 UUID (java.util.UUID)10 LivingEntity (org.bukkit.entity.LivingEntity)10 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)9