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

Solved Help

Discussion in 'Plugin Help' started by ATVExtremeGamer, Sep 13, 2021.

  1. ATVExtremeGamer

    ATVExtremeGamer Creeper

    Messages:
    4
    GitHub:
    atvextremegamer
    Hi,

    PHP:
    <?php

    namespace test;

    use 
    pocketmine\Server;
    use 
    pocketmine\Player;

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\event\Listener;

    use 
    pocketmine\event\player\PlayerJoinEvent;

    use 
    pocketmine\utils\Config;

    class 
    main extends PluginBase implements Listener {
     
        public function 
    onEnable() {
         
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            @
    mkdir($this->getDataFolder()  . "players/");
         
            
    $this->getServer()->getLogger()->info("[test] Enabled");
        }
     
        public function 
    onDisable() {
            
    $this->getServer()->getLogger()->info("[test] Disabled");
        }
     
        public function 
    playerJoinEvent(PlayerJoinEvent $event) {
         
            
    $player $event->getPlayer();

            
    $this->config = new Config($this->getDataFolder()  . "players/"  strtolower($player->getName()), Config::YAML, array(
                
    "ruleaccepted" => false
            
    ));
            
    $this->config;
         
            if (
    $this->config->get("ruleaccepted") == false) {
                
    $this->formOnJoin($player);
            }
        }
     
        public function 
    formOnJoin($player) {
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $playerint $data null) {
                
    $result $data;
                if(
    $result === null) {
                    
    $this->formOnJoin($player);
                    return 
    true;
                }

                switch(
    $result) {
                    case 
    0:
                        
    $this->config->set("ruleaccepted"true);
                        
    $this->config->save();
                         
                        
    $player->sendMessage("Thank you for accepting the rules.");
                    break;
     
                    case 
    1:
                        
    $player->kick("\nYou have not agreed to the rules.");
                    break;
                }
            });
            
    $form->setTitle("Welcome and Rules");
            
    $form->setContent("RULES");
            
    $form->addButton("I accept\nAnd do not show this again.");
            
    $form->addButton("I disagree");
            
    $form->sendToPlayer($player);
            return 
    $form;
        }
    }

    ?>

    Whenever I join from my main account and then from my alt, and click on disagree (on my alt), and accept (on my main account), it only sets "ruleaccepted" to true for my alt and not for my main's.

    Is there a way to fix this?
    Thanks.
     
    Last edited: Sep 14, 2021
  2. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    PHP:
    $this->config->set("ruleaccepted"true);
    This part and all the related part to this are misunderstooded... It got used by all players...
    I will help you latter ^^
    sorry for bad grammar :p
     
    ATVExtremeGamer likes this.
  3. Axon

    Axon Zombie

    Messages:
    276
    Helpful tip!
    Add code blocks between your code to make it look neater.
    Eg (Type it without the space in front of PHP:
    [ PHP]
    Code…
    [ /PHP]

    Or click the + sign intop of the chat box, and click code.
     
    Agent, NTT and ATVExtremeGamer like this.
  4. ATVExtremeGamer

    ATVExtremeGamer Creeper

    Messages:
    4
    GitHub:
    atvextremegamer
    Here is the updated code:

    PHP:
    <?php

    namespace test;

    use 
    pocketmine\Server;
    use 
    pocketmine\Player;

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\event\Listener;

    use 
    pocketmine\event\player\PlayerJoinEvent;

    use 
    pocketmine\utils\Config;

    class 
    main extends PluginBase implements Listener {
     
        public function 
    onEnable() {
        
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            @
    mkdir($this->getDataFolder()  . "players/");
        
            
    $this->getServer()->getLogger()->info("[test] Enabled");
        }
     
        public function 
    onDisable() {
            
    $this->getServer()->getLogger()->info("[test] Disabled");
        }
     
        public function 
    playerJoinEvent(PlayerJoinEvent $event) {
        
            
    $player $event->getPlayer();

            
    $this->config = new Config($this->getDataFolder()  . "players/"  strtolower($player->getName()), Config::YAML, array(
                
    "ruleaccepted" => false
            
    ));
            
    $this->config;
        
            if (
    $this->config->get("ruleaccepted") == false) {
                
    $this->formOnJoin($player$this->config);
            }
        }
     
        public function 
    formOnJoin($player$config) {
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $playerint $data null) use ($config) {
                
    $result $data;
                if(
    $result === null) {
                    
    $this->formOnJoin($player$config);
                    return 
    true;
                }

                switch(
    $result) {
                    case 
    0:
                        
    $config->set("ruleaccepted"true);
                        
    $config->save();
                        
                        
    $player->sendMessage("Thank you for accepting the rules.");
                    break;
     
                    case 
    1:
                        
    $player->kick("\nYou have not agreed to the rules.");
                    break;
                }
            });
            
    $form->setTitle("Welcome and Rules");
            
    $form->setContent("RULES");
            
    $form->addButton("I accept\nAnd do not show this again.");
            
    $form->addButton("I disagree");
            
    $form->sendToPlayer($player);
            return 
    $form;
        }
    }

    ?>
    Thanks to: lıu = sıɥʇ JJJJJJJJe/\
    for helping me to fix.
     
  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.