/** * Adds the shops associated with the specified block to the provided collection * * @param block The block to check around * @param plugin The currently active PhysicalShop plugin * @param shops The collection to add to * @return the provided collection */ public static Collection<Shop> getShops( final Block block, final PhysicalShop plugin, final Collection<Shop> shops) { Validate.notNull(shops, "Must provide a collection to add result to"); for (final BlockFace face : EXTENDED_DIRECTIONS) { final Shop shop = getShop(block.getRelative(face), plugin); if (shop != null && shop.isShopBlock(block)) { shops.add(shop); } } return shops; }
/** * Checks a list of shops against player for ownership.<br> * Assumes block ARE protected. * * @param shops The shops being destroyed * @param player The player destroying block, can be null (as in, no destroyer) * @param plugin The active PhysicalShop plugin * @return false if there are shops and player is null or not admin and not owner */ public static boolean isShopsDestroyable( final Collection<Shop> shops, final Player player, final PhysicalShop plugin) { if (shops.isEmpty()) return true; if (player == null) return false; if (plugin.getPermissionHandler().hasAdmin(player)) return true; for (final Shop shop : shops) { if (!hasAccess(player.getName(), shop, plugin)) { shop.getSign().update(); return false; } } return true; }
/** * Attempts to create a new shop object based on this block * * @param block the block to consider * @param plugin The active PhysicalShop plugin * @return null if block is not sign or said sign is invalid, otherwise a new associated {@link * Shop} for this block */ public static Shop getShop(final Block block, final PhysicalShop plugin) { if (block == null) return null; if (block.getType() != SIGN_POST && block.getType() != WALL_SIGN) return null; final Sign sign = (Sign) block.getState(); if (sign == null) return null; final String ownerName = Shop.getOwnerName(sign.getLines()); try { if (block.getRelative(DOWN).getType() == CHEST) return new ChestShop(sign, plugin); else if (ownerName.equalsIgnoreCase(plugin.getConfig().getString(SERVER_SHOP))) return new Shop(sign, plugin); else return null; } catch (final InvalidSignException e) { return null; } }
/** * This assumes player does NOT have admin access * * @param player Player to check for access * @param shop Shop to check for access * @param plugin The current instance of PhysicalShop * @return true if the player has permission for the shop */ public static boolean hasAccess(final String player, final Shop shop, final PhysicalShop plugin) { return shop == null || (!plugin.getConfig().getString(SERVER_SHOP).equals(shop.getOwnerName()) && shop.isSmartOwner(player, plugin)); }