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

Solved Event registering

Comments in 'Plugin Development' started by Tim // robske Büba, Mar 17, 2016.

  1. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Ok, i have an plugin:
    MainClass:
    PHP:
    class Main extends PluginBase implements
    Listener{
    public function 
    onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    new 
    InventoryManager($this"SW");
    }
    }
    MainClass works fine
    But on
    new InventoryManager($this, "SW");
    PHP:
    <?php
    namespace robske_110\ServerCore;

    use 
    pocketmine\event\entity\EntityLevelChangeEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    #use pocketmine\event\inventory\InventoryEvent; //TODO::ForLaterImplementationToSaveStuffBetter
    #use pocketmine\event\player\PlayerExperienceChangeEvent; //TODO::ForLaterImplementationToSaveStuffBetter
    #use pocketmine\event\player\FOOD; //TODO::ForLaterImplementationToSaveStuffBetter
    #use pocketmine\event\entity\EntityDamageEvent; //TODO::ForLaterImplementationToSaveStuffBetter
    use pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\plugin\PluginBase;
    #use pocketmine\utils\TextFormat; //TODO::Messages
    use pocketmine\item\Item;

    class 
    InventoryManager extends Main implements Listener{
        public 
    $WatchWorld;
        private 
    $MainConfig;
        private 
    $Server;
        private 
    $savedInv//TODO::Events ForLaterImplementationToSaveStuffBetter
        
    private $savedExp//TODO::Events ForLaterImplementationToSaveStuffBetter
        
    private $savedFood//TODO::WaitingForEvents ForLaterImplementationToSaveStuffBetter
        
    private $savedHealth//TODO::Events ForLaterImplementationToSaveStuffBetter
        
    private $Stats;

        public function 
    __construct($MAIN$WatchWorld NULL){
            if (
    $WatchWorld == NULL) {
                
    #InventoryManager::__destruct(); //PHP will destruct this class by itself.
            
    } else {
                
    $this->Server $MAIN->getServer();
                
    $this->Server->getPluginManager()->registerEvents($this$this);
                @
    mkdir($this->getDataFolder());
                
    $this->MainConfig = new Config($this->getDataFolder() . "InventoryManager.yml"Config::YAML, array());
                if(!
    $this->MainConfig->exists("Stats")){
                    
    $this->MainConfig->set("Stats", ['Saves:' => 0,"Reads:" => 0]);
                    
    $this->Stats $this->MainConfig->get("Stats");
                }else{
                    
    $this->Stats $this->MainConfig->get("Stats");
                }
                
    $this->MainConfig->save();
                
    $this->WatchWorld $WatchWorld;
            }
        }
    Code:
    [21:54:00] [Server thread/CRITICAL]: pocketmine\utils\PluginException: "Plugin attempted to register robske_110\ServerCore\InventoryManager while not enabled" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 680
    
    The class crashes with that
    Last edited: Mar 18, 2016
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Leave a line break on main wtf can't read.
    applqpak and Vaivez66 like this.
  3. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Oops, gonna fix this, but all you need to know is that main class calls new InventoryManager($this, "SW") on onEnable
  4. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    You should probably make your code snippet readable
    applqpak and Hotshot_9930 like this.
  5. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Done
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    No answer?
  7. TheNewHEROBRINE
    Offline

    TheNewHEROBRINE New Member

    Joined:
    Mar 5, 2016
    Posts:
    10
    Minecraft User:
    TheNewHEROBRINE
    I think
    PHP:
    class Main extends PluginBase implements Listener{
    public function 
    onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    $this->getServer()->getPluginManager()->registerEvents(new InventoryManager($this"SW"), $this);
    }
    }
    and remove the line
    PHP:
    $this->Server->getPluginManager()->registerEvents($this$this);
    in InventoryManager
    Last edited: Mar 18, 2016
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This line in the InventoryManager constructor
    PHP:
    $this->Server->getPluginManager()->registerEvents($this$this);
    The plugin parameter should be $MAIN, not $this.
    applqpak likes this.
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Thanks, this is one of the copy paste functions you never think about :D (Erm what is the plugin param [first or secound?])
    Would work too, but i want InventoryManager to be completly independent.
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You can't register Listener without owner Plugin, as far as I know.
    Survingo likes this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Mind looking it up yourself?
    https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/plugin/PluginManager.php#L689
    PHP:
    public function PluginManager::registerEvents(ListenerPlugin);
    Or use an IDE ;) This is what happens in PhpStorm:

    psaf.PNG
    psaf2.PNG
    psaf3.PNG
  12. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I love you @PEMapModder #NoHomo (Do i even know your real gender lol)
    Especially for pointing out lines in the sources!
    And to the IDE: Is there an free one (Or can you get PHPStorm for free?)
  13. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Yes, i just didn't know the exact syntnax of the function
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I don't use NetBeans, but I heard that it has similar functions too. It is free.
    About free PhpStorm: https://www.jetbrains.com/student/
    applqpak and Primus like this.
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I'm such an noob, it won't allow me to install without Java >= 1.8 :D
    applqpak likes this.
  16. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Problems:
    1. I'm not an student (yet) [Still school]
    2. I'm in germany
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then install it?

Share This Page

Advertisement