Solved BlockState

Discussion in 'Plugin Development' started by 97WaterPolo, Sep 7, 2014.

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



    Trying to update blocks and such, so hopefully someone can help.

    The code seems simple enough, if a player has a sword in their hand, and right clicks a block, it changes to stone. Then once the player dies it needs to revert to the original block that was there. How would I do it? The current way I am doing it is

    //I handle the per player stuff somewhere else, but I am just trying to figure out why the block isn't //updating and staying the same block I set it to.

    List<BlockState> block =...

    if sword and p.hasPerm

    for (BlockState b : block)

    But for some reason, it is staying stone, it isn't reverting to the original block.

    Any help would be appreciated!
  2. Offline


    97WaterPolo Can you verify the code is being ran? Also, what does the update method return? (True/False)
  3. Offline


    masons123456 the boolean flag indicates whether it should force updates (if the flag is false, and the Material is different, it would silently fail)
  4. Offline


    fireblast709 Well that would most likely be his fix then, forcing the update, but I was asking about what the method returned, most likely false due to the fact that it doesn't do anything.
  5. Offline


    Maybe you need to set the block data back to the block data it was at before, maybe something like this..
    Although that seems kinda backwards, its the only thing I could think of. Either that or use a HashMap with location and block state and then update the block at location with the block state.
  6. Offline


    masons123456 masons123456 firecombat4
    It seems to be running, I have also tried b.setType(block.getType()); and that still doesn't fix it. I feel that the blockstate in the arraylist is being updated when I set the type, but I am not sure why it is as I am not adding/updating it willingly.
  7. Offline


    97WaterPolo debug the state you are pushing into the List
  8. Offline


    Okay, managed to get it to work, I was doing something wrong, and this part works, but now I am getting

    Caused by: java.util.ConcurrentModificationException
    with the line pointing to for (blockState b : og)

    1. for(Location l : portal.get(player.getName())){
    2. for (BlockState b : og){
    3. if (b.getLocation().distance(l) < .75){
    4. b.update(true);
    5. og.remove(b);
    6. }
    7. }
  9. Offline


    97WaterPolo you remove BlockState b from og while iterating over it. Use Iterators instead ;3
  10. Offline


Thread Status:
Not open for further replies.

Share This Page