Java 类org.bukkit.block.Chest 实例源码

项目:ProjectAres    文件:FillListener.java   
/**
 * Return a predicate that applies a Filter to the given InventoryHolder,
 * or null if the InventoryHolder is not something that we should be filling.
 */
private static @Nullable Predicate<Filter> passesFilter(InventoryHolder holder) {
    if(holder instanceof DoubleChest) {
        final DoubleChest doubleChest = (DoubleChest) holder;
        return filter -> !filter.denies((Chest) doubleChest.getLeftSide()) ||
                         !filter.denies((Chest) doubleChest.getRightSide());
    } else if(holder instanceof BlockState) {
        return filter -> !filter.denies((BlockState) holder);
    } else if(holder instanceof Player) {
        // This happens with crafting inventories, and possibly other transient inventory types
        // Pretty sure we never want to fill an inventory held by the player
        return null;
    } else if(holder instanceof Entity) {
        return filter -> !filter.denies(new EntityQuery((Entity) holder));
    } else {
        // If we're not sure what it is, don't fill it
        return null;
    }
}
项目:MT_Core    文件:SupplyDropManager.java   
public void deliverSupplyDrop(World world) {
    Random r = new Random();

    // Supply drops between -500, + 500
    double x = r.nextInt(1000) - 500;
    double y = 0.0D;
    double z = r.nextInt(1000) - 500;

    Location dropLocation = new Location(world, x, y, z);

    // Get the highest block at that location.
    dropLocation.setY(world.getHighestBlockYAt(dropLocation));

    dropLocation.getBlock().setType(Material.CHEST);
    Chest dropChest = (Chest) dropLocation.getBlock().getState();

    SupplyDropObject supplyDrop = new SupplyDropObject(dropLocation, dropChest, dropChest.getInventory());
    addSupplyDrop(supplyDrop);

    for (Player p : world.getPlayers()) {
        p.sendMessage(MortuusTerraCore.ALERT_PREFIX + StringUtilities
                .color("&eSupply Drop spotted at: &6" + x + ", " + dropLocation.getY() + ", " + z + "&e!"));
    }
}
项目:McLink    文件:ActionBind.java   
@EventHandler
public void onInventoryMoveItem(InventoryInteractEvent event) {
    //System.out.println("E");

    if (openchests.containsKey(event.getInventory())) {
        System.out.println("move");
        openchests.get(event.getInventory()).getInventory().setContents(event.getInventory().getContents());
        openchests.remove(event.getInventory());
    } else {
        for (int i = 0; i < openchests.size(); i++) {
            Chest c = ((List<Chest>) openchests.values()).get(i);
            if (c.getInventory().equals(event.getInventory())) {
                ((List<Inventory>) openchests.keySet()).get(i).setContents(event.getInventory().getContents());
            }
        }
    }
}
项目:OMGPI    文件:BukkitEventHandler.java   
@EventHandler
public void event(BlockBreakEvent e) {
    new OMGBreakEvent(e, get(e.getPlayer()), e.getBlock());
    if (Area.registeredAreas.values().stream().anyMatch(a -> a.isInside(e.getBlock().getLocation())) && Area.registeredAreas.values().stream().noneMatch(a -> a.isInside(e.getBlock().getLocation()) && a.isBreakAllowed(get(e.getPlayer()).team, e.getBlock().getType()))) {
        e.setCancelled(true);
        return;
    }
    if (g.settings.isLootingOn && e.getBlock().getType() == Material.CHEST) {
        e.setCancelled(true);
        Inventory inv = ((Chest) e.getBlock().getState()).getBlockInventory();
        String lootid = inv.getTitle() == null ? "" : inv.getTitle();
        OMGLoot.LootParser lp = g.loot_contents(get(e.getPlayer()), lootid);
        if (lp != null) {
            inv.clear();
            for (int i = 0; i < inv.getSize(); i++) {
                ItemStack ii = lp.getRandom().toItem();
                if (ii != null && NBTParser.getTagCompound(ii).getByte("Undroppable") != 1)
                    e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), ii);
            }
        }
        e.getBlock().setType(Material.AIR);
        e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(Material.CHEST));
    }
    if (!GameArea.isBlockInside(e.getBlock())) e.setCancelled(true);
}
项目:OMGPI    文件:BukkitEventHandler.java   
@EventHandler
public void event(EntityExplodeEvent e) {
    e.blockList().removeIf(b -> Area.registeredAreas.values().stream().anyMatch(a -> a.isInside(b.getLocation())) && Area.registeredAreas.values().stream().filter(a -> a.isInside(b.getLocation())).noneMatch(a -> a.canExplode.contains(b.getType())));
    if (g.state == GameState.INGAME && g.settings.isLootingOn)
        e.blockList().removeIf(b -> {
            if (b.getType() == Material.CHEST) {
                Inventory inv = ((Chest) b.getState()).getBlockInventory();
                String lootid = inv.getTitle() == null ? "" : inv.getTitle();
                OMGLoot.LootParser lp = g.loot_contents(null, lootid);
                if (lp != null) {
                    inv.clear();
                    for (int i = 0; i < inv.getSize(); i++) {
                        ItemStack ii = lp.getRandom().toItem();
                        if (ii != null && NBTParser.getTagCompound(ii).getByte("Undroppable") != 1)
                            b.getWorld().dropItemNaturally(b.getLocation(), ii);
                    }
                }
                b.setType(Material.AIR);
                b.getWorld().dropItemNaturally(b.getLocation(), new ItemStack(Material.CHEST));
                return true;
            }
            return false;
        });
}
项目:BiteSkywars    文件:PlayerChestFilled.java   
@EventHandler
public void onPlayerOpenChest(PlayerInteractEvent event){
    if(event.getClickedBlock()  == null)return;
    Block clicked = event.getClickedBlock();
    Location blockClicked = event.getClickedBlock().getLocation();
    Player p = event.getPlayer();
    Arena a =  am.getArena(p);
    if(a == null)return;
    if(clicked.getState() instanceof Chest){
    Chest chest = (Chest)clicked.getState();
    if(!a.contains(blockClicked)){
        a.addChest(blockClicked);
        Skywars.getCC().populateChest(a, chest);
    }

    }


}
项目:factions-top    文件:WorthListener.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void checkWorth(InventoryOpenEvent event) {
    // Do nothing if a player did not open the inventory or if chest events
    // are disabled.
    if (!(event.getPlayer() instanceof Player) || plugin.getSettings().isDisableChestEvents()) {
        return;
    }

    Inventory inventory = event.getInventory();

    // Set all default worth values for this chest.
    if (inventory.getHolder() instanceof DoubleChest) {
        DoubleChest chest = (DoubleChest) inventory.getHolder();
        checkWorth((Chest) chest.getLeftSide());
        checkWorth((Chest) chest.getRightSide());
    }

    if (inventory.getHolder() instanceof Chest) {
        checkWorth((Chest) inventory.getHolder());
    }
}
项目:factions-top    文件:WorthListener.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void updateWorth(InventoryCloseEvent event) {
    // Do nothing if a player did not close the inventory or if chest
    // events are disabled.
    if (!(event.getPlayer() instanceof Player) || plugin.getSettings().isDisableChestEvents()) {
        return;
    }

    // Get cached values from when chest was opened and add the difference
    // to the worth manager.
    if (event.getInventory().getHolder() instanceof DoubleChest) {
        DoubleChest chest = (DoubleChest) event.getInventory().getHolder();
        updateWorth((Chest) chest.getLeftSide());
        updateWorth((Chest) chest.getRightSide());
    }

    if (event.getInventory().getHolder() instanceof Chest) {
        updateWorth((Chest) event.getInventory().getHolder());
    }
}
项目:CleanShop    文件:EventListener.java   
public void handleChestDestruction(Block b,List<Block> explodedBlocks)
  {
    Vector<ProtectedRegion> regions=ShopUtils.getRegions(b.getLocation());

if(regions!=null)
    for(ProtectedRegion p:regions)
    {
        if(p!=null&&ShopUtils.shopExists(p))
        {
            BlockFace side=getDoubleChestSide(b);

            if(side==null) //Single chest
            {
                ChestUtils.clearSingleChest((Chest)b.getState(),ShopUtils.getShop(p));
            }
            else //uuugggghhhh I have to deal with this freaking double chest
            {
                ChestUtils.dealWithThisFreakingDoubleChest((Chest)b.getState(),ShopUtils.getShop(p),side,explodedBlocks);
            }
        }
    }
  }
