Get Block Name?

Discussion in 'Plugin Development' started by itsatacoshop247, Mar 31, 2011.

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

    itsatacoshop247

    I used:
    Code:
    string playername = event.getPlayer().getName();
    So that I could replace @Player@ in a config with the players name.
    How can I do it with @Block@? Basically what is like:
    Code:
    string blockname = event.getBlock().getName();
     
  2. Offline

    MrChick

    event.getBlock().getType().toString(); ?
     
  3. Offline

    narrowtux

    You could use the toString-method of Material. This would then work like this:
    Code:
    String blockname = event.getBlock().getType().toString();
    
    But this just gives you the name of the selected enum value and this is UPPER_CASE_WITH_UNDERSCORES. So if you want to output it in the chat or something like that, you may want to do also:
    Code:
    blockname = blockname.toLowerCase().replace("_"," ");
    
    This would convert the string to lower case and add spaces instead of underscores.

    Screw it, somebody was faster than me :D
     
  4. Offline

    MrChick

    It should. Do you get an error?
     
  5. Offline

    narrowtux

    No, this one works all over the place in my code...
     
  6. Offline

    itsatacoshop247

    Thank you both for the fast reply, it works perfectly :D
    EDIT: When I said it didn't work I had .replace(@Block@) but i realized it should be @BlockName@, so my fault.
     
  7. Offline

    MrChick

    wtf there was a post stating that it doesn't work a minute ago :confused:
     
  8. Offline

    itsatacoshop247

    I deleted the post cause I messed up with something else
     
  9. Offline

    MrChick

    Ah ok... :)
     
Thread Status:
Not open for further replies.

Share This Page