Solved getting location of a block when left clicked

Discussion in 'Plugin Development' started by ninja2003, Jul 24, 2014.

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

    ninja2003

    So i've googled for a while and i can't find how to get the location of the block when i left click i use the onPlayerUse(PlayerInteractEvent event) thing so here is what i got atm
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onPlayerUse(PlayerInteractEvent event) {
    3. if(event.getAction() == Action.LEFT_CLICK_BLOCK) {
    4. // Anything
    5. }
    6. }
    And i hope you can help me.
     
  2. Offline

    Bavestry

    Try using the event.getInteractedBlock() method...?

    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void onPlayerUse(PlayerInteractEvent event) {
    3. if(event.getAction() == Action.LEFT_CLICK_BLOCK) {
    4. Block b = event.getInteractedBlock();
    5. Location loc = b.getLocation(); //make sure you're importing the right Location, the one from org.bukkit.
    6. //if you need the double forms of the x, y, z, pitch, or yaw, use loc.getX(), loc.getY(), loc.getZ(), etc.
    7. }
    8.  
    9. }


    If you're ever confused about something, try looking it up in the javadocs before posting a thread here. This link will take you straight to the PlayerInteractEvent class.
     
  3. Offline

    ninja2003

    Thanks alot, helped alot!

    The getInteractedBlock doesn't exist I suppose i you mean't getClickedBlock() method.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. please mark thread as solved, when its solved
     
  5. Offline

    Bavestry

    ninja2003 Depends on what version of bukkit you're running. In the links I provided, 1.7.10-R0.1 was used. That version uses getInteractedBlock() while older versions use getClickedBlock(). :p
     
  6. Offline

    ninja2003

    Oh didn't even know the 1.7.10 was out :p Can't wait for the full version of minecraft 1.8 and bukkit :)
     
Thread Status:
Not open for further replies.

Share This Page