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

Remove All Items in my Lobby

Discussion in 'Development' started by Baducai, Apr 2, 2018.

  1. Baducai

    Baducai Spider Jockey

    Messages:
    30
    GitHub:
    Baducai
    How do all items disappear on the ground?

    How do I fix this?
    PHP:
    class DropParticle extends PluginTask {

     
        public function 
    __construct($plugin) {

            
    $this->plugin $plugin;

            
    parent::__construct($plugin);

        }

      

        public function 
    onRun($tick) {

          

            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $player) {

                
    $name $player->getName();

                
    $inv $player->getInventory();

              

                
    $players $player->getLevel()->getPlayers();

                
    $level $player->getLevel();

              

                
    $cfg = new Config($this->plugin->getDataFolder() . "config.yml"Config::YAML);

                if(
    in_array($level->getFolderName(),$cfg->get("Lobbys"))) {

                    foreach(
    $level->getEntities() as $e) {

                        if(
    $e instanceof ItemEntity) {

                            
    $player->getLevel()->removeEntity($e);

                        }
                    }
                }
            }
        }
    }
     
  2. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    [​IMG]
     
  3. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    PHP:
    foreach($this->plugin->getServer()->getOnlinePlayers() as $player) {
    $player->getInventory()->clearAll(); //Inventory
    $player->getArmorInventory()->clearAll(); //Armor
    }
     
  4. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    But, I would not do that on the PluginTask. Maybe something like that on your main file.
    PHP:
    //use pockermine/event/player/PlayerJoinEvent;
    public function onJoin(PlayerJoinEvent $event){
         
    $player $event->getPlayer();
         
    $player->getInventory()->clearAll(); //Inventory
         
    $player->getArmorInventory()->clearAll(); //Armor
    }
     
  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.