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

runtime execption

Discussion in 'Help' started by SaintsDEV, Jul 2, 2020.

  1. SaintsDEV

    SaintsDEV Silverfish

    Messages:
    16
    GitHub:
    yukishiro
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    It looks like your "core" plugin UnitedNetwork has a bug in it. You might consider posting the faulty code.
     
  3. SaintsDEV

    SaintsDEV Silverfish

    Messages:
    16
    GitHub:
    yukishiro
    <?php

    namespace Juqn\Permission;


    use Juqn\Loader;
    use pocketmine\permission\PermissionAttachment;
    use pocketmine\Player;

    class PermissionUtils {

    private $plugin;
    private $attachments = [];
    private static $instance;

    public function __construct(Loader $plugin){
    $this->plugin = $plugin;
    self::$instance = $this;
    }

    private function getPlugin(){
    return $this->plugin;
    }

    public static function getInstance(){
    return self::$instance;
    }

    private function getAttachment(Player $player){
    $name = $player->getName();
    if(!isset($this->attachments[$name]))
    throw new \RuntimeException("Tried to calculate permissions on ".$name." using null attachment");
    return $this->attachments[$name];
    }

    public function registerPlayer(Player $player){
    $name = $player->getName();
    if(!isset($this->attachments[$name])){
    $attachment = $player->addAttachment($this->getPlugin());
    $this->attachments[$name] = $attachment;
    //print_r($this->attachments);
    }
    }

    public function updatePermission(Player $player, array $permissions){
    $perms = [];
    foreach ($permissions as $permission) {
    $perms[$permission] = true;
    }
    $attachment = $this->getAttachment($player);
    $attachment->clearPermissions();
    $attachment->setPermissions($perms);
    }

    public function addPermission(Player $player, array $permissions){
    $perms = [];
    foreach ($permissions as $permission) {
    $perms[$permission] = true;
    }
    $attachment = $this->getAttachment($player);
    $attachment->setPermissions($perms);
    }

    public function removePermission(Player $player){
    $attachment = $this->getAttachment($player);
    $attachment->clearPermissions();
    }
    }
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    749
    Apparently the PermissionUtils::getAttachment needs the player to be registered with PermissionUtils::registerPlayer before calling that method. I'm clueless, but try to add line to RankUpCommand before line 52, use the utils object->registerPlayer($sender).
     
  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.