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

Why does addItem not work?

Comments in 'Plugin Development' started by myst02, May 29, 2015.

  1. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Hi,

    I coded a plugin, and it fails at this line of code:
    PHP:
    $player->getInventory()->addItem(new ItemBlock(Block::get($itemname), "10"$count));
    Error is:
    13:36:01 [CRITICAL] Could not pass event pocketmine\event\player\PlayerInteractEvent to EasyRewards v1.1.2: Class kjjnetwork\EasyRewards\ItemBlock not found on kjjnetwork\EasyRewards\Main
    13:36:01 [CRITICAL] ClassNotFoundException: "Class kjjnetwork\EasyRewards\ItemBlock not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 144

    Please help :)
  2. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    The error is not related to the part of code you wrote here.
    Check plugin.yml file. The error is there
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    It is an class error. Make sure that class name and file name is all same. This is a quote from @PEMapModder.
  4. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Maybe it doesnt work because my plugin does not have any commands or perms?
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    It doea not matter with commands and permissions I think...
  6. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    You are missing an "use" statement
    iJoshuaHD likes this.
  7. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    ok, and which one? Some with "ItemBlock"?
    thank you :)
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Maybe
    Code:
    use pocketmine\event\Player\PlayerInteractEvent;
  9. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    I have already added this :(
    But it still doesn't work
  10. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Can you post your plugin.yml file and the entire main class?
  11. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Yes, I can:

    plugin.yml:
    Code:
    name: EasyRewards
    api: [1.3.1]
    version: 1.1.2
    load: POSTWORLD
    main: kjjnetwork\EasyRewards\Main
    author: kjjnetwork
    website: http://www.kjjserver.com
    
    commands:
    
    
    
    permissions:
    

    Main.php:
    PHP:
    <?php

    namespace kjjnetwork\EasyRewards;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\event\block\SignChangeEvent;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\tile\Tile;
    use 
    pocketmine\Player;
    use 
    pocketmine\item/ItemBlock;
    use 
    onebone\economyapi\EconomyAPI;

    class 
    Main extends PluginBase implements Listener{
      private 
    $api$server$path;

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

      public function 
    playerBlockTouch(PlayerInteractEvent $event){
      if(
    $event->getBlock()->getID() == 323 || $event->getBlock()->getID() == 63 || $event->getBlock()->getID() == 68){
      
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
      if(!(
    $sign instanceof Sign)){
      return;
      }
      
    $sign $sign->getText();
      if(
    $sign[0]=='[REWARD]'){
      if(empty(
    $sign[2]) !== true){
      
    $itemname $sign[1];
      
    $count $sign[2];
      
    $money $sign[3];
      
    $player $event->getPlayer();
      
    $playername $player->getName();
      
    EconomyAPI::getInstance()->addMoney($player$money);
      
    $player->getInventory()->addItem(new ItemBlock(Block::get($itemname), "10"$count));
      
    $this->getServer()->broadcastMessage("[server] Player '".$playername."' just got cool rewards!");
      
    $event->getPlayer()->sendMessage("[server] Reward given! Thanks for playing on KJJ!");
      }else{
      
    $event->getPlayer()->sendMessage("[server] Reward sign is broken! Please report to [email protected]");
      }
      }
      }
      }
      }

    Thank you!
    AddMoney part is working, but not giving items.
  12. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    You should just use Item::get or Item::fromString, which means you need to do use ....something...\Item
    PEMapModder likes this.
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What? Why? He just forgot to use pocketmine\item\ItemBlock.
  15. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Yes. I read the thread too fast xD
    Then I realised that the error was on ItemBlock class, sorry :p
  16. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Yay! It works now! Thanks so much for all your help!
    I also had to add pocketmine\block\Block
    Now it works :)

Share This Page

Advertisement