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

show item id ingame

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

  1. mariusbjornor
    Offline

    mariusbjornor Active Member

    Joined:
    Jan 6, 2015
    Posts:
    109
    Minecraft User:
    MariusB
    <?php

    namespace MariusB\ItemID;

    use pocketmine\plugin\PluginBase;
    use pocketmine\event\player\PlayerItemHeldEvent;

    class Main extends PluginBase{

    public function onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    $this->getLogger()->info("ItemID is enabled");
    }

    public function onDisable(){
    $this->getLogger()->info("ItemID is Disabled");
    }

    public function onItemHeld(PlayerItemHeldEvent $event){
    $item = $event->getItem();
    $player = $event->getPlayer();
    if($player->hasPermission('item.info')){
    $player->sendPopup($item->getName()." ".$item->getId().":".$item->getDamage()." x".$item->getCount(), 2); // More info about item that is held
    return true;
    }
    }
    }
  2. Primus
    Offline

    Primus Notable Member

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

    namespace MariusB\ItemID;

    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\Player// I always add this :)

    class Main extends PluginBase implements Listener{

    public function 
    onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    $this->getLogger()->info("ItemID is enabled");
    }

    public function 
    onDisable(){
    $this->getLogger()->info("ItemID is Disabled");
    }

    public function 
    onItemHeld(PlayerItemHeldEvent $event){
    $item $event->getItem();
    $player $event->getPlayer();
    if(
    $player->hasPermission('item.info')){
    $player->sendPopup($item->getName()." ".$item->getId().":".$item->getDamage()." x".$item->getCount(), 2); // More info about item that is held
    return true;
    }
    }
    }
    CraftYourBukkit likes this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please use [PHP] [/PHP]
  4. mariusbjornor
    Offline

    mariusbjornor Active Member

    Joined:
    Jan 6, 2015
    Posts:
    109
    Minecraft User:
    MariusB
    @Primus

    is it possible to get code to give popup everytime you tap item in hotbar?

    public function onItemHeld(PlayerItemHeldEvent $event){
    $item = $event->getItem();
    $player = $event->getPlayer();
    if($player->hasPermission('item.info')){
    $player->sendPopup($item->getName()." ".$item->getId().":".$item->getDamage()." x".$item->getCount(), 2); // More info about item that is held
    return true;
    }
    }
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Yes it is but i dont know how to use pocketmine\inventory\Inventory::eek:nSlotChange() right
    Legoboy0215 likes this.
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Or
    PHP:
    use pocketmine\event\entity\EntityBlockChangeEvent;

    public function 
    onSlotChange(EntityBlockChangeEvent $event){
    $player->getEntity();
    if(
    $player instanceof Player){
    $item $event->getNewItem();
    $player->sendPopup($item->getName()." ".$item->getId().":".$item->getDamage()." x".$item->getCount(), 2);
    }
    }
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You can't use it unless you make a subclass of Inventory, which is not applicable for your case.

Share This Page

Advertisement