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

addItem() not works

Comments in 'Plugin Development' started by Ragnok1234, Aug 28, 2016.

  1. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    Hello? I have little code:
    PHP:
    foreach($this->redPlayer as $num => $red){
            
    $this->getServer()->getPlayer($red)->getInventory()->addItem(Item::get(27401));
           }
    Sometimes code gives the stone pickaxe, but sometimes no. sendContents() I tried, like addItem(). Any idea why sometimes DOESNT gives stone pickaxe?
  2. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    You mean Item::STONE_PICKAXE?
    PocketKiller likes this.
  3. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    My bad :p
  4. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    I changed it with ITEM::STONE_PICKAXE, but already that problem
  5. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Try to check if player is Player not other entity?
  6. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    I have checked, all in $this->redPlayer=array() are players
  7. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Class names are case-senstive.
    Wut?
    Maybe it gave the item, but the client didn't display the item? try relogging.
  8. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Try to var_dump the array, to check if there are all redPlayers in it, because I assume that there is a problem with your array
  9. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Class names are not case sensitive, constants are.
    I don't see how this will solve the problem, Item::STONE_PICKAXE also refers to 274. But it's a good practice to use constants instead of hard-coding the numbers. :)
    What the...
    I suspect it has something to do with your redPlayer array. You should add a couple debug lines, I guarantee that you'll find some surprising things. ;)
    Primus likes this.
  10. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    If a bug "sometimes" occurs in a simple plugin and you can't find out the condition, it most likely means that you have a PocketMine/client/PHP bug. It is because simple plugins have little conditions to check for, and you won't have that very complicated bugs either. GI, GO.
    Primus likes this.
  11. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Classes are case insensitive, but some filesystems are case sensitive. This leads to a problem when autoloading. This doesn't matter in this situation though, because the Item class is first loaded in the Server class to register default items.
    Gamecrafter and Primus like this.
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    phpstorm will complain if you don't use right caps and I always listen to this ide :D that's one more reason why you shouldn't do that. We can't know what will happen in future and class references can get case sensitive.
  13. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    This compatibility thing is less likely. If it is supposed to be compatible the first day, it should theoretically never be removed. Guessing that it will be incompatible one day is a very low priority, because you never guess what will happen in the future. Instead, worry about yourself mixing up this fact with other programming languages.
    Gamecrafter likes this.

Share This Page

Advertisement