How do I get a declared block in command to use in event ?

Discussion in 'Plugin Development' started by zDubsCrazy, Apr 18, 2014.

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

    zDubsCrazy

    I want to use a block that I stored in an ArrayList, when you run the command, i am not able to use the same block at the event ... How make?
    ArrayListName.contaisKey (block); does not work!

    Thanks.
     
  2. Offline

    caseif

    You should instead store the location and then get the block at it.
     
  3. Offline

    agent6262

    ShadyPotato His answer is probably the way to go
    ??? For example is the block just a Dirt block or a specific instance of a dirt block?
     
  4. Offline

    zDubsCrazy

    ShadyPotato I'm a beginner, could explain better how to do this?
     
  5. Offline

    agent6262

    Could you explain how the user gets the block i.e. via command or event
     
  6. Offline

    zDubsCrazy

    agent6262 I saved it in an ArrayList, thus:

    Code:java
    1. ArrayList<Block> blockList = new ArrayList<Block>();
    2.  
    3. // When you run the command, I put this:
    4.  
    5. blockList.add(player.getLocation().getBlock());
     
  7. Offline

    nuclearmissile

    What do you want to use the block for?
     
  8. Offline

    agent6262

    zDubsCrazy
    The line of code you are using to add the block at the players position returns the block where your legs are. With that being said if you are not partly "in" a block I DON'T THINK it will add any thing but i may be wrong.
     
  9. Offline

    zDubsCrazy

    nuclearmissile
    I want to use the block at an event for when the player stepped on, a sequence of actions occur.

    agent6262 I think I will yes, because when you enter the command, the block where the player is automatically stored in the ArrayList.

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

    caseif

    zDubsCrazy
    Regarding what agent6262 mentioned, it will add a block, but that block will in fact be the block containing the player's legs. Here's some code that will store a location and fix that at the same time:
    Code:java
    1. List<Location> locations = new ArrayList<Location>(); // as a global
    2.  
    3. locations.add(player.getLocation().subtract(0, 1, 0); // upon running the command
     
    zDubsCrazy likes this.
  11. Offline

    agent6262

    zDubsCrazy just did a little googling and found this see if it works
    Code:java
    1. player.getLocation().getBlock().getRelative(BlockFace.DOWN)
     
    zDubsCrazy likes this.
  12. Offline

    zDubsCrazy

    ShadyPotato
    Ok, so I understand, but for me to use this location on my event?

    agent6262
    Thanks for the help, now I understand better!
     
  13. Offline

    caseif

    Depends what you want to do. If you want the block, just use Location#getBlock().
     
Thread Status:
Not open for further replies.

Share This Page