Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bug onJoin

Comments in 'Plugin Development' started by Asparanc, Feb 28, 2015.

  1. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Hey i've a big bug with my onJoin function.

    PHP:
    <?php

    namespace Asparanc\EconomyMaster;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\permission\Permission;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\utils\TextFormat;
    use 
    Asparanc\EconomyMaster\EcoAPI;
    class 
    Register implements Listener{

    public function 
    __construct(EcoAPI $plugin){
      
    $this->plugin $plugin;
     }

    public function 
    onJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            if(!
    EcoAPI::getInstance()->isRegistered($player->getName())){
             
    $this->data $this->getDataFolder();
             
    $data = new Config($this->data "players/" strtolower($player->getName() . ".yml"), Config::YAML);
            
    $data->set("money"0);
            
    $date->set("bank"0);
            
    $data->save();
             
    $this->plugin->getLogger()->notice("New player : ".$player->getName());
            }
    else{ 
    $this->plugin->getLogger()->notice("aaaa");}
    }
    }
    PHP:
    <?php

    namespace Asparanc\EconomyMaster;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    Asparanc\EconomyMaster\Register;

    class 
    EcoAPI extends PluginBase{
    public 
    $config;
    public 
    $data;
    private static 
    $object null;
       
    public static function 
    getInstance(){
            return 
    self::$object;
        }
       
    public function 
    onLoad(){
            if(!
    self::$object instanceof EconomyMaster){
                
    self::$object $this;
            }
              
    $this->data $this->getDataFolder();
    }
        public function 
    onEnable(){
           @
    mkdir($this->getDataFolder());
           @
    mkdir($this->getDataFolder() . "players/");
           @
    mkdir($this->getDataFolder() . "areas/");
           @
    mkdir($this->getDataFolder() . "casinos/");
           @
    mkdir($this->getDataFolder() . "clouds/");
           @
    mkdir($this->getDataFolder() . "lands/");
           @
    mkdir($this->getDataFolder() . "npcs/");
           @
    mkdir($this->getDataFolder() . "pjobs/");
           @
    mkdir($this->getDataFolder() . "pshops/");
           @
    mkdir($this->getDataFolder() . "signs/"); 
          @
    mkdir($this->getDataFolder() . "coporates/");
        
    $this->data $this->getDataFolder();
            
    $this->config $this->getConfig()->getAll();
            
    $this->playerfolder $this->getDataFolder() . "players/";

    }
    public function 
    getSymbol(){
      
    $this->config = new Config($this->data "config.yml"Config::YAML);
            return 
    $this->config->get('symbol');
    }

    public function 
    isRegistered($player){
        return 
    file_exists($this->playerfolder.strtolower($player.".yml"));
    }
    }
    I don't understand why it don't work, the server just do anything, same as the code doesn't exist...
  2. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Because you don't register the event in the "onEnable()" function, try to add the following line:
    PHP:
    $this->getServer()->getPluginManager()->registerEvents($this$this);
  3. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    In onEnable ?
  4. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    It say unexpected $this
  5. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Yes
    Ooops, try this:
    PHP:
    $this->getServer()->getPluginManager()->registerEvents(new Register($this), $this);
  6. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Unexpected $this
    Again..
  7. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    .-. Did you know how to use multiple files?
  8. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Not really x) i need $this = Register ?
  9. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    No, please look at other plugins that use this kind of function, if you can't get it working, register it in the main class
  10. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
  11. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    I've see you use

    use EssentialsPE\.........;
    And look my main :
    use Asparanc\EconomyMaster\Register

  12. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    PHP:
    /**
      * @param PlayerJoinEvent
      *
      * @priority MONITOR
      * @ignoreCancelled true
      */
    Maybe add that

    And also, what is exactly the bug?
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I don't think PlayerJoinEvent is Cancellable.
  14. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Sorry, i've fix it :) this night.

Share This Page

Advertisement