Solved Remove player certain blocks per player

Discussion in 'Plugin Development' started by khave, Sep 13, 2014.

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

    khave

    Sorry for my english to start off. It's very hard to explain in english when it's not your main language.

    So what I had in mind, was that I wanted a HashMap with a String and a Block. Then I'd store some blocks along with, for example, the players name. Then when I wanted it to be removed, I'd remove the blocks, BUT only for that one player. I've tried using an ArrayList with blocks, but it removes ALL blocks in that array list. I only want to remove per player blocks.

    I hope you understood that and thank you in advance.
     
  2. Offline

    TheMcScavenger

    Not really, it just requires knowledge of the language. It's not different from any other languages.

    Anyways, it's impossible. You can't have different worlds per player. It's one world, that's being sent to the player.
     
  3. Offline

    khave


    I don't think you get what I'm saying. I just want certain blocks to be set to Air when, but done with a HashMap and only the blocks of the player's disappearing.

    I guess you could say LogBlock does it too? It removes all the blocks the player placed. I'd rather not have to set it in a config, if possible.

    Also, yea it requires knowledge to of the language, and that can take years to get. It's different from person to person. I don't think I'm adequate at explaining yet. I can't seem to get my point across most of the time.
     
  4. Code:java
    1. Map<Player,List<Block>> stuff = new HashMap<Player,List<Block>>();


    If done correctly, you can put 'stuff.get(player)' in a for loop and set them all to air.
     
  5. Offline

    khave

    Okay. I'm doing this:

    Code:java
    1. static HashMap<String , List<Block>> blocks = new HashMap<String, List<Block>>();
    2.  
    3.  
    4. public static void removeBlocks(Player p) {
    5. for(Map.Entry<String, List<Block>> entry : blocks.entrySet()){
    6. if(entry.getKey().equals(p.getName())) {
    7. for (Block b : entry.getValue()) {
    8. b.setType(Material.AIR);
    9. }
    10. }
    11. }
    12. blocks.clear();
    13. }


    And adding like this:

    Code:java
    1. blocks.put(p.getName(), (List)p.getLocation().subtract(0, i, 0).getBlock());
    2.  


    But it doesn't seem to work?
     
  6. When addding a block:
    - check if 'blocks' containsKey with the player's name
    - if it does:
    Code:java
    1. blocks.get(p.getName()).add(p.getLocation().subtract(0, i, 0).getBlock());

    - if it does not:
    Code:java
    1. blocks.put(p.getName(), new ArraList<Block>());
    2. and
    3. blocks.get(p.getName()).add(p.getLocation().subtract(0, i, 0).getBlock());
    4.  

    When you set them to air you can use blocks.get(p.getname()) in the for loop.
     
  7. Offline

    khave


    Aha. Thanks. Is there any way I can clear the HashMap for the specific player? If I just do a HashMap.clear, it'll also clear the blocks for everyone else.
     
  8. Code:java
    1. blocks.remove(p.getName());
     
    khave likes this.
Thread Status:
Not open for further replies.

Share This Page