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

What code should i use to give a player an item as they join

Comments in 'Plugin Development' started by Hotshot_9930, May 2, 2015.

  1. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Do you even know the PocketMine API? PlayerJoinEvent is not a Cancellable. PocketMine will throw an exception of you attempt to cancel it.
    I believe you forgot a ! (not) operator on line 3.
    Man, it is no longer 1.3. PocketMine event handlers don't need any return values now.
    You should use the full names of the classes you mentioned in your code only.
    What is the significance of following?
    TigerHix, EvolSoft and Hotshot_9930 like this.
  2. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Thanks for your tips @PEMapModder. But im still having a bit of a challenge though. How would i make it so new players get a certain item? Ive been doing
    PHP:
    public function playerJoin(PlayerJoinEvent $pje){
    $player $pje->getPlayer();
    if(
    $player->hasPlayedBefore()) {
    $player->getInventory()->addItem(new Item (iddamageamount));

    }
    else {
    $player->getInventory()->addItem(new Item(iddamageamount))
    }
    But that doesnt work.
    Im still a bit of a noob with the pocketmine api so any suggestions would be helpfull
    Last edited: May 3, 2015
  3. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    I believe it's already implemented
    Why shouldn't I use new Item()? It works fine.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It won't work with some particular items. For example, a water bucket, depending in the way you use it, may not work because the server doesn't know it is a water bucket unless it is created from new Bucket() or from Item::get() (which eventually returns a Bucket). Item won't have the code for that.
  5. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Will try later, but thanks.

Share This Page

Advertisement