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

Custom Item-Popups

Comments in 'Plugin Development' started by SM11, Aug 5, 2015.

  1. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Hey, I really need some help with A custom Item Popup, I finished but when I ran the Plugin and Used the Item nothing came Up. Could Someone please help me.
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I have nothing to do so i will try to create Main.php for you ;) Wait i'm writing...
  3. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Thanks, Although I already Have the code, I don't know why it dosnt work
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Mine will be better concept :p
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    <?php

    namespace Author\PluginName// This one should be changed

    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;

    use 
    pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\Config;

    class 
    CustomItemPopup extends PluginBase implements Listener{
       
       public 
    $prefs;
         
         public function 
    onLoad(){
             
    $this->getLogger()->info('Loading...');
         }
         public function 
    onEnable(){
           @
    mkdir($this->getDataFolder());
           if(
    file_exists($this->getDataFolder()."config.yml")){
           
    $this->prefs = (new Config($this->getDataFolder()."config.yml"Config::YAML))->getAll();
           }else{
             
    $default = array(
             
    "popup-time" => 2,
             
    "items" = array(
               
    "246" => "AllMighty Glowing Obsidian"
             
    ));
             
    $this->prefs = ($this->getDataFolder()."config.yml"Config::YAML$default);
           }
           
    $this->getServer()->getPluginManager()->registerEvents($this$this); // You must register Listener to do something on events
           
    $this->getLogger()->info('Enabled!');
         }
         public function 
    onDisable(){
           
    $this->prefs = new Config($this->getDataFolder()."config.yml"Config::YAML$this->prefs);
           
    $this->getLogger()->info('Disabled');
         }
         
         public function 
    onItemHeld(PlayerItemHeldEvent $event){
           
    $player $event->getPlayer();
           
    $item $event->getItem();
             if(
    array_key_exists($item->getId(), $this->prefs['items'])){
               
    $popup $this->prefs['items'][$item->getId()];
               
    $player->sendPopup($popup$this->prefs['popup-time']);
               return 
    true;
             }
         }
    }
    Test
  6. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You don't need to a return value for events.
  7. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Crashed, There was a Red mark on items = array
  8. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Lol just don't use the code he gives you.
  9. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    I know that but he said he was going to make the code for me
  10. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Code crashes your server, correct?
  11. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Yea i know but when im reading it it's better for me to understand!
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Wait where is the problem? I dont have phone to test on.
  13. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    items = array(
  14. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    yes It crashes my server
  15. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    OMG you created 100. page in development forum!
  16. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    ?
  17. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    <?php

    namespace Author\PluginName// This one should be changed

    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;

    use 
    pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\Config;

    class 
    CustomItemPopup extends PluginBase implements Listener{
      
       public 
    $prefs;
        
         public function 
    onLoad(){
             
    $this->getLogger()->info('Loading...');
         }
         public function 
    onEnable(){
           @
    mkdir($this->getDataFolder());
           if(
    file_exists($this->getDataFolder()."config.yml")){
           
    $this->prefs = (new Config($this->getDataFolder()."config.yml"Config::YAML))->getAll();
           }else{
             
    $default = array(
             
    "popup-time" => 2,
             
    "items" => array(
               
    "246" => "AllMighty Glowing Obsidian"
             
    ));
             
    $this->prefs = ($this->getDataFolder()."config.yml"Config::YAML$default);
           }
           
    $this->getServer()->getPluginManager()->registerEvents($this$this); // You must register Listener to do something on events
           
    $this->getLogger()->info('Enabled!');
         }
         public function 
    onDisable(){
           
    $this->prefs = new Config($this->getDataFolder()."config.yml"Config::YAML$this->prefs);
           
    $this->getLogger()->info('Disabled');
         }
        
         public function 
    onItemHeld(PlayerItemHeldEvent $event){
           
    $player $event->getPlayer();
           
    $item $event->getItem();
             if(
    array_key_exists($item->getId(), $this->prefs['items'])){
               
    $popup $this->prefs['items'][$item->getId()];
               
    $player->sendPopup($popup$this->prefs['popup-time']);
               return 
    true;
             }
         }
    }
    Little typo instead of "=>" i typed "="
  18. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    :confused: The code is so messy...
  19. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Crashed, Error at $this->prefs = ($this->getDataFolder()."config.yml", Config::YAML, $default);
  20. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Did'nt used much linebreaks so it could compress here as compact code :)

Share This Page

Advertisement