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

Solved Player detected as console

Discussion in 'Plugin Help' started by FresherGAMING, Aug 18, 2021.

  1. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    42
    GitHub:
    FresherGAMING
    When I type /fly, it send LytraSystem::NOCONSOLE message, but when I type it in console, it send the LytraSystem::NOCONSOLE too

    How to solve it ?

    PHP:
    <?php

    namespace LytraSystem\Commands;

    use 
    LytraSystem\LytraSystem;

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

    class 
    FlyCmd extends PluginCommand {
      
           public function 
    __construct(string $nameLytraSystem $plugin){
               
    parent::__construct($name$plugin);
               
    $this->setDescription("Flying");
               
    $this->setUsage("§cUsage: /fly");
               
    $this->setPermission("lytrasystem.fly.toggle");
               
    $this->plugin $plugin;
           }
      
           public function 
    execute(CommandSender $senderstring $alias, array $args) : bool{
               if(!
    $this->testPermission($sender)){
               return 
    true;
               }
               if(!
    $sender instanceof Player){
               
    $sender->sendMessage(LytraSystem::NOCONSOLE);
               return 
    true;
               } else {
               
    $sender->sendMessage($sender->getAllowFlight() === false LytraSystem::PREFIX "§eFly mode telah diaktifkan" LytraSystem::PREFIX "§cFly mode telah dinonaktifkan");
               
    $sender->setAllowFlight($sender->getAllowFlight() === false true false);
               
    $sender->setFlying($sender->isFlying() === false true false);
               return 
    true;
               }
           }
    }
     
  2. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    PHP:
    <?php

    namespace LytraSystem\Commands;

    use 
    LytraSystem\LytraSystem;

    use 
    pocketmine\command\PluginCommand;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;

    class 
    FlyCmd extends PluginCommand {
      
           public function 
    __construct(string $nameLytraSystem $plugin){
               
    parent::__construct($name$plugin);
               
    $this->setDescription("Flying");
               
    $this->plugin $plugin;
           }
      
           public function 
    execute(CommandSender $senderstring $alias, array $args) : bool{
               if(!
    $sender->hasPermission("lytrasystem.fly.toggle")){
                    
    $sender->sendMessage("You do not have permission to use this command!");
                    return 
    false;
               }
               if(!
    $sender instanceof Player){ # if sender is not a player
                    
    $sender->sendMessage(LytraSystem::NOCONSOLE);
                    return 
    false;
               }
               
    $sender->sendMessage($sender->getAllowFlight() === false LytraSystem::PREFIX "§eFly mode telah diaktifkan" LytraSystem::PREFIX "§cFly mode telah dinonaktifkan");
               
    $sender->setAllowFlight($sender->getAllowFlight() === false true false);
               
    $sender->setFlying($sender->isFlying() === false true false);
               return 
    true;
           }
    }
    Try this and see if it works. You didn't import pocketmine\Player, and had some unnecessary things in your code.
     
    Agent and Primus like this.
  3. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    42
    GitHub:
    FresherGAMING
    It worked, thanks
     
    minijaham 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.