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

Solved Command not work

Discussion in 'Development' started by AbelGamerC, Aug 4, 2017.

  1. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    My code is it:
    PHP:
    <?php

    namespace NovaCore\Commands;

    use 
    NovaCore\Core\NCCore;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\PluginIdentifiableCommand;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\Config;
    use 
    NovaCore\Player\PlayerData;

    class 
    RegisterCommand extends Command implements PluginIdentifiableCommand{

        
    /** @var  NCCore $plugin */
        
    private $plugin;

        public function 
    __construct(NCCore $plugin){
            
    parent::__construct("register""Register in NovaCraft PE");
            
    $this->plugin $plugin;
        }

        public function 
    execute(CommandSender $senderstring $commandLabel, array $args) : bool
        
    {
            if (
    $sender instanceof Player) {
                
    $users = new Config($this->plugin->getDataFolder() . "users.yml"Config::YAML);

                
    /** @var PlayerData $pd */
                
    $pd $this->plugin->players[strtolower($sender->getName())];
                if (!
    $users->exists($sender)) {
                    if(!isset(
    $args[0])){
                        return 
    true;
                    }
                    if (!
    $pd->isAuthed()) {
                        
    $sender->sendMessage(TextFormat::DARK_AQUA "Te has registrado correctamente!");
                        
    $users->set($sender->getName(), $args[0]);
                        
    $users->save();
                        
    $sender->removeAllEffects();
                        
    $pd->setAuthed(true);
                    } else {
                        
    $sender->sendMessage(TextFormat::DARK_RED "No es necesario volver a iniciar secion");
                    }
                    
    /**} else {
                     * $sender->sendMessage(TextFormat::DARK_RED . "Ya te has registrado, porfavor inicia secion");
                     * }
                     * } else {
                     * $sender->sendMessage(TextFormat::DARK_RED . "Ejecuta este comando en el juego");
                     * }*/
                
    }
            }
            return 
    false;
        }

        public function 
    getPlugin() : Plugin{
            return 
    $this->plugin;
        }
    }

    Error in console:
    [12:13:00] [Server thread/CRITICAL]: Unhandled exception executing command 'register xd' in register: Illegal offset type in isset or empty
    [12:13:00] [Server thread/CRITICAL]: ErrorException: "Illegal offset type in isset or empty" (EXCEPTION) in "src/pocketmine/utils/Config" at line 421
     
    Last edited by a moderator: Aug 4, 2017
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You're using the CommandSender object as the key, which is invalid. Only ints or strings can be used.
     
  3. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    PHP:
    #you are using a config in yaml i don't think "exists()" is the good function
    #replace if(!$users->exists($sender)) by
    if(!$users->get($sender)) 
    #maybe $sender->getName() will be good
    i think that can work.
     
  4. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    Loool XD thanks guys
     
  5. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    now work thanks!
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    There is nothing wrong with using exists()...
     
    jasonwynn10, Thunder33345 and Levi like this.
  7. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    But that work Not a problem
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    PHP:
    exit(0);
    This will work and fix all bugs. Your server will exit with 0 i.e. it executed successfully.
     
  9. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    So you're creating a Config every time the command is ran?
     
  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.