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

Need help figuring out why plugin not doing what it's supposed to

Discussion in 'Development' started by Sakkzz, Aug 25, 2019.

  1. Sakkzz

    Sakkzz Spider

    Messages:
    7
    GitHub:
    rezzsin
    I just started trying to learn how to code plugins less than a day ago so have mercy on my knowledge lol I'm still learning but anyway. I tried to make a plugin that would say when a staff member joins the server using PurePerms groups. I thought I had it since I had no errors but it doesnt work and doesnt change the join message. Anyone mind helping me out?​

    PHP:
        public function onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->perms $this->getServer()->getPluginManager()->getPlugin("PurePerms");
            
    $this->getLogger()->info("Finished loading!");
    }

        public function 
    onJoin(PlayerJoinEvent $event) {
            
    $group $this->perms->getUserDataMgr()->getGroup($event->getPlayer())->getName();
                if(
    $group == "Guest"){
                
    $event->setJoinMessage("§7".$event->getPlayer()->getName() . "has joined the server!");
              }
                if(
    $group == "Mod"){
                
    $event->setJoinMessage("§fServer §9Mod§b" $event->getPlayer()->getName() . "§fhas joined the server!");
              }
                if(
    $group == "Admin"){
                
    $event->setJoinMessage("§fServer §eAdmin§a" $event->getPlayer()->getName() . "§fhas joined the server!");
              }
                if(
    $group == "Owner"){
                
    $event->setJoinMessage("§fServer §4Owner§6" $event->getPlayer()->getName() . "§fhas joined the server!");
            }
        }
    }

        public function 
    onQuit(PlayerQuitEvent $event) {
            
    $group $this->perms->getUserDataMgr()->getGroup($event->getPlayer())->getName();
                if(
    $group == "Guest"){
                
    $event->setQuitMessage("§7".$event->getPlayer()->getName() . "§fhas left the server!");
              }
                if(
    $group == "Mod"){
                
    $event->setQuitMessage("§fServer §9Mod§b" $event->getPlayer()->getName() . "§fhas left the server!");
              }
                if(
    $group == "Admin"){
                
    $event->setQuitMessage("§fServer §eAdmin§a" $event->getPlayer()->getName() . "§fhas left the server!");
              }
                if(
    $group == "Owner"){
                
    $event->setQuitMessage("§fServer §4Owner§6" $event->getPlayer()->getName() . "§fhas left the server!");
                }
            }
        }
    }
     
  2. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    Can do you var_dump($group) and check what it shows in console?
     
  3. Sakkzz

    Sakkzz Spider

    Messages:
    7
    GitHub:
    rezzsin
    I'm not sure how to do that tbh
    I've only just started doing this lol but if you could tell me how or direct me to where I could learn then that would be fine also
     
  4. kriskotooBG

    kriskotooBG Spider Jockey

    Messages:
    46
    GitHub:
    kriskotoobg
    About learning PHP: i would suggest going through the PHP documentation, its really well written and a great starting point, PHP docs: https://www.php.net/docs.php

    About the pocketmine API: i personally would suggest going through its source code and see how stuff works, or go through other well-written plugins.

    About the problem you're having: Under this line:
    PHP:
    public function onJoin(PlayerJoinEvent $event) {
        
    $group $this->perms->getUserDataMgr()->getGroup($event->getPlayer())->getName();
    put
    PHP:
    var_dump($group);
    so in the end it should look like:
    PHP:
    public function onJoin(PlayerJoinEvent $event) {
        
    $group $this->perms->getUserDataMgr()->getGroup($event->getPlayer())->getName();
        
    var_dump($group);
        
    //other code...
    What var_dump does is basically "dump" the "var" aka the variable to the console, giving you its type, and value that way you can see if
    PHP:
    $group $this->perms->getUserDataMgr()->getGroup($event->getPlayer())->getName();
    returns the correct value you're looking for!

    var_dump() PHP docs: https://www.php.net/manual/en/function.var-dump.php
     
    HimbeersaftLP likes this.
  5. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    The code looks fine at first glance, so are you sure that your plugin loaded correctly? To check, when you type '/plugins' is it listed in green or red, or not there at all? Were there any errors on console during startup? Did you add PurePerms to the softdepend section of plugin.yml?
     
    HimbeersaftLP likes this.
  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.