项目:CleanShop    文件:EventListener.java   
@EventHandler
public void onInventoryCloseEvent(InventoryCloseEvent event) {
    //long time=System.nanoTime();
    if(event.getInventory().getType()==InventoryType.CHEST&&CleanShop.shopScan)
    {
        Vector<ProtectedRegion> regions=null;
        if(event.getInventory().getHolder() instanceof Chest)
            regions=ShopUtils.getRegions(((Chest)event.getInventory().getHolder()).getLocation());
        if(event.getInventory().getHolder() instanceof DoubleChest)
            regions=ShopUtils.getRegions(((DoubleChest)event.getInventory().getHolder()).getLocation());
        if(regions!=null)
            for(ProtectedRegion p:regions)
            {
                if(p!=null)
                    if(ShopUtils.shopExists(p))
                    {
                        //plugin.calculateShopStock(plugin.getShop(p));
                        if(event.getInventory().getHolder() instanceof Chest)
                            ChestUtils.calculateChestStock((Chest)event.getInventory().getHolder(), ShopUtils.getShop(p));
                        else
                            ChestUtils.calculateChestStock((DoubleChest)event.getInventory().getHolder(), ShopUtils.getShop(p));
                        FileHandler.saveShops();
                    }
            }
    }
}
项目:ExilePearl    文件:PlayerListener.java   
/**
 * Updates the pearl holder
 * @param pearl The pearl to update
 * @param holder The pearl holder
 * @param event The event
 */
