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

Not responding to my call.

Discussion in 'Development' started by InspectorGadget, Dec 22, 2016.

  1. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi, I have been working on this plugin. There were no errors produced on Console but the plugin just doesn't load at all. Please correct me, if there's an issue. Thanks :)
    PHP:
    - AFKSystem.php -
    <?php

    /**
        * All rights reserved RTGNetworkkk
        * GitHub: https://github.com/RTGNetworkkk
        * Author: InspectorGadget
    */

    namespace RTG\AFK;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\Cancellable;

    use 
    pocketmine\event\player\PlayerDropItemEvent;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\event\player\PlayerDamageEvent;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\player\PlayerChatEvent;

    class 
    AFKSystem extends PluginBase implements Listener {
       
        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveResource("afklist.txt");
            
    $this->cfg = new Config($this->getDataFolder() . "afklist.txt");
        }
       
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
            switch(
    strtolower($cmd->getName())) {
           
                case 
    "afkmode":
                    if(
    $sender instanceof Player) {
                        if(
    $sender->hasPermission("afk.command")) {
                            if(isset(
    $args[0])) {
                                switch(
    strtolower($args[0])) {
                                   
                                    case 
    "on":
                                        
    $n $sender->getName();
                                       
                                        if(
    $this->cfg->get($n) === false) {
                                            
    $this->cfg->save();
                                            
    $this->broadcastMessage("§d[Server] [] $n is now AFK!");
                                        }
                                        return 
    true;
                                    break;
                                   
                                    case 
    "off":
                                        
    $n $sender->getName();
                                       
                                        if(
    $this->cfg->get($n) === true) {
                                            
    $this->cfg->remove($n);
                                            
    $this->cfg->save();
                                            
    $this->broadcastMessage("§d[Server] [] $n is no longer AFK!");
                                        }
                                        return 
    true;
                                    break;
                                   
                                }
                            }
                            else {
                                
    $sender->sendMessage("Usage: /afkmode < on | off >");
                            }
                        }
                        else {
                            
    $sender->sendMessage("§cYou have no permission to use this command!");
                        }
                    }
                    else {
                        
    $sender->sendMessage("Only in-game!");
                    }
                    return 
    true;
                break;
       
        public function 
    onMove(PlayerMoveEvent $e) {
            
    $n $e->getPlayer()->getName();
            if(
    $this->cfg->get($n) === true) {
                
    $e->getPlayer()->sendPopup("§c[AFK] Please do /afk to leave AFK Mode!");
                
    $this->setCancelled();
            }
        }
       
        public function 
    onHurt(PlayerDamageEvent $e) {
            
    $n $e->getPlayer()->getName();
            if(
    $this->cfg->get($n) === true) {
                
    $this->setCancelled();
            }
        }
       
        public function 
    onDrop(PlayerDropItemEvent $e) {
            
    $n $e->getPlayer()->getName();
            if(
    $this->cfg->get($n) === true) {
                
    $this->setCancelled();
            }
        }
       
        public function 
    onDeath(PlayerDeathEvent $e) {
            
    $n $e->getPlayer()->getName();
            if(
    $this->cfg->get($n) === true) {
                
    $this->setCancelled();
            }
        }
       
        public function 
    onChat(PlayerChatEvent $e) {
            
    $n $e->getPlayer()->getName();
            if(
    $this->cfg->get($n) === true) {
                
    $e->getPlayer()->sendMessage("[] Please do /afk to turn off AFK Mode!");
                
    $this->setCancelled();
            }
        }
       
        public function 
    onJoin(PlayerJoinEvent $e) {
            
    $n $e->getPlayer()->getName();
            if(
    $this->cfg->get($n) === true) {
                
    $this->cfg->remove($n);
                
    $this->cfg->save();
                
    $e->getPlayer()->sendMessage("You are no longer AFK!");
            }
        }
       
        public function 
    onDisable() {
        }
       
    }
    PHP:
    plugin.yml -
    nameAFKSystem
    version
    1.0.0
    main
    RTG\AFK\AFKSystem
    api
    : [2.0.02.1.03.0.0]
    authorInspectorGadget
    commands
    :
      
    afkmode:
        
    usage"/afkmode"
        
    permissionafk.command
        description
    "Toggles AFK!"
    permissions:
      
    afk.command:
        default: 
    op
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    If you are extending a class as listener, you need to register it as the event listener class.

    PHP:
    public function onEnable() {
        
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }
     
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Don't I have that? I'm confused.
     
    SOFe and svile like this.
  4. svile

    svile Spider

    Messages:
    14
    If it doesn't load at all your problem isn't the code (that seems like to be ok) but may depend on how are you trying to load it (is it a phar?) and what's your folder structure.
     
  5. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I load it using SRC, DevTools.
     
  6. svile

    svile Spider

    Messages:
    14
    What's your folder structure?
     
  7. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Example? I upload it straight without making it a ZIP using Build in FTP.
     
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Try adding debugging code like on all events, add a echo"Works EV(event name)";
     
    SOFe likes this.
  9. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Ok, will do
     
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Didn't see that oops..
    Your code seems fine, there's nothing wrong.
    Is plugin.yml and the src folder in the same directory?
     
  11. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Yes
     
  12. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    It's a good idea to push the whole code structure onto GitHub via Git. In this way we can see how the whole plugin looks like.
     
    Dog2puppy likes this.
  13. Dog2puppy

    Dog2puppy Slime

    Messages:
    94
    GitHub:
    colesquared
  14. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
  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.