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

On player quit, delete inventory

Comments in 'Plugin Development' started by TonyDroidd, May 31, 2015.

  1. TonyDroidd
    Offline

    TonyDroidd Active Member

    Joined:
    Sep 6, 2014
    Posts:
    180
    Minecraft User:
    TonyDroidd
    How to delete the player inventory quen left the game??

    i tried whit:
    but i get this error: Error: Call to a member function setContents() on null
  2. TonyDroidd
    Offline

    TonyDroidd Active Member

    Joined:
    Sep 6, 2014
    Posts:
    180
    Minecraft User:
    TonyDroidd
  3. DestroyerofDeq
    Offline

    DestroyerofDeq Active Member

    Joined:
    May 17, 2014
    Posts:
    92
    Minecraft User:
    DestroyerofDeq
    But why would you want to delete someones inventory when they leave
  4. TonyDroidd
    Offline

    TonyDroidd Active Member

    Joined:
    Sep 6, 2014
    Posts:
    180
    Minecraft User:
    TonyDroidd
    too tried with
    $event->getPlayer()->getInventory()->setContents(array(Item::get(0, 0, 0)));
    but get the same error xd
  5. DestroyerofDeq
    Offline

    DestroyerofDeq Active Member

    Joined:
    May 17, 2014
    Posts:
    92
    Minecraft User:
    DestroyerofDeq
    tht didnt answer my question
  6. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    setContents() is not on the code you show.
    I cannot deem the problem based on unseen code :)
  7. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    He said he tried with that too.
  8. MineBuilderFR
    Offline

    MineBuilderFR Active Member

    Joined:
    Mar 14, 2015
    Posts:
    56
    Minecraft User:
    MineBuilderFR
    Public function onQuit(PlayerQuitEvent $event)

    $event->getPlayer ()->getInventory ()->clearAll ();
    } <- This
    }
  9. Goerick
    Offline

    Goerick Active Member

    Joined:
    Jan 24, 2014
    Posts:
    250
    Minecraft User:
    goerick
    I'm not that good at coding... how do you implement this?
  10. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    try this =_= :)
    PHP:
    public function OnJoin(PlayerJoinEvent $event){
    $player->$event->getPlayer();
    $inv $player->getInventory();
    if (
    $inv instanceof PlayerInventory) {
    $inv->clearAll();
    }
    }
  11. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Just remove invetory when player join :)
    LDX likes this.
  12. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Make sure your implementing the Listener :p
    PHP:
    <?php

    use pocketmine\plugin\PluginBase;
    use 
    pockemine\event\Listener;
    use 
    pocketmine\event\player\PlayerQuitEvent;

    namespace 
    Plugin;

    class 
    Main extends PluginBase implements Listener {
        public function 
    onQuit(PlayerQuitEvent $event) {
            
    $event->getPlayer()->getInventory()->clearAll();
        }
    }
    EDIT***

    PHP:
    <?php

    use pocketmine\plugin\PluginBase;
    use 
    pockemine\event\Listener;
    use 
    pocketmine\event\player\PlayerQuitEvent;

    namespace 
    Plugin;

    class 
    Main extends PluginBase implements Listener {

        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

        public function 
    onQuit(PlayerQuitEvent $event) {
            
    $event->getPlayer()->getInventory()->clearAll();
        }
    }
    Last edited: Jun 2, 2015
  13. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    RegisterEvents
    CrazedMiner likes this.
  14. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    i get this on crashdump

    Last edited: Jun 5, 2015
  15. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  16. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    clearAll() likes to crash the server if the players inventory is already empty, use this instead:
    PHP:
    <?php
    use pocketmine\plugin\PluginBase;
    use 
    pockemine\event\Listener;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\item\Item;

    namespace 
    Plugin;

    class 
    Main extends PluginBase implements Listener {

        public function 
    onEnable() {
        
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

        public function 
    onQuit(PlayerQuitEvent $event) {
        
    $event->getPlayer()->getInventory()->setContents(array(Item::get(000));
        }
    }
    Creeperface likes this.
  17. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Yes i have same problem
    CrazedMiner likes this.
  18. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    Logs the same error
  19. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    It can't have the same error... the clearAll() function was taken out.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Guys, did you even read the error message?
    It seems that the player inventory isn't even initialized. That happens when the player quits before logging in.
    Do a check first:
    if($player->getInventory() instanceof PlayerInventory)
    CrazedMiner likes this.

Share This Page

Advertisement