private void updatePearlHolder(ExilePearl pearl, InventoryHolder holder, Cancellable event) {

    if (holder instanceof Chest) {
        updatePearl(pearl, (Chest)holder);
    } else if (holder instanceof DoubleChest) {
        updatePearl(pearl, (Chest) ((DoubleChest) holder).getLeftSide());
    } else if (holder instanceof Furnace) {
        updatePearl(pearl, (Furnace) holder);
    } else if (holder instanceof Dispenser) {
        updatePearl(pearl, (Dispenser) holder);
    } else if (holder instanceof Dropper) {
        updatePearl(pearl, (Dropper) holder);
    } else if (holder instanceof Hopper) {
        updatePearl(pearl, (Hopper) holder);
    } else if (holder instanceof BrewingStand) {
        updatePearl(pearl, (BrewingStand) holder);
    } else if (holder instanceof Player) {
        updatePearl(pearl, (Player) holder);
    }else {
        event.setCancelled(true);
    }
}
项目:skyblock-interactive-minecraft    文件:CreateBonusIslandAction.java   
private void spawnChest(final Location l) {
    if (InteractivePlugin.INSTANCE != null) {
        Bukkit.getScheduler().runTaskLater(InteractivePlugin.INSTANCE, new Runnable() {
            @Override
            public void run() {
                Block block = l.getBlock();
                block.setType(Material.CHEST);
                Chest chest = (Chest)block.getState();
                Inventory inv = chest.getInventory();

                int amount = 3 + CreateBonusIslandAction.this.random.nextInt(6);

                for (int i = 0; i < amount; i++){
                    Material[] materials = Material.values();
                    Material material = materials[CreateBonusIslandAction.this.random.nextInt(materials.length)];

                    inv.addItem(new ItemStack(material, 1 + CreateBonusIslandAction.this.random.nextInt(3)));
                }
            }
        }, 1);
    }
}
项目:Mapper_2    文件:ClearchestCommand.java   
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        return true;
    }
    Player player = (Player) sender;
    if (player.getItemInHand().equals(Material.AIR)) {
        Util.sendmessage(player, "&cアイテムが見つかりません。");
        return true;
    }

    @SuppressWarnings("deprecation")
    Block block = player.getTargetBlock((HashSet<Byte>) null, 10);
    if (!(block.getType().equals(Material.CHEST)
            || block.getType().equals(Material.TRAPPED_CHEST))) {
        Util.sendmessage(player, "&cチェストが見つかりません。");
        return true;
    }

    Inventory inventory = ((Chest) block.getState()).getInventory();

    inventory.clear();
    Util.sendmessage(player, "&7インベントリ内のアイテムを削除しました。");
    return true;
}
项目:LuckyBlocksBukkit    文件:LuckyBlocksActionController.java   
public void MagicChest(BlockBreakEvent event){
    Location loc = event.getBlock().getLocation();
    World world = loc.getWorld();
    event.setCancelled(true);
    Block block = event.getBlock();
    block.setType(Material.CHEST);
    DirectionalContainer chestData = (DirectionalContainer) block.getState().getData();
    BlockFace directionInfo = new LuckyBlocksInvokeMethodClass().getCardinalDirection(event.getPlayer());
    chestData.setFacingDirection(directionInfo);
    //Next Line makes use of a Deprecated Method
    block.setData(chestData.getData(),true);
    Chest chest = (Chest) block.getState();
    world.playEffect(loc,Effect.ENDER_SIGNAL,50);
    int RandomSelection = (int) (Math.random()*100);
    if (RandomSelection < 50) {
        ItemStack goldenApples = new ItemStack(Material.GOLDEN_APPLE);
        goldenApples.setAmount(5);
        chest.getInventory().addItem(goldenApples);
    }
    else if (RandomSelection >= 50) isUnluckyChestActivated = 1;

}
项目:LuckyBlocksBukkit    文件:LuckyBlocksActionController.java   
public void MagicChest(BlockBreakEvent event){
    Location loc = event.getBlock().getLocation();
    World world = loc.getWorld();
    event.setCancelled(true);
    Block block = event.getBlock();
    block.setType(Material.CHEST);
    DirectionalContainer chestData = (DirectionalContainer) block.getState().getData();
    BlockFace directionInfo = new LuckyBlocksInvokeMethodClass().getCardinalDirection(event.getPlayer());
    chestData.setFacingDirection(directionInfo);
    //Next Line makes use of a Deprecated Method
    block.setData(chestData.getData(),true);
    Chest chest = (Chest) block.getState();
    world.playEffect(loc,Effect.ENDER_SIGNAL,50);
    int RandomSelection = (int) (Math.random()*100);
    if (RandomSelection < 50) {
        ItemStack goldenApples = new ItemStack(Material.GOLDEN_APPLE);
        goldenApples.setAmount(5);
        chest.getInventory().addItem(goldenApples);
    }
    else if (RandomSelection >= 50) isUnluckyChestActivated = 1;

}
项目:BiteSkywars    文件:PlayerChestFilled.java   
@EventHandler
public void onPlayerOpenChest(PlayerInteractEvent event){
    if(event.getClickedBlock()  == null)return;
    Block clicked = event.getClickedBlock();
    Location blockClicked = event.getClickedBlock().getLocation();
    Player p = event.getPlayer();
    Arena a =  am.getArena(p);
    if(a == null)return;
    if(clicked.getState() instanceof Chest){
    Chest chest = (Chest)clicked.getState();
    if(!a.contains(blockClicked)){
        a.addChest(blockClicked);
        Skywars.getCC().populateChest(a, chest);
    }

    }


}
项目:FastAsyncWorldedit    文件:BukkitWorld.java   
/**
 * Gets the single block inventory for a potentially double chest.
 * Handles people who have an old version of Bukkit.
 * This should be replaced with {@link org.bukkit.block.Chest#getBlockInventory()}
 * in a few months (now = March 2012) // note from future dev - lol
 *
 * @param chest The chest to get a single block inventory for
 * @return The chest's inventory
 */
