Block DataValues help

Discussion in 'Plugin Development' started by greaperc4, Dec 10, 2013.

Thread Status:
Not open for further replies.
  1. Hello,
    So I know the .getData() is deprecated and that it still works
    but I found another way to get the DataValue of a block.
    MaterialData.
    My question is, How to get the integer thats inside of the MaterialData

    e.g. I have a LightBlue wool in my hand and I know the DataValue is 3
    Code:java
    1. MaterialData data = player.getItemInHand().getData();

    this wil not deprecate.
    and when I send it to me it says:

    Code:
    LIGHT_BLUE WOOL(3)
    how to remove all except for the number ?

    regards,
    Greaperc4

    Okey, I found something but.. I think it's a bit much to add..

    Code:java
    1. MaterialData data = player.getItemInHand().getData();
    2.  
    3. Pattern p = Pattern.compile("-?\\d+");
    4. Matcher m = p.matcher(data.toString());
    5. while (m.find()) {
    6.  
    7. player.sendMessage("The DataValue of this Block is: " + m.group());
    8. }


    If there is no other solution to this... I think there is.. I will use this code.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  2. Offline

    felixfritz

    I believe you can also use .getDurability() to do this. It returns a short and is pretty much the same as the data.
     
  3. Thanks felixfritz,
    Great, that works to, never thought about that
     
Thread Status:
Not open for further replies.

Share This Page