1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Resetting permissions

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

  1. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    39
    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:
    39
    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:
    175
    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 Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    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:
    39
    GitHub:
    drewsucksatlife
    Yes, I update the arrays.
     
  6. notdrewdev

    notdrewdev Spider Jockey

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

    notdrewdev Spider Jockey

    Messages:
    39
    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:
    39
    GitHub:
    drewsucksatlife
    Solved it but refreshing permissions when the async task is completed, I'm officially dumb lol
     
  9. Levi

    Levi Skeleton

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

    KielKing Zombie

    Messages:
    245
    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);
    }
     
  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.