private Inventory getBlockInventory(Chest chest) {
    try {
        return chest.getBlockInventory();
    } catch (Throwable t) {
        if (chest.getInventory() instanceof DoubleChestInventory) {
            DoubleChestInventory inven = (DoubleChestInventory) chest.getInventory();
            if (inven.getLeftSide().getHolder().equals(chest)) {
                return inven.getLeftSide();
            } else if (inven.getRightSide().getHolder().equals(chest)) {
                return inven.getRightSide();
            } else {
                return inven;
            }
        } else {
            return chest.getInventory();
        }
    }
}
项目:FastAsyncWorldedit    文件:BukkitWorld.java   
@Override
public boolean clearContainerBlockContents(Vector pt) {
    Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
    if (block == null) {
        return false;
    }
    BlockState state = block.getState();
    if (!(state instanceof org.bukkit.inventory.InventoryHolder)) {
        return false;
    }

    org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state;
    Inventory inven = chest.getInventory();
    if (chest instanceof Chest) {
        inven = getBlockInventory((Chest) chest);
    }
    inven.clear();
    return true;
}
项目:Gringotts-    文件:AccountChest.java   
/**
 * Connected chests that comprise the inventory of this account chest.
 * @return chest blocks connected to this chest, if any
 */
private Chest[] connectedChests() {
    Inventory inv = inventory();
    if (inv == null)
        return new Chest[0];

    if (inv instanceof DoubleChestInventory) {
        DoubleChestInventory dinv = (DoubleChestInventory)inv;
        Chest left = (Chest)(dinv.getLeftSide().getHolder());
        Chest right = (Chest)(dinv.getRightSide().getHolder());

        return new Chest[] {left, right};
    } else {
        InventoryHolder invHolder = inv.getHolder();
        if (invHolder instanceof Chest)
            return new Chest[] {(Chest)(inv.getHolder())};
    }

    return new Chest[0];
}
项目:Gringotts-    文件:AccountChest.java   
/**
 * Determine whether the chest of another AccountChest would be connected to this chest.
 * @param chest another AccountChest
 * @return whether the chest of another AccountChest would be connected to this chest
 */
