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

    Jedodalci

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

    HELP!
     
  2. Offline

    1Rogue

    What have you done so far?
     
  3. Offline

    Jedodalci

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

    AoH_Ruthless

    Jedodalci
    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

    excusemyluck

    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

    xXMaTTHDXx

    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

    excusemyluck

    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

    xXMaTTHDXx

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

    excusemyluck

  10. Offline

    EgyptianKing

    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

    teej107

    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.
    Code:java
    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