Advertisement
broken-arrow

Untitled

Nov 9th, 2021
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1.     public boolean canAccessProtection(Player player, Protection protection) {
  2.         if (protection == null || player == null) {
  3.             return true;
  4.         }
  5.  
  6.         if (isAdmin(player)) {
  7.             return true;
  8.         }
  9.         if (isMod(player)) {
  10.             Player protectionOwner = protection.getBukkitOwner();
  11.  
  12.             if (protectionOwner == null) {
  13.                 return true;
  14.             }
  15.  
  16.             if (!isAdmin(protectionOwner)) {
  17.                 return true;
  18.             }
  19.         }
  20.         if (hasPermission(player, "lwc.bypass.access.protection")) {
  21.             Player protectionOwner = protection.getBukkitOwner();
  22.  
  23.             if (protectionOwner == null) {
  24.                 return true;
  25.             }
  26.  
  27.             if (!isAdmin(protectionOwner)) {
  28.                 return true;
  29.             }else if (hasPermission(player, "lwc.bypass.access.only.admin"))
  30.                 return true;
  31.         }
  32.         // Their access level
  33.         Permission.Access access = Permission.Access.NONE;
  34.  
  35.         switch (protection.getType()) {
  36.             case PUBLIC:
  37.             case DONATION:
  38.             case DISPLAY:
  39.                 return true;
  40.  
  41.             case PASSWORD:
  42.                 if (wrapPlayer(player).getAccessibleProtections().contains(protection)) {
  43.                     return true;
  44.                 }
  45.  
  46.                 break;
  47.  
  48.             case PRIVATE:
  49.                 if (protection.isOwner(player)) {
  50.                     return true;
  51.                 }
  52.  
  53.                 if (protection.getAccess(player.getUniqueId().toString(), Permission.Type.PLAYER)
  54.                         .ordinal() >= Permission.Access.PLAYER.ordinal()) {
  55.                     return true;
  56.                 }
  57.  
  58.                 if (protection.getAccess(player.getName(), Permission.Type.PLAYER).ordinal() >= Permission.Access.PLAYER
  59.                         .ordinal()) {
  60.                     return true;
  61.                 }
  62.  
  63.                 // Check for item keys
  64.                 for (Permission permission : protection.getPermissions()) {
  65.                     if (permission.getType() != Permission.Type.ITEM) {
  66.                         continue;
  67.                     }
  68.  
  69.                     // Get the item they need to have
  70.                     int item = Integer.parseInt(permission.getName());
  71.  
  72.                     // Are they wielding it?
  73.                     BlockCache blockCache = BlockCache.getInstance();
  74.                     if (blockCache.getBlockId(player.getItemInHand().getType()) == item) {
  75.                         return true;
  76.                     }
  77.                 }
  78.  
  79.                 for (String groupName : permissions.getGroups(player)) {
  80.                     if (protection.getAccess(groupName, Permission.Type.GROUP).ordinal() >= Permission.Access.PLAYER
  81.                             .ordinal()) {
  82.                         return true;
  83.                     }
  84.                 }
  85.  
  86.                 break;
  87.             default:
  88.                 break;
  89.         }
  90.  
  91.         // call the canAccessProtection hook
  92.         LWCAccessEvent event = new LWCAccessEvent(player, protection, access);
  93.         moduleLoader.dispatchEvent(event);
  94.  
  95.         return  event.getAccess() == Permission.Access.PLAYER || event.getAccess() == Permission.Access.ADMIN;
  96.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement