Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.32 KB | None | 0 0
  1.     public boolean canBeModifiedFrom(PlotPermissions _originOfChange)
  2.     {
  3.         if(this.destroy.isPermitOthers() && this.build.isPermitOthers()) //others = anyone can modify
  4.         {
  5.             return true;
  6.         }
  7.         else //others cannot build or destroy
  8.         {
  9.             if(_originOfChange == null) //coming from unclaim
  10.             {
  11.                 return false;
  12.             }
  13.  
  14.             //The other claim allow others to change, we cannot allow it
  15.             if(_originOfChange.build.isPermitOthers() || _originOfChange.destroy.isPermitOthers())
  16.             {
  17.                 return false;
  18.             }
  19.         }
  20.  
  21.         if(this.destroy.isPermitFriends() && this.build.isPermitFriends())
  22.         {
  23.             //The other claim allow friends to change, we must check if its the same owner (for same friends)
  24.             if(_originOfChange.build.isPermitFriends() || _originOfChange.destroy.isPermitFriends())
  25.             {
  26.                 //different owner -> different friends, we cannot allow it
  27.                 if(this.owner != null && _originOfChange.owner != null && this.owner.getId() != _originOfChange.owner.getId())
  28.                 {
  29.                     return false;
  30.                 }
  31.             }
  32.         }
  33.         else //friends cannot build or destroy
  34.         {
  35.             //The other claim allow friends to change, we cannot allow it
  36.             if(_originOfChange.build.isPermitFriends() || _originOfChange.destroy.isPermitFriends())
  37.             {
  38.                 return false;
  39.             }
  40.         }
  41.  
  42.         if(this.destroy.isPermitGroup() && this.build.isPermitGroup())
  43.         {
  44.             //The other claim allow groups to change, we must check if its the same groups
  45.             if(_originOfChange.build.isPermitGroup() || _originOfChange.destroy.isPermitGroup())
  46.             {
  47.                 //different number of groups
  48.                 if(this.groups.size() != _originOfChange.groups.size())
  49.                 {
  50.                     return false;
  51.                 }
  52.  
  53.                 boolean foundGroup;
  54.                 boolean foundAllGroup = true;
  55.                 for(PermissionGroup group : this.groups)
  56.                 {
  57.                     foundGroup = false;
  58.                     for(PermissionGroup otherGroup : _originOfChange.groups)
  59.                     {
  60.                         if(group.getId() == otherGroup.getId()) //we found this group, we can progress to the next one
  61.                         {
  62.                             foundGroup = true;
  63.                             break;
  64.                         }
  65.                     }
  66.                     if(!foundGroup) //we didn't find this group, meaning people we might don't want can modify, we cannot allow them
  67.                     {
  68.                         foundAllGroup = false;
  69.                         break;
  70.                     }
  71.                 }
  72.                 if(!foundAllGroup)
  73.                 {
  74.                     return false;
  75.                 }
  76.             }
  77.         }
  78.         else //groups cannot build or destroy
  79.         {
  80.             //The other claim allow groups to change, we cannot allow it
  81.             if(_originOfChange.build.isPermitGroup() || _originOfChange.destroy.isPermitGroup())
  82.             {
  83.                 return false;
  84.             }
  85.         }
  86.  
  87.         return true;
  88.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement