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

Get meta value of item

Comments in 'Plugin Development' started by BalAnce, Jul 25, 2015.

  1. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    So i have a PlayerItemHeldEvent and im trying to get the meta value of a colored wool block cause i need a certain color of wool to preform a action how do i get the meta value of the item. I can get the iD but how do i get the meta cause when i just get the id its the same as a regular wool block. id:meta.
  2. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Use:
    PHP:
    $ev->getItem()->getDamage(); //this return e.g. 3
    //If you want have something like 35:1, use:
    $item = ($ev->getItem()->getId().":".$ev->getItem()->getDamage()); //this return e.g. 35:4
    //If you want know wool name, use:
     
    $name $ev->getItem()->getName();
    PEMapModder, jojoe77777 and BalAnce like this.
  3. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Thanks bro completely forgot about getDamage.
  4. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    you know how to get from a blockplaceevent?
  5. Achak
    Offline

    Achak New Member

    Joined:
    Feb 14, 2015
    Posts:
    32
    Minecraft User:
    Achak_Adhay
    I just made this plugin that gets item name id and meta for the item in players hand, I haven't figured out the submission process here or if it is really wanted or needed.
    but here it is

    it still has /test command
    the main command is
    /iditem

    PHP:
      public function onCommand(CommandSender $senderCommand $command$label, array $args){
      if(
    strtolower($command->getName()) === "iditem"){
      if (
    $sender instanceof Player){
      if (
    $sender->hasPermission("iditem.command.item")){  
      if (
    count($args) <1) {
      
    $inHandid $sender->getInventory()->getItemInHand()->getId();
      
    $inHandname $sender->getInventory()->getItemInHand()->getName();
      
    $inHandmeta $sender->getInventory()->getItemInHand()->getDamage();
      
    $sender->sendMessage("[Iditem]You are holding $inHandname ID $inHandid meta $inHandmeta");
      return 
    true;}
      else {
    $sender->sendMessage("[Iditem]what?what?");
      
    /*Ene count $args*/return true;}
      }else {
    $sender->sendMessage("[Iditem]You are not a Player");
      
    /*End hasPermission*/}
      
    /*End instanceof Player*/return true;}
      
    /*End strtolower "/iditem"*/}

      
    /* End public function onCommand*/ return true;}

    Attached Files:

    Last edited: Jul 26, 2015
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use [php][/php] please >.<

Share This Page

Advertisement