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

PlayerQuitEvent

Discussion in 'Plugin Help' started by ZackyVN, Dec 29, 2018.

  1. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    So i have this code to cancel every Particles task on the player when the player left
    PHP:


    namespace Wings;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    Wings\Tasks\{GreenWingRedWingFlameWing};
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase{

        public 
    $tasks = [];
      
    //  public $particle1 = array("GreenWing");
     //   public $particle2 = array("RedWing");
     //  public $particle3 = array("FlameWing");

        
    public function onEnable () : void{
            
    $this->getServer()->getLogger()->info("§l§aHero§bMC§e>§r§a Wings Enable");
        }

        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool{
            if (
    $cmd == "wing"){
                if(empty(
    $args[0]) || empty($args[1])){
                    
    $sender->sendMessage("§9•§4 Wing Red. §e/wing red <on|off>");
                    
    $sender->sendMessage("§9•§a Wing Green §e/wing green <on|off>");
                    
    $sender->sendMessage("§9•§6 Wing Flame. §e/wing Flame <on|off>");
                return 
    true;
            }
                if(!empty(
    $args[0])){
                    switch(
    $args[0]){
                        case 
    "green":
                            if(!
    $sender->hasPermission("green.wing")){
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn không có quyền dùng Wing §aGreen");
                            return 
    true;
                        }
                            if(
    $args[1] == "on"){
                            
    $task = new GreenWing($sender);
                            
    $this->tasks[$sender->getId()] = $task;
                            
    $this->getScheduler()->scheduleRepeatingTask($task10);
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§a Đã bật Wing Green");
                            }
                                if(
    $args[1] == "off"){
                                    
    $task $this->tasks[$sender->getId()];
                                    unset(
    $this->tasks[$sender->getId()]);
                                    
    $task->getHandler()->cancel();
                                    
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Wing §aGreen");
                                }
                        break;
                        case 
    "red":
                            if(!
    $sender->hasPermission("red.wing")){
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn không có quyền dùng Wing §4Red");
                            return 
    true;
                        }
                            if(
    $args[1] == "on"){
                            
    $task = new RedWing($sender);
                            
    $this->tasks[$sender->getId()] = $task;
                            
    $this->getScheduler()->scheduleRepeatingTask($task10);
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§a Đã bật Wing §4Red");
                            }
                                if(
    $args[1] == "off"){
                                    
    $task $this->tasks[$sender->getId()];
                                    unset(
    $this->tasks[$sender->getId()]);
                                    
    $task->getHandler()->cancel();
                                    
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Wing §4Red");
                                }
                        break;
                        case 
    "flame":
                            if(!
    $sender->hasPermission("flame.wing")){
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Bạn không có quyền dùng Wing §6Flame");
                            return 
    true;
                        }
                            if(
    $args[1] == "on"){
                            
    $task = new FlameWing($sender);
                            
    $this->tasks[$sender->getId()] = $task;
                            
    $this->getScheduler()->scheduleRepeatingTask($task10);
                                
    $sender->sendMessage("§l§aHero§bMC§e>§r§a Đã bật Wing §6Flame");
                            }
                                if(
    $args[1] == "off"){
                                    
    $task $this->tasks[$sender->getId()];
                                    unset(
    $this->tasks[$sender->getId()]);
                                    
    $task->getHandler()->cancel();
                                    
    $sender->sendMessage("§l§aHero§bMC§e>§r§c Đã tắt Wing §6Flame");
                                }
                        break;
                        default:
                    
    $sender->sendMessage("§9•§4 Wing Red. §e/wing red");
                    
    $sender->sendMessage("§9•§a Wing Green §e/wing green");
                    
    $sender->sendMessage("§9•§6 Wing Flame. §e/wing Flame");
                            break;
                    }
                }
            }
            return 
    true;
        }
       
        public function 
    onQuit(PlayerQuitEvent $e) {
            
    $player $e->getPlayer();
            
    $task $this->tasks[$player->getId()];           
            unset(
    $this->tasks[$player->getId()]);
            
    $task->getHandler()->cancel();
        }
    }
    But it doesnt work and it didnt send any error except my particles task because it cant locate the player
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You did not register events
    implement Listener
    PHP:
    class Main extends PluginBase implements \pocketmine\event\Listener{
    register events
    PHP:
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
     
    corytortoise 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.