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

Help my first plugin

Comments in 'Plugin Development' started by eloszki013, Apr 26, 2016.

  1. eloszki013
    Offline

    eloszki013 New Member

    Joined:
    Jan 21, 2016
    Posts:
    5
    Minecraft User:
    eloszki123
    Plzz editi code for me.

    Main.php
    Code:
    <?php
    
    namespace Flsmers;
    
    use pocketmine\plugin\PluginBase;
    use pocketmine\item\Item;
    use pocketmine\Player;
    use pocketmine\utils\Config;
    use oocketmine\inventory\Inventory;
    use pocketminr\command\ConsoleCommandSender;
    use pocketmine\command\CommandSender;
    use pocketmine\command\Command;
    
    class Main extends PluginBase{
        public function onEnable(){
            }
            $this->getLogger()->info("Zadania zaladowane");
            }
    
      public function onCommand(CommandSender $sender, Command $command, $label, array $args){   
                if(strtolower($command->getName('cobblex'))) {
                    if(empty($args)) {
                        $sender->sendMessage("");
                        $sender->sendMessage("• §9>> §aZdobądz 64 cobblestona §9>> §a/skyblock 1");
                        $sender->sendMessage("• §9>> §aZdobądz 32 złota §9>> §a/skyblock 2");
                        $sender->sendMessage("• §9>> §aZdobądz 32 żelaza §9>> §a/skyblock 3");
                        $sender->sendMessage("• §9>> §aZdobądz 64 diamenty §9>> §a/skyblock 4");
                        $sender->sendMessage("• §9>> §cWięcej zadań wkrótce :)");
                        return true;
                    }
                if($args[0] == "kup") {
            }else{
          if($sender->getInventory()->contains(Item::get(4, 0, 64))){
                $sender->getInventory()->addItem(Item::get(388, 0, 1));
                $sender->sendMessage("§a • Kupiłeś cobblex • ");
                }
                else{
                  $sender->sendMessage("§c • Nie masz cobblestone'a • ");
                  }
               }
              return true;
                }
            }
        }
    }
    
    plugin.yml
    Code:
    name: CobblexKup
    main: Flsmers\Main
    version: 1.0.0
    api: 2.0.0
    commands:
    cobblex:
      description: "Kupno cobblex"
      permission: "cobblex.cobblexkup"
      default: true
    
    Thanks :)
  2. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    What an error you have?
  3. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    PHP:
    class Main extends PluginBase{
    public function 
    onEnable(){
    }
    $this->getLogger()->info("Zadania zaladowane");
    }
    I have narrowed down where the mistake may be at. Try to find it yourself.
    Primus and HotFireyDeath like this.
  4. ankitmaharjan252
    Offline

    ankitmaharjan252 New Member

    Joined:
    Mar 17, 2015
    Posts:
    5
    Minecraft User:
    AnkitM252
    I saw where is the mistake
  5. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    PHP:
    <?php

    namespace Flsmers;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\Config;
    use 
    oocketmine\inventory\Inventory;
    use 
    pocketminr\command\ConsoleCommandSender;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\Listener;

    class 
    Main extends PluginBase implements Listener{
        public function 
    onEnable(){
            }
            
    $this->getLogger()->info("Zadania zaladowane");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }

      public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){  
                if(
    strtolower($command->getName('cobblex'))) {
                    if(empty(
    $args)) {
                        
    $sender->sendMessage("");
                        
    $sender->sendMessage("• §9>> §aZdobądz 64 cobblestona §9>> §a/skyblock 1");
                        
    $sender->sendMessage("• §9>> §aZdobądz 32 złota §9>> §a/skyblock 2");
                        
    $sender->sendMessage("• §9>> §aZdobądz 32 żelaza §9>> §a/skyblock 3");
                        
    $sender->sendMessage("• §9>> §aZdobądz 64 diamenty §9>> §a/skyblock 4");
                        
    $sender->sendMessage("• §9>> §cWięcej zadań wkrótce :)");
                        return 
    true;
                    }
                if(
    $args[0] == "kup") {
            }else{
          if(
    $sender->getInventory()->contains(Item::get(4064))){
                
    $sender->getInventory()->addItem(Item::get(38801));
                
    $sender->sendMessage("§a • Kupiłeś cobblex • ");
                }
                else{
                  
    $sender->sendMessage("§c • Nie masz cobblestone'a • ");
                  }
               }
              return 
    true;
                }
            }
        }
    }
    I dont know wether it is right but I've registered the events and implements the Listener
  6. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    One main problem you have is the OnEnable

    here is a corrected one.
    PHP:
    class Main extends PluginBase implements Listener{
        public function 
    onEnable(){
            
    $this->getLogger()->info("Zadania zaladowane");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }
    The last "}" for the "class Main extends PluginBase implements Listener{" goes at the bottom of the whole code
    Ill correct the rest soon
    Last edited: Apr 27, 2016
  7. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Your bold tags are wrong...
  8. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Why would you even implement unnecessary Listener?
    Primus and HotFireyDeath like this.
  9. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    I havent added it. I simply corrected where the "{" / "}" tags go
  10. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    You implemented Listener alright...
    minebuilder0110 likes this.
  11. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    Quotes to help you :)

  12. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    You should look at the original code, not the one suggested by someone else.
  13. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    I understand what you mean, but the person who suggested it was also wrong. So I have the right to correct that person.
    Dont you agree?
    Primus likes this.
  14. TheDeibo
    Offline

    TheDeibo Notable Member

    Joined:
    Sep 8, 2014
    Posts:
    693
    Minecraft User:
    TheDeibo
    Hey! Hope its not too late to point out that little typos make a big diference too.

    use oocketmine\inventory\Inventory;

    Look in BOLD for the error

    oocketmine is the typo. Its supposed to be pocketmine
    Primus and minebuilder0110 like this.

Share This Page

Advertisement