Solved HashMap

Discussion in 'Plugin Development' started by bronzzze, May 13, 2015.

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

    bronzzze

    So I crated hashmap
    Code:
        public HashMap<UUID, UUID> granades = new HashMap<UUID, UUID>();
    
    And then I crated this method:
    Code:
     public void setGrenade(Entity item, Player player) {
                granades.put(item.getUniqueId(), player.getUniqueId());
            }
    and then When I right click I used this method
    Code:
    @EventHandler
        public void onThrow(PlayerInteractEvent event) {
            final Player player = event.getPlayer();
            ItemStack hand = (ItemStack) player.getItemInHand();
            if (event.getAction() == Action.RIGHT_CLICK_AIR
                    || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    ....
    main.setGrenade(grenade, player);
    
    ...
    }

    I want to make so when multiple players use this bomb don't cancel each other. I am not sure what I am doing wrong. There is no error just nothing happend.
    Is this happend maybe beacuse granade is static?

    Edit:
    Ok lol now is working I just need to remove static from public static Entity granade;
     
    Last edited: May 13, 2015
  2. Offline

    mine-care

    @bronzzze static is your worse enemy when used improperly.
    Also you dont have to cast itemstack to itemstack (line 4 of your onThrow methοd :p)
     
    bronzzze likes this.
Thread Status:
Not open for further replies.

Share This Page