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

Plugin help

Comments in 'Plugin Development' started by XFuryMCPE, Dec 25, 2015.

  1. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    Hey, I was making this plugin for a dude in Plugin Help and i dont see what i did wrong

    PHP:
    namespace xfury\ti;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\inventory\PlayerInventory;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    class 
    Main extends PluginBase implements Listener{

      public function 
    onCommand(Command $cmd array $args $sender){
        
    $p $this->getPlayer();
        if(
    strtolower($cmd->getName()) == "take"){
          if(
    count($args) == 1){
            
    $sender->sendMessage(TextFormat::RED."USAGE: /take <player> <item> <amount>");
          }
          if(
    count($args == 2){
            
    $args[0] = $p->getName();
            if(!
    $args[0] instanceof $p){
              
    $sender->sendMessage(TextFormat::RED."ERROR: Player not online!");
            }
            else{
              if(!
    numeric($args[1])){
                
    $sender->sendMessage(TextFormat::RED."ERROR: Item ID must be numeric!");
              }
              else{
                
    $args[0]->getInventory()->takeItem($args[1], 064);
                
    $sender->sendMessage(TextFormat::GREEN."SUCCESS: Successfully took 64 of ID$args[1] from $args[0]!");
              }
            }
          }
          if(
    count($args == 3){
            
    $args[0] = $p->getName();
            if(!
    args[0] instanceof $p){
              
    $sender->sendMessage(TextFormat::RED."ERROR: Player not found!");
            }
            else{
              if(!
    numeric($args[1])){
                
    $sendMessage(TextFormat::RED."ERROR: Item ID must be numeric!");
              }
              else{
                if(!
    numeric($args[2])){
                  
    $sender->sendMessage(TextFormat::RED."ERROR: Item Amount must be numeric!");
                }
                else{
                  
    $args[0]->getInventory()->takeItem($args[1], 0$args[2]);
                  
    $sender->sendMessage(TextFormat::GREEN."SUCCESS: Successfully took $args[2] of ID$args[1] frp, $args[0]");
                }
              }
            }
          }
        }
      }
    }
    The error I get:

    RuntimeException: "Couldn't load the source plugin TakeItems: main class not found"

    Any ideas? I'm pretty new to the PocketMine API, probably made a dumb mistake haha
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    you have some PHP Problems, also can i have the plugin.yml ?
  3. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    Code:
    name: TakeItems
    author: XFuryMCPE
    description: "Take items from players inventories!"
    version: 1.0.0
    main: xfury/ti/Main
    api: 1.12.0
    website: s.at-fac.net
    
    commands:
      take:
        description: "Take items from players"
        permission: take.use
    permissions:
      take.use:
        default: op
        description: "Main permission to take items from players."
    
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    the main file name should be Main.php and the directory src/xfury/ti as on your plugin.yml, so have you did that?
  5. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    I'm not sure about that second part. The file is in xfury/ti, i haven't included the src/ in any of my other plugins so i don't think it would be necessary here?
  6. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Just change all the "/" to "\" in the plugin.yml. Problem solved.
    KubixQ and PocketKiller like this.
  7. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    I tried that too and got another error:

    Code:
    ClassNotFoundException: "Class xfury\ti\Main not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 131
    ?
  8. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    look at this, it might help u
    Screenshot (45).png
    Primus likes this.
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    what is this o_O
    1.
    PHP:
    $p $this->getPlayer();

    (!
    $args[0] instanceof Player)
    2. Implementing Listener altough you're not registered it and event not using any events.

    3. Why do you think Item Ammount must be 64? (Not dynamicly changeable)

    4. Why there is no return statements?
    PHP:
    return false// Will send usage
    return true// Will send nothing
    5. Could be more but i'm not that bored.
    Last edited: Dec 25, 2015
    PocketKiller likes this.
  10. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    this
    PHP:
    public function onCommand(Command $cmd array $args $sender){
    should be
    PHP:
    public function onCommand(\pocketmine\command\CommandSender $senderCommand $command$label, array $args) {
    o_O
  11. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    public function onCommand(\pocketmine\command\CommandSender $sender, \pocketmine\command\Command $command$label, array $args)
  12. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    i already edited it, refresh the page -.-
  13. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Ohh i see, you wanted me to keep refreshing page until it changes? Well it's your fault that you had to take second shot don't blame me now!
    applqpak likes this.
  14. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    whoops
  15. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    PHP:
      if(count($args == 2){ 
    You forgot the ) after $args
  16. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Why didn you created another post instead of using edit button? And its called "Concatenating"
  17. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    PHP:
    public function onCommand(Command $cmd array $args $sender)
    {
    $p $this->getPlayer();
    Where is the , between the variable, instead of $this->getPlayer() you should type $sender, so it is $p = $sender;
  18. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I wasn't criticizing but teaching.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Make your plugin into a zip, upload it to http://pmt.MCPE.me and check the inspection checkboxes. They tell you everything.
    XFuryMCPE likes this.
  20. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Too much code for a really easy plugin lol

Share This Page

Advertisement