public boolean connected(AccountChest chest) {

    // no valid account chest anymore -> no connection
    if (! updateValid())
        return false;

    if (chestLocation().equals(chest.chestLocation()))
        return true;

    // no double chest -> no further connection possible
    if (! (inventory() instanceof DoubleChestInventory))
        return false;

    Location myLoc = chestLocation();
    for (Chest c : chest.connectedChests())
        if (c.getLocation().equals(myLoc))
            return true;

    return false;
}
项目:vanillacraft    文件:GriefContainer.java   
public GriefContainer(BlockState block, UUID owner, boolean allowed)
{
    this.block = block;
    this.owner = owner;
    this.allowed = allowed;
    if (block instanceof Chest)
    {
        items = ((Chest) block).getBlockInventory().getContents();
    }
    else
    {
        items = ((InventoryHolder) block).getInventory().getContents();
    }

    timestamp = System.currentTimeMillis();
}
项目:IZenith-Main    文件:BowListener.java   
public void set(Location loc, Material material) {
    if (loc.getBlock().getType().equals(Material.AIR)) {
        loc.getBlock().setType(material);
        if (material.equals(Material.CHEST) || material.equals(Material.TRAP_DOOR)) {
            Chest chest = (Chest) loc.getBlock().getState();
            Inventory inv = chest.getInventory();
            for (int i = 0; i < inv.getSize(); i++) {
                Random gen = new Random();
                inv.setItem(i, new ItemStack(Material.values()[gen.nextInt(Material.values().length)]));
            }
            inv.setItem(4, new ItemStack(Material.BEDROCK));
            inv.setItem(13, new ItemStack(Material.BEDROCK));
            inv.setItem(21, new ItemStack(Material.BEDROCK));
            inv.setItem(23, new ItemStack(Material.BEDROCK));
        }
    }
}
项目:ShopChest    文件:ShopUtils.java   
/** Remove a shop
 * @param shop Shop to remove
 * @param removeFromDatabase Whether the shop should also be removed from the database
 * @param callback Callback that - if succeeded - returns null
 */
