Int counting for every player?

Discussion in 'Spigot Plugin Development' started by michiel, Apr 17, 2018.

  1. Hello,

    Curently I am working with Config files and have seen in a video that he is logging all placed blocks.
    And he uses int count for every time the player places a block. And then count++.
    Will this int count for each player from 0 - ... or will it continue from other players? Like if you store something in a int from a specific player, will it also be the same value for the other player?

    Check here the code for what I mean: ClickMe

  2. this is for every player that places a block.
  3. Yes, I understand that but will it start counting from zero for each player or if player a places 5 blocks and player b 1 later will it be for player b be 6?
  4. player a: 1 2 3 4
    player b will continue it: 5 6 7

    because the count is a public number.

    you can test it for yourself
    • Like Like x 1
  5. because its in the global scope it will be updated with everyblockplace, so if player1 places a block it will be 1, if player2 places 5 blocks after that it will be 6.
    • Like Like x 1
  6. Yes, okay thats what I wanted to know thanks!
    Is there any other way to make this for each player start from zero?
    Maybe adding a count in each players config?
  7. you can change the config a little bit and adding hashmap.

    the config will look something like this:
    Code (Text):

    and you will need a hashmap, the key will be player's uuid and the value is the count.
  8. Code (Text):
    HashMap<Player, Integer> count = new HashMap<>();
        public void onBlockPlace(BlockPlaceEvent event) {
            Player player = event.getPlayer();
            if(count.containsKey(player)) {
                count.replace(player, count.get(player)+1);
            }else {
                count.put(player, 1);
    now you have a hasmap with for each player the blocks they placed,
    get the blocks a player placed by doing:
    Code (Text):
  9. Alright ...... Thanks a lot for the help. I'll figure out and use this method! Thanks a lot! :)