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);
}
}
}
}
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);
}
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;
}
Aggregations