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

Why cant i send a message with variables?

Discussion in 'Development' started by alex dooley, May 6, 2020.

  1. alex dooley

    alex dooley Creeper

    Messages:
    2
    GitHub:
    dotmoney
    i get the special but not the variables in between.

    PHP:
    <?php

    namespace Buff;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\command\ConsoleCommandSender;

    class 
    Main extends PluginBase implements Listener
    {

        public function 
    onEnable()
        {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            @
    mkdir($this->getDataFolder());
            
    $this->cfg = new Config($this->getDataFolder() . "sp.yml"Config::YAML);
        }
        public function 
    onJoin(PlayerJoinEvent $event)
        {
            
    $player $event->getPlayer();
            
    $name $player->getName();
            if(
    $this->cfg->get($name) !== null) {
                
    $this->ss $this->cfg->get($player.'+s');
                
    $this->sp $this->cfg->get($player.'+p');
                
    $this->se $this->cfg->get($player.'+e');
                
    $this->sc $this->cfg->get($player.'+c');
                
    $this->si $this->cfg->get($player.'+i');
                
    $this->sa $this->cfg->get($player.'+a');
                
    $this->sl $this->cfg->get($player.'+l');
                
    $this->sx $this->cfg->get($player.'+ex');
            }else{
                
    $this->cfg->set("$name+s",0);
                
    $this->cfg->set("$name+p",0);
                
    $this->cfg->set("$name+e",0);
                
    $this->cfg->set("$name+c",0);
                
    $this->cfg->set("$name+i",0);
                
    $this->cfg->set("$name+a",0);
                
    $this->cfg->set("$name+l",0);
                
    $this->cfg->set("$name+ex",40);
                
    $this->cfg->set("$name lock"false);
                
    $this->cfg->save();
            }
        }
        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args): bool
        
    {
            switch (
    $cmd->getName()) {
                case 
    'sp':
                    
    $sender->sendMessage("S:$this->ss, P:$this->sp, E:$this->se, C:$this->sc, I:$this->si, A:$this->sa, L:$this->sl, Extra:$this->sx");
                    break;
                case 
    'set':
                    
    $slk $this->cfg->get("$sender lock");
                    if(
    $slk == false) {
                        if(
    $args[1] == 's' or $args[1] == 'S') {
                            
    $this->cfg->set("$sender +s"$args[2]);
                            
    $this->sx -= $args[2];
                            
    $this->cfg->set("$sender +ex",$this->sx);
                            
    $this->cfg->save();
                        }
                    }else{
                        
    $sender->sendMessage('gay');
                    }
                    break;
            }
            return 
    true;
        }
    }
    ?>[/CODE]
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Oh my god that code physically hurts me and the childish error message for non-lock players is just the cherry on top.
    As for fixing your issue, you need to use $sender->getName()
     
    driver1848 likes this.
  3. alex dooley

    alex dooley Creeper

    Messages:
    2
    GitHub:
    dotmoney
    So I put the $sender->getName() instead of what? also i am not gonna keep the word in there for non locked players xd
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Ditch that, the whole code is awful and not going to work without significant changes, I don't have time to do that right now, maybe ask someone one Discord
     
  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.