every 500 block break run a command HELP

Discussion in 'Plugin Development' started by Jedodalci, Aug 7, 2014.

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


    I wanted to make a plugin that every 500 blocks of obsidian split you run a command but do not know the method

  2. Offline


    What have you done so far?
  3. Offline


    The Listener but I do not know how to control blocks destroyed
  4. Offline


    Global counter that increments every time an obsidian block is destroyed. Check if this number is 500, and if so execute your command.
  5. Offline


    I was going to say do almost that, but I had a little different of a procedure. I would save each player into a hashmap with the number of blocks they have broken. When a player breaks a block, update the number of blocks they have broken in the hashmap. If you would like to save that number for each player, save the hashmap to a config on plugin disable, otherwise just do nothing and the hashmap will reset every reload/start/stop/restart.
  6. Offline


    excusemyluck why do that when he only wants it to not break per every 500th block, there isnt need to add +1 to a hashmap everytime when as AoH_Ruthless said he could just use a global int?
  7. Offline


    xXMaTTHDXx Because if you use a global int it will count the 500 for everyone. But the hashmap is per-player. I could have also read the O.P. first, in which case I apologize.
  8. Offline


    excusemyluck no need to apologize :p I was just making a statment
  9. Offline


  10. Offline


    You should increment onto an integer that is stored in a config or in a SQL database, so that you don't lose your block-break count on restarts.
  11. Offline


    If you want it for every 500th block mined, follow the suggestions above to store an integer and use a modulo (%) to check if it's the 500th block mined. It's division but it has remainders.
    1. if(yourIntegerHere % 500 == 0)
    2. {
    3. //Code here
    4. }

    You check to see if the statement equals 0 because anything divisible by 500 will have 0 remainders.

    You can also just clear the player's integer once they reach 500 rather than using a modulo.
Thread Status:
Not open for further replies.

Share This Page