public void removeShop(Shop shop, boolean removeFromDatabase, Callback<Void> callback) {
    plugin.debug("Removing shop (#" + shop.getID() + ")");

    InventoryHolder ih = shop.getInventoryHolder();

    if (ih instanceof DoubleChest) {
        DoubleChest dc = (DoubleChest) ih;
        Chest r = (Chest) dc.getRightSide();
        Chest l = (Chest) dc.getLeftSide();

        shopLocation.remove(r.getLocation());
        shopLocation.remove(l.getLocation());
    } else {
        shopLocation.remove(shop.getLocation());
    }

    shop.removeItem();
    shop.removeHologram();

    if (removeFromDatabase) {
        plugin.getShopDatabase().removeShop(shop, callback);
    } else {
        if (callback != null) callback.callSyncResult(null);
    }
}
项目:ShopChest    文件:ChestProtectListener.java   
private void remove(final Shop shop, final Block b, final Player p) {
    if (shop.getInventoryHolder() instanceof DoubleChest) {
        DoubleChest dc = (DoubleChest) shop.getInventoryHolder();
        final Chest l = (Chest) dc.getLeftSide();
        final Chest r = (Chest) dc.getRightSide();

        Location loc = (b.getLocation().equals(l.getLocation()) ? r.getLocation() : l.getLocation());
        final Shop newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), loc, shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());

        shopUtils.removeShop(shop, true, new Callback<Void>(plugin) {
            @Override
            public void onResult(Void result) {
                newShop.create(true);
                shopUtils.addShop(newShop, true);
            }
        });
    } else {
        shopUtils.removeShop(shop, true);
        plugin.debug(String.format("%s broke %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
        p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_REMOVED));
    }
}
项目:ShopChest    文件:ChestProtectListener.java   
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onItemMove(InventoryMoveItemEvent e) {
    if (config.hopper_protection) {
        if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) {

            if (e.getSource().getHolder() instanceof DoubleChest) {
                DoubleChest dc = (DoubleChest) e.getSource().getHolder();
                Chest r = (Chest) dc.getRightSide();
                Chest l = (Chest) dc.getLeftSide();

                if (shopUtils.isShop(r.getLocation()) || shopUtils.isShop(l.getLocation())) e.setCancelled(true);

            } else if (e.getSource().getHolder() instanceof Chest) {
                Chest c = (Chest) e.getSource().getHolder();

                if (shopUtils.isShop(c.getLocation())) e.setCancelled(true);
            }

        }
    }
}
项目:uSkyBlock    文件:SignLogic.java   
public void addSign(Sign block, String[] lines, Chest chest) {
    Location loc = block.getLocation();
    ConfigurationSection signs = config.getConfigurationSection("signs");
    if (signs == null) {
        signs = config.createSection("signs");
    }
    String signLocation = LocationUtil.asKey(loc);
    ConfigurationSection signSection = signs.createSection(signLocation);
    signSection.set("location", LocationUtil.asString(loc));
    signSection.set("challenge", lines[1]);
    String chestLocation = LocationUtil.asString(chest.getLocation());
    signSection.set("chest", chestLocation);
    ConfigurationSection chests = config.getConfigurationSection("chests");
    if (chests == null) {
        chests = config.createSection("chests");
    }
    String chestPath = LocationUtil.asKey(chest.getLocation());
    List<String> signList = chests.getStringList(chestPath);
    if (!signList.contains(signLocation)) {
        signList.add(signLocation);
    }
    chests.set(chestPath, signList);
    saveAsync();
    updateSignsOnContainer(chest.getLocation());
}
项目:uSkyBlock    文件:SignEvents.java   
@EventHandler(priority = EventPriority.MONITOR)
public void onSignChanged(SignChangeEvent e) {
    if (e.isCancelled() || e.getPlayer() == null
            || !plugin.isSkyAssociatedWorld(e.getPlayer().getWorld())
            || !e.getLines()[0].equalsIgnoreCase("[usb]")
            || e.getLines()[1].trim().isEmpty()
            || !hasPermission(e.getPlayer(), "usb.island.signs.place")
            || !(e.getBlock().getType() == Material.WALL_SIGN)
            || !(e.getBlock().getState() instanceof Sign)
            ) {
        return;
    }
    Sign sign = (Sign) e.getBlock().getState();
    org.bukkit.material.Sign data = (org.bukkit.material.Sign) sign.getData();
    Block wallBlock = sign.getBlock().getRelative(data.getAttachedFace());
    if (isChest(wallBlock)) {
        logic.addSign(sign, e.getLines(), (Chest) wallBlock.getState());
    }
}
项目:civcraft    文件:PlayerListener.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryOpenEvent(InventoryOpenEvent event) {
    if (event.getInventory() instanceof DoubleChestInventory) {
        DoubleChestInventory doubleInv = (DoubleChestInventory)event.getInventory();

        Chest leftChest = (Chest)doubleInv.getHolder().getLeftSide();           
        /*Generate a new player 'switch' event for the left and right chests. */
        PlayerInteractEvent interactLeft = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, leftChest.getBlock(), null);
        BlockListener.OnPlayerSwitchEvent(interactLeft);

        if (interactLeft.isCancelled()) {
            event.setCancelled(true);
            return;
        }

        Chest rightChest = (Chest)doubleInv.getHolder().getRightSide();
        PlayerInteractEvent interactRight = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, rightChest.getBlock(), null);
        BlockListener.OnPlayerSwitchEvent(interactRight);

        if (interactRight.isCancelled()) {
            event.setCancelled(true);
            return;
        }           
    }
}
项目:civcraft    文件:InventoryHolderStorage.java   
public InventoryHolder getHolder() throws CivException {
    if (playerName != null) {
        Player player = CivGlobal.getPlayer(playerName);
        return (InventoryHolder)player;
    } 

    if (blockLocation != null) {
        /* Make sure the chunk is loaded. */

        if (!blockLocation.getChunk().isLoaded()) {
            if(!blockLocation.getChunk().load()) {
                throw new CivException("Couldn't load chunk at "+blockLocation+" where holder should reside.");
            }
        }
        if (!(blockLocation.getBlock().getState() instanceof Chest)) {
            throw new CivException("Holder location is not a chest, invalid.");
        }

        Chest chest = (Chest) blockLocation.getBlock().getState();
        return chest.getInventory().getHolder();
    }

    throw new CivException("Invalid holder.");
}
项目:civcraft    文件:InventoryHolderStorage.java   
public void setHolder(InventoryHolder holder) throws CivException {
    if (holder instanceof Player) {
        Player player = (Player)holder;
        playerName = player.getName();
        blockLocation = null;
        return;
    } 

    if (holder instanceof Chest) {
        Chest chest = (Chest)holder;
        playerName = null;
        blockLocation = chest.getLocation();
        return;
    } 

    if (holder instanceof DoubleChest) {
        DoubleChest dchest = (DoubleChest)holder;
        playerName = null;
        blockLocation = dchest.getLocation();
        return;
    }

    throw new CivException("Invalid holder passed to set holder:"+holder.toString());
}
项目:civcraft    文件:BonusGoodie.java   
public void setHolder(InventoryHolder holder) throws CivException {
    if (holder == null) {
        return;
    }

    if (holderStore == null) {
        if (holder instanceof Chest) {
            holderStore = new InventoryHolderStorage(((Chest)holder).getLocation());
        } else if (holder instanceof Player){
            holderStore = new InventoryHolderStorage((Player)holder);
        } else {
            throw new CivException("Invalid holder.");
        }
    } else {
        holderStore.setHolder(holder);
    }

    // If we have a holder, we cannot be on the ground or in a item frame.
    this.frameStore = null;
    this.item = null;

}
项目:StarQuestCode    文件:SQShops.java   
private double getWorth(Sign s) {

        double total = 0;
        Location l = new Location(s.getWorld(), s.getLocation().getX(), (s.getLocation().getY() - 1), s.getLocation().getZ());
        Chest c = (Chest) l.getBlock().getState();
        Inventory i = c.getInventory();

        for (ItemStack finalStack : i.getContents()) {
            if (finalStack == null)
                continue;

            if (inBlacklist(finalStack.getType())) {
                continue;
            }
            double quantity = finalStack.getAmount();
            ItemStack checkStack = new ItemStack(finalStack);
            checkStack.setAmount(1);
            if (itemIndex.get(checkStack) == null)
                continue;
            double price = itemIndex.get(checkStack);
            total = total + (price * quantity);
        }
        return roundTwoDecimals(total);

    }
