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

Solved setPrefix Error

Discussion in 'Development' started by KinokiYT, May 11, 2020.

  1. KinokiYT

    KinokiYT Spider Jockey

    Messages:
    25
    GitHub:
    kinokiyt
    Hello, I'm working on a plugin vote reward plugin. I am having an issue with setting the player's prefix. I want to have it set the player's prefix instead of their rank because I don't want a voter rank overriding their current rank. This is what I have attempted:
    PHP:
    $prefix $this->getServer()->getPluginManager()->getPlugin("PureChat");
    $prefix->setPrefix('§8[§eVoter§8]§r'$player->getName());
    If you know why it's not working, that will help a lot. Thank you.
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
  3. KinokiYT

    KinokiYT Spider Jockey

    Messages:
    25
    GitHub:
    kinokiyt
    Alright, that worked. I have one last question, how will I get the $player in a delayed task? This is what I have:

    PHP:
    public function __construct(Main $main$playerName) {
            
    $this->main $main;
            
    $this->playerName $playerName;
        }
        public function 
    onRun(int $currentTick) {
            if(
    $player instanceof Player) {
                
    $prefix $this->getServer()->getPluginManager()->getPlugin("PureChat");
                
    $prefix->setPrefix(''$player);
    I don't know how I can get $player from that, I've made a few attempts, but they didn't work. Is there a way to do it from getServer(), or is there another way I can do it? Thanks.
     
  4. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    On your task, you want the __construct function to get the player:
    PHP:
    new MyTask($this$player)
    //$this is representing the PluginBase object
    PHP:
    public $player;
    public 
    $main

    public function __construct(Main $mainPlayer $player) {
            
    $this->main $main;
            
    $this->player $player;
        }
        public function 
    onRun(int $currentTick) {
            if(
    $this->player instanceof Player) {
                
    $prefix $this->player->getServer()->getPluginManager()->getPlugin("PureChat");
                
    $prefix->setPrefix(''$player);
    }
     
    Last edited: May 12, 2020
    KinokiYT likes this.
  5. KinokiYT

    KinokiYT Spider Jockey

    Messages:
    25
    GitHub:
    kinokiyt
    Thanks, that fixed it.
     
  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.