Search in sources :

Example 6 with Chest

use of org.spongepowered.api.block.tileentity.carrier.Chest in project TotalEconomy by Erigitic.

the class ShopManager method onShopDestroy.

/**
 * Handles a chest shop being destroyed.
 *
 * @param event Pre break block
 * @param player The player who broke the block
 */
@Listener
public void onShopDestroy(ChangeBlockEvent.Break.Pre event, @First Player player) {
    Optional<TileEntity> tileEntityOpt = event.getLocations().get(0).getTileEntity();
    if (tileEntityOpt.isPresent()) {
        TileEntity tileEntity = tileEntityOpt.get();
        Optional<Shop> shopOpt = tileEntity.get(ShopKeys.SINGLE_SHOP);
        if (shopOpt.isPresent()) {
            Chest chest = (Chest) tileEntity;
            Shop shop = shopOpt.get();
            UUID shopOwner = shop.getOwner();
            if (!player.getUniqueId().equals(shopOwner)) {
                event.setCancelled(true);
                player.sendMessage(messageManager.getMessage("shops.remove.notowner"));
            } else if (player.getUniqueId().equals(shopOwner) && chest.getInventory().totalItems() > 0) {
                event.setCancelled(true);
                player.sendMessage(messageManager.getMessage("shops.remove.stocked"));
            } else {
                event.getLocations().get(0).removeBlock();
                event.getLocations().get(0).setBlockType(BlockTypes.CHEST);
            }
        }
    }
}
Also used : Chest(org.spongepowered.api.block.tileentity.carrier.Chest) Listener(org.spongepowered.api.event.Listener)

Example 7 with Chest

use of org.spongepowered.api.block.tileentity.carrier.Chest in project LanternServer by LanternPowered.

the class LanternChest method getConnectedChests.

@Override
public Set<Chest> getConnectedChests() {
    if (!isValid()) {
        return Collections.emptySet();
    }
    final Location<World> location = getLocation();
    final Set<Chest> chests = new HashSet<>();
    for (Direction directionToCheck : HORIZONTAL_DIRECTIONS) {
        final Location<World> loc = location.getRelative(directionToCheck);
        if (loc.getBlock().getType() != getBlock().getType()) {
            continue;
        }
        final Optional<TileEntity> optTileEntity = location.getRelative(directionToCheck).getTileEntity();
        if (optTileEntity.isPresent() && optTileEntity.get() instanceof LanternChest) {
            chests.add((Chest) optTileEntity.get());
        }
    }
    return Collections.unmodifiableSet(chests);
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Chest(org.spongepowered.api.block.tileentity.carrier.Chest) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) HashSet(java.util.HashSet)

Example 8 with Chest

use of org.spongepowered.api.block.tileentity.carrier.Chest in project LanternServer by LanternPowered.

the class ChestInteractionBehavior method validateOpenableSpace.

@SuppressWarnings("ConstantConditions")
@Override
protected boolean validateOpenableSpace(BehaviorContext context, Location<World> location, List<Runnable> tasks) {
    final TileEntity tileEntity = location.getTileEntity().get();
    if (tileEntity instanceof Chest) {
        final Set<Chest> chests = new HashSet<>(((Chest) tileEntity).getConnectedChests());
        chests.add((Chest) tileEntity);
        for (Chest chest : chests) {
            final Location<World> loc = chest.getLocation();
            if (!validateOpenableChestSpace(context, loc, tasks)) {
                return false;
            }
        }
    }
    return true;
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Chest(org.spongepowered.api.block.tileentity.carrier.Chest) World(org.spongepowered.api.world.World) HashSet(java.util.HashSet)

Aggregations

Chest (org.spongepowered.api.block.tileentity.carrier.Chest)8 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)6 World (org.spongepowered.api.world.World)6 Carrier (org.spongepowered.api.item.inventory.Carrier)4 Inventory (org.spongepowered.api.item.inventory.Inventory)4 Listener (org.spongepowered.api.event.Listener)3 Direction (org.spongepowered.api.util.Direction)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 DuctData (org.cubeengine.module.itemduct.data.DuctData)2 BlockCarrier (org.spongepowered.api.item.inventory.BlockCarrier)2 CarriedInventory (org.spongepowered.api.item.inventory.type.CarriedInventory)2 Location (org.spongepowered.api.world.Location)2 InventoryQueueEntry (com.karanumcoding.adamantineshield.db.queue.InventoryQueueEntry)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1