项目:StarQuestCode    文件:ActiveHarvester.java   
public boolean update()
{
    anchor = harvester.detectFarmHeadAnchorBlock(anchorSupports, guiBlock);

    farmHeadSupport = harvester.detectFarmHeadSupports(anchor, forward);
    Block chestBlock = harvester.detectChest(guiBlock);
    harvesterHead = harvester.detectFarmHarvesterHead(farmHeadSupport);

    Integer rowPosition = harvester.getHarvestingRowLocation(guiBlock, forward);
    Integer headPosition = harvester.getHarvesterHeadLocation(guiBlock, forward, farmHeadSupport);

    if (rowPosition == null || anchorSupports.size() == 0 || harvesterHead == null || headPosition == null
            || !plugin.isActive(machine) // stop if its not active
            || (chestBlock.getState() instanceof Chest) == false)
        return false;

    chest = (Chest) chestBlock.getState();

    return true;
}
项目:StarQuestCode    文件:Drill.java   
/**
 * Detects if a chest is placed in the correct position and returns the chest Block or null if no chest was found.
 * @param base the GuiBlock
 * @return the chest Block
 */
public static Block detectChest(final Block base)
{
    List<BlockFace> diamond = new ArrayList<BlockFace>();
    diamond.add(BlockFace.NORTH);
    diamond.add(BlockFace.EAST);
    diamond.add(BlockFace.SOUTH);
    diamond.add(BlockFace.WEST);

    for(BlockFace bf : diamond)
    {
        if(base.getRelative(bf).getState() instanceof Chest)
            return base.getRelative(bf);
    }

    return null;
}
项目:CPU    文件:InventoryListener.java   
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryInteract(InventoryClickEvent e) {
    if (e.getInventory().getType() != InventoryType.CHEST) {
        return;
    }
    if (!(e.getRawSlot() == e.getSlot())) {
        return;
    }
    Block block = ((Chest) e.getInventory().getHolder()).getBlock();
    ItemStack[] contents = e.getView().getTopInventory().getContents();
    for (CPU cpu : CPUDatabase.CPUDatabaseMap) {
        if (!cpu.isBlockPartOfCPU(block)) {
            continue;
        }
        if (Arrays.deepEquals(contents, cpu.getCore().getInventory().getContents())) {
            cpu.getType().disable();
            CPUDatabase.removeCPU(cpu);
        }
    }
}
项目:Pugna    文件:Death.java   
public void destroyAll()
{
    Iterator<Map.Entry<String, DeathChest>> iterator = deathlocationspost.entrySet().iterator();
    while(iterator.hasNext())
    {
        Map.Entry<String, DeathChest> entry = iterator.next();
        String[] ld = entry.getKey().split(",");
        Location location = new Location(Bukkit.getWorld(ld[0]),Double.parseDouble(ld[1]),Double.parseDouble(ld[2]),Double.parseDouble(ld[3]));
        Block toDestroy = location.getBlock();
        if(toDestroy.getType().equals(Material.CHEST))
        {
            Chest drops = (Chest) toDestroy.getState();
            drops.getInventory().clear();
            toDestroy.setType(Material.AIR);
            toDestroy.setType(Material.AIR);
        }
        iterator.remove();
    }
}
项目:Pugna    文件:Death.java   
public void removeChest(UUID playerId, Location local)
{
    String location = local.getWorld().getName() + "," + String.valueOf( local.getBlockX()) + "," + String.valueOf( local.getBlockY()) + "," + String.valueOf(local.getBlockZ());
    Iterator<Map.Entry<String, DeathChest>> iterator = deathlocations.entrySet().iterator();

    while(iterator.hasNext())
    {
        Map.Entry<String, DeathChest> entry = iterator.next();
        DeathChest chest = entry.getValue();
        String loc = entry.getKey();

        if (chest.checkOwner(playerId) && loc.equals(location))
        {
            Block toDestroy = local.getBlock();
            if(toDestroy.getType().equals(Material.CHEST))
            {
                Chest drops = (Chest) toDestroy.getState();
                drops.getInventory().clear();
                toDestroy.setType(Material.AIR);
            }
            iterator.remove();
        }
    }
}
项目:Pugna    文件:Death.java   
public void createDeathChest(Player player, List<ItemStack> drops)
{
    if (pg.config.deathChest)
    {
        if(pg.config.global || player.getLocation().getWorld().toString().equals(pg.config.mapName))
        {
            Location death = checkLocation(player.getLocation());
            Block chest = death.getBlock();
            chest.setType(Material.CHEST);
            Chest chestp = (Chest) death.getBlock().getState();
            for (ItemStack tmp : drops)
            {
                chestp.getInventory().addItem(tmp);
            }
            UUID playerId = player.getUniqueId();
            String local = death.getWorld().getName() + "," + String.valueOf( death.getBlockX()) + "," + String.valueOf( death.getBlockY()) + "," + String.valueOf(death.getBlockZ());
            DeathChest box = new DeathChest(playerId);
            deathlocations.put(local, box);

            Message.info(player, "You have " + String.valueOf(pg.config.deathChestTime/20) + " seconds to retrive your items, good luck!"); 

            deathChestTimer(player, death);
        }
    }
}
项目:manco2    文件:CratePlayer.java   
/**
 * removes all memory allocated objects of the crate the player owns
 * 
 * @author xize
 */
