Storing a block in a hashmap

Discussion in 'Plugin Development' started by PickNChew, Apr 11, 2014.

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


    So basically, I want to store blocks that a player has placed into a hashmap. It's sort of like the mcmmo but I've never touched upon hashmaps. Any help is greatly appreciated. Also, is it possible to detect a block that has been moved by a piston? Thanks ;)
  2. Offline


    HashMap<StringBlockmap = new HashMap<>();
    public void onBlockBreak(BlockBreakEvent e) {
    map.put(e.getPlayer().getName(), e.getBlock());
    For further reading on the HashMap class
  3. Offline


    Wizehh so i need to retrieve info from the hashmap which I don't know how, then make an if statement to see if a player placed that block, still not sure how.
  4. Offline


    Read up on how to use a Map. Google is a good resource as is StackOverflow.
  5. Offline


    Here's a clue, without giving you code

  6. Offline


    k I'll tell you what I'm trying to do. I have fortune on blocks. You see now right? Now we have a infinite dupe here. I'm trying to log the coordinates of blocks that are diamond blocks, gold blocks, coal blocks, lapis blocks, emerald blocks, and redstone blocks into a hashmap. By doing this, I can check if the coordinates are in the hashmap and if it is then don't do the fortune. and I thought hashmaps would work. I've tried, but I had no success. So if anyone would explain to me clearly, it would be amazing.
  7. Offline


    instead of storing thousands upon thousands of blocks in a hashmap, instead,

    just do

    if(block.getType() == Material.DIAMOND_BLOCK || block.getType() == Material.GOLD_BLOCK){//ect..
  8. Offline


    Sabersamus Yes, that is exactly what I'm doing. However, I have no idea where to put the retrieved coordinates of the block and how to get the blocks coordinates. I need the coordinates to prevent duping. So I check if the coordinates was placed by a player, then I need to store it somewhere.

    I don't think you understand what I'm trying to do. Fortune only works on Emerald Blocks, Gold Blocks, etc. So I need to check if it is a Emerald Block, etc. <--- I know how to do this. I'm trying to log the coordinates of the blocks and put it somewhere to store.

    Any help is appreciated

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


    Ah okay, yes I see.

    private List<Location> locations = Lists.newArrayList();
    public void onBreak(BlockBreakEvent event){
        //check block type first
            //no fortune
            //do fortune
            //it might be event.getBlock().getLocation(), i'm just too lazy to check
    PickNChew likes this.
  10. Offline


Thread Status:
Not open for further replies.

Share This Page