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. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You dont need $this->prefs in CustomItemPopups::eek:nDisable.
  2. 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)->getAll();
           }
           
    $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;
             }
         }
    }
    Fixed
    Sorry for crashes i'm trying to help as much i can, if i would have my phone i would give you phar instead :)
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    true, but if i implement like command that will add items custom popups in-game? It's rudemental for now.
  4. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Commands? Wut?
  5. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Crashed Heres the Crash Log

    PocketMine-MP Crash Dump Wed Aug 5 12:26:51 AKDT 2015

    Error: syntax error, unexpected ','
    File: /SSMMessages/src/SM11/SSMMessages/Main
    Line: 29
    Type: E_PARSE

    THIS CRASH WAS CAUSED BY A PLUGIN

    Code:
    [20] @mkdir($this->getDataFolder());
    [21] if(file_exists($this->getDataFolder()."config.yml")){
    [22] $this->prefs = (new Config($this->getDataFolder()."config.yml", Config::YAML))->getAll();
    [23] }else{
    [24] $default = array(
    [25] "popup-time" => 2,
    [26] "items" => array(
    [27] "246" => "AllMighty Glowing Obsidian"
    [28] ));
    [29] $this->prefs = ($this->getDataFolder()."config.yml", Config::YAML, $default)->getAll();
    [30] }
    [31] $this->getServer()->getPluginManager()->registerEvents($this, $this); // You must register Listener to do something on events
    [32] $this->getLogger()->info('Enabled!');
    [33] }
    [34] public function onDisable(){
    [35] $this->prefs = new Config($this->getDataFolder()."config.yml", Config::YAML, $this->prefs);
    [36] $this->getLogger()->info('Disabled');
    [37] }
    [38]
    [39] public function onItemHeld(PlayerItemHeldEvent $event){

    Backtrace:
    #0 /src/pocketmine/Server__32bit(0): pocketmine\Server->crashDump()
    #1 /DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader(64): BaseClassLoader->loadClass()
    #2 /DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader(64): spl_autoload_call()
    #3 /DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader(64): class_exists()
    #4 /src/pocketmine/plugin/PluginManager(152): FolderPluginLoader\FolderPluginLoader->loadPlugin()
    #5 /src/pocketmine/plugin/PluginManager(296): pocketmine\plugin\PluginManager->loadPlugin()
    #6 /DevTools_v1.10.0.phar/src/DevTools/DevTools(45): pocketmine\plugin\PluginManager->loadPlugins()
    #7 /src/pocketmine/plugin/PluginBase(86): DevTools\DevTools->onEnable()
    #8 /src/pocketmine/plugin/PharPluginLoader(123): pocketmine\plugin\PluginBase->setEnabled()
    #9 /src/pocketmine/plugin/PluginManager(562): pocketmine\plugin\PharPluginLoader->enablePlugin()
    #10 /src/pocketmine/Server__32bit(1969): pocketmine\plugin\PluginManager->enablePlugin()
    #11 /src/pocketmine/Server__32bit(1955): pocketmine\Server->enablePlugin()
    #12 /src/pocketmine/Server__32bit(1712): pocketmine\Server->enablePlugins()
    #13 /src/pocketmine/PocketMine(464): pocketmine\Server->__construct()
    #14 (1): ()
    #15 (0): {main}()

    PocketMine-MP version: 1.5dev #1232 [Protocol 27; API 1.12.0]
    Git commit: 0000000000000000000000000000000000000000
    uname -a: Windows NT ASUS-LAPTOP 6.2 build 9200 (Windows 8 Home Premium Edition) i586
    PHP Version: 5.6.6
    Zend version: 2.6.0
    OS : WINNT, win
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    *facepalm*
    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 = (new Config($this->getDataFolder()."config.yml"Config::YAML$default))->getAll();
           }
           
    $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;
             }
         }
    }
  7. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Lol you're almost there just need to fix about half the code now. XD
    HotFireyDeath likes this.
  8. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Works Thank You so much for helping
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Dude i'm doing something (If you didnt know it's better then nothing) :p
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    what the?

    You don't know what a Config does...
    Taha_The_Hacker and iksaku like this.
  11. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    you can't have length control for a popup lmao
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    iksaku likes this.
  13. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    @PEMapModder I bet they will keep using this method when 1.6 comes out xD
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I think the item protocol would change.
  15. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
  16. Blaneplooster2
    Offline

    Blaneplooster2 New Member

    Joined:
    May 26, 2015
    Posts:
    7
    Minecraft User:
    Blaneplooster2
    Does it need a config file? I am useing this with another plugin i have made to make a new gameplay.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You simply don't understand the usage of the Config class.
  18. MiniPEDevTeam
    Offline

    MiniPEDevTeam New Member

    Joined:
    Sep 8, 2015
    Posts:
    1
    It would make it easier to finish my plugin and upload if someone would answer my question above.

Share This Page

Advertisement