[SOLVED]how to count the blocks of new players

Discussion in 'Plugin Development' started by blackwolf12333, May 17, 2012.

Thread Status:
Not open for further replies.
  1. Hi,
    So, what i want to do is count the blocks of new players, i got it working when only one players logs on and is a new player, but when 2 new players join the block count of the first player is added to the block count of of the second player, so, how do i count the blocks of these individual players?

    thanks in advance, blackwolf12333
     
  2. Offline

    TheBeast808

    You'll have to use a map. Maps link a key to a value(player name to a value)
    Initiate it like this:
    Code:
    public static Map<String, Integer> playerBlockCount = new HashMap<String, Integer>();
    
    To add players to the Map on join:
    Code:
    public void onPlayerLogin(PlayerLoginEvent event) {
        String name = event.getPlayer().getname();
        playerBlockCount.put(name, 0);
    }
    To update the block count when they break a block:
    Code:
    public void onBlockBreak(BlockBreakEvent event) {
        String name = event.getPlayer().getName();
        int BlockCount = playerBlockCount.get(playername);
        BlockCount++;
        playerBlockCount.put(playername, BlockCount);
    }

    Or something like that.
     
  3. Hmm, i tried something like that, but i'll try it as you say i should do it, thanks.
    greetz blackwolf12333
     
  4. Offline

    TheBeast808

    Oh, and I forgot, you'll want to remove the player from the list when they log out.
     
  5. Ok yes, thanks so much, i have spend a few days getting this to work:p, now it does work.
    greetz blackwolf12333
     
Thread Status:
Not open for further replies.

Share This Page