Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean canAccessProtection(Player player, Protection protection) {
- if (protection == null || player == null) {
- return true;
- }
- if (isAdmin(player)) {
- return true;
- }
- if (isMod(player)) {
- Player protectionOwner = protection.getBukkitOwner();
- if (protectionOwner == null) {
- return true;
- }
- if (!isAdmin(protectionOwner)) {
- return true;
- }
- }
- if (hasPermission(player, "lwc.bypass.access.protection")) {
- Player protectionOwner = protection.getBukkitOwner();
- if (protectionOwner == null) {
- return true;
- }
- if (!isAdmin(protectionOwner)) {
- return true;
- }else if (hasPermission(player, "lwc.bypass.access.only.admin"))
- return true;
- }
- // Their access level
- Permission.Access access = Permission.Access.NONE;
- switch (protection.getType()) {
- case PUBLIC:
- case DONATION:
- case DISPLAY:
- return true;
- case PASSWORD:
- if (wrapPlayer(player).getAccessibleProtections().contains(protection)) {
- return true;
- }
- break;
- case PRIVATE:
- if (protection.isOwner(player)) {
- return true;
- }
- if (protection.getAccess(player.getUniqueId().toString(), Permission.Type.PLAYER)
- .ordinal() >= Permission.Access.PLAYER.ordinal()) {
- return true;
- }
- if (protection.getAccess(player.getName(), Permission.Type.PLAYER).ordinal() >= Permission.Access.PLAYER
- .ordinal()) {
- return true;
- }
- // Check for item keys
- for (Permission permission : protection.getPermissions()) {
- if (permission.getType() != Permission.Type.ITEM) {
- continue;
- }
- // Get the item they need to have
- int item = Integer.parseInt(permission.getName());
- // Are they wielding it?
- BlockCache blockCache = BlockCache.getInstance();
- if (blockCache.getBlockId(player.getItemInHand().getType()) == item) {
- return true;
- }
- }
- for (String groupName : permissions.getGroups(player)) {
- if (protection.getAccess(groupName, Permission.Type.GROUP).ordinal() >= Permission.Access.PLAYER
- .ordinal()) {
- return true;
- }
- }
- break;
- default:
- break;
- }
- // call the canAccessProtection hook
- LWCAccessEvent event = new LWCAccessEvent(player, protection, access);
- moduleLoader.dispatchEvent(event);
- return event.getAccess() == Permission.Access.PLAYER || event.getAccess() == Permission.Access.ADMIN;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement