Getting an item with a 'specail' id

Discussion in 'Plugin Development' started by UHoplite, May 9, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    UHoplite

    Hi. I want to get an item in a player's hand, and to check if it's Allium.
    Now, because Allium's id is 38:2, I just can't user these lines of code-

    Code:java
    1. if ( ( Integer.toString(player.getItemInHand().getType().getId() ) ).equals("38:2"){
    2. //lines of code


    I've tried using '.toString' amd '.getName' and equalize them to 'Allium', but nothing seemed to work.

    Do you know how to do it, if it's possible at all?
    Thanks ahead.
     
  2. UHoplite Try using
    Code:
    getData().getData()
    (returns a byte) - even though it's deprecated, it should work...

    Code:
    if(player.getItemInHand().getData().getData() == 2) {
        //lines of code
    }
     
  3. Offline

    FabeGabeMC

    Yes but if you are gonna use it for a player interact event getting the clicked block just use one getData(); ;)
    Ex:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onBlockClick(PlayerInteractEvent e){
    4. Player p = e.getPlayer();
    5. Action a = e.getAction();
    6. Block b = e.getClickedBlock();
    7. if(a == Action.RIGHT_CLICK_BLOCK && b.getType() == Material.PISTON_BASE &&
    8. b.getData() == 6){
    9. p.sendMessage("Well hello there! This is not HiveMC!");
    10. }
    11. }


    btw that was an actual code for one of my plugins (NotTheHive) ;P
     
    UHoplite likes this.
  4. Offline

    UHoplite


    So Allium's ID is 38, and its data is 2?
     
  5. Offline

    rfsantos1996

    Yep
     
  6. Offline

    UHoplite


    I managed, I actually wrote this and it works now:

    Code:java
    1. player.getItemInHand().getType() == Material.RED_ROSE && player.getItemInHand().getDurability() == (short) 2
     
Thread Status:
Not open for further replies.

Share This Page