public void remove() {
    if(pl.getCrateOwners().contains(p.getName())) {
        pl.getCrateOwners().remove(p.getName());
    }
    if(p.hasMetadata("crate")) {
        Chest chest = getCrateChest();
        chest.getInventory().clear();
        chest.removeMetadata("crate_owner", pl);
        chest.removeMetadata("crate_serie", pl);
        if(chest.hasMetadata("crate")) {
            System.out.println("chest has metadata key \"crate\"");
        }
        //chest.removeMetadata("crate", pl);
        chest.getBlock().setType(Material.AIR);
        p.removeMetadata("crate", pl);
    }
}
项目:manco2    文件:PlayerCrateProtectionEvent.java   
@EventHandler
public void onInteract(PlayerInteractEvent e) {
    if(e.isCancelled()) {
        return;
    }

    if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if(e.getClickedBlock().getType() == Material.CHEST) {
            Chest chest = (Chest) e.getClickedBlock().getState();
            if(chest.hasMetadata("crate_owner")) {
                String owner = ((FixedMetadataValue)chest.getMetadata("crate_owner").get(0)).asString();
                if(!e.getPlayer().getName().equalsIgnoreCase(owner)) {
                    e.getPlayer().sendMessage(ChatColor.RED + "this crate does not belongs to you!.");
                    e.setCancelled(true);
                }
            }
        }
    }
}