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

Error when running /spawn

Discussion in 'Development' started by CocoonBuilder, Sep 30, 2018.

  1. CocoonBuilder

    CocoonBuilder Spider Jockey

    Messages:
    43
    GitHub:
    chimneychuckles
    <?php

    namespace JoinItem;

    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\event\player\PlayerJoinEvent;
    use pocketmine\Player;
    use pocketmine\Server;
    use pocketmine\item\Item;
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;

    class Main extends PluginBase implements Listener {

    public function onEnable(){
    $this->getLogger()->info("Successfully Enabled");
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function onDisable(){
    $this->getLogger()->info("Successfully Disabled");
    }

    public function onJoin(PlayerJoinEvent $event){
    $player = $event->getPlayer(); //Player = Get Player That Doing The Event (Join Server)
    $player->getInventory()->clearAll();
    $player->getInventory()->setItem(3, Item::get(280, 1, 1));
    $player->getInventory()->setItem(5, Item::get(399, 1, 1));
    }

    public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool{

    if(strtolower($command->getName()) == "spawn"){
    $sender->getInventory()->clearAll();
    $sender->getInventory()->setItem(3, Item::get(280, 1, 1));
    $sender->getInventory()->setItem(5, Item::get(399, 1, 1));
    return true;
    }
    }
    }



    Not sure what is wrong with it please help
     
  2. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    Undefined variable $command at 8th to last line. Also, don't use hardcoded item IDs...
     
    HimbeersaftLP likes this.
  3. CocoonBuilder

    CocoonBuilder Spider Jockey

    Messages:
    43
    GitHub:
    chimneychuckles
  4. CocoonBuilder

    CocoonBuilder Spider Jockey

    Messages:
    43
    GitHub:
    chimneychuckles
    thx it is fixed
     
  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.