Solved Resetting permissions

Discussion in 'Development' started by notdrewdev, Mar 21, 2019.

  1. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    33
    GitHub:
    drewsucksatlife
    So, whilst working on permissions, I was able to set them when a player joins with the following code:
    PHP:
    foreach(RankData::PERMISSIONS[$this->getRank()] as $permissions){
                
    $this->attachment $this->addAttachment(Loader::getInstance(), $permissionstrue);
            }
    however, when I update the players rank via mysql, their permissions don't reset and I'm not too sure how to do so. What solutions do y'all recommend?
     
  2. TheClimbing

    TheClimbing Spider Jockey

    Messages:
    32
    GitHub:
    theclimbing
    Do you update your arrays after updating your mysql database? If no that would be the reason
     
  3. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    160
    GitHub:
    diamondgamermcpe
    Instead of adding an attachment, check if the permission is in the array. ¯\_(ツ)_/¯
    That's an idea.
    PHP:
        // I'm guessing you are doing this in player class.
        
    public function hasPermission(string $permission): bool {
            
    $permissions RankData::PERMISSIONS[$this->getRank()];
            if(
    in_array($permission$permissions)) {
                return 
    true;
            }
            return 
    parent::hasPermission($permission);
        }
    And also, kind of off topic, I didn't know you were still in this community, Drew.
     
  4. wolfdale

    wolfdale Zombie

    Messages:
    258
    How you want the permission to reset? Remove the permissions of previous rank?
    PHP:
    //add
    foreach(RankData::PERMISSIONS[$this->getRank()] as $permissions){
                
    $this->attachments[] = $this->addAttachment(Loader::getInstance(), $permissionstrue);
            }
    //remove
    foreach($this->attachments as $a)
    $this->removeAttachment($a);
     
  5. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    33
    GitHub:
    drewsucksatlife
    Yes, I update the arrays.
     
  6. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    33
    GitHub:
    drewsucksatlife
    Not what I would prefer to do, and lol
     
  7. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    33
    GitHub:
    drewsucksatlife
    I did try that, but the only way it works is if I use a have a delayed task to wait for the mysql task to update, which I'd rather not want to wait for.
     
  8. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    33
    GitHub:
    drewsucksatlife
    Solved it but refreshing permissions when the async task is completed, I'm officially dumb lol
     
  9. Levi

    Levi Zombie Pigman

    Messages:
    763
    GitHub:
    captainleviftw
    Reset permissions as in attachmen->clearPermissions()?
     
  10. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
    I think it should be in reverse
    PHP:
    $this->attachments = [];
    foreach(
    RankData::PERMISSIONS[$this->getRank()] as $permission){
        
    $this->attachments[] = $this->addAttachment(Loader::getInstance(), $permissiontrue);
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.