Interval code

Discussion in 'Spigot Plugin Help' started by zDrakon, May 27, 2015.

  1. I am developing a plugin and so far is going pretty well, except 1 thing. I can't figure out how to set intervals to be used in my plugin.

    For example for every 5 dirt blocks a player places i want a command to run such as
    /eco give playername 500

    giving them $500

    Anyone know how to do the interval thing in java code? PM or email thanks please. OR POST XD
  2. Just set a hashmap, and then whenver a player places a block, just add 1 to it. Then, just run a conditional if the player has placed 5 dirt blocks.
    • Agree Agree x 2
  3. But i would many conditionals to do this...? Say if i wanted every 5 blocks so I would put 1 for 10, 15, 20, etc...
  4. Nah.. only one conditional would be needed really. If you wanted to do every 5. you would just reset the variable everytime 5 is hit.


    Code (Text):
    place dirt:
       update player variable + 1
       if player variable is equal to 5:
          execute command
          reset player variable to 0
    that would ensure that every 5th block would execute the command

    OR you could do a modulo and just check if the player variable can be divided by 5 with no remainder. That would make it a multiple of 5, meaning it would have to be an iteration of a 5th block.
    • Agree Agree x 1
  5. Okay... what if I wanted it to stack so that a player will have placed 24 blocks, (Not resetting it to 0) and on the 25th they get $500... I don't want it to reset, the point is to make a block placing counter to reward them as an example.
  6. Then what you could do is create a multidimensional Map like <playername, Block, integer> and that way, one HashMap can store all of the placement you want.
  7. Okay I admit it i want to make a killstreak plugin and every 5 kills I want it to give a money multiplied reward!

    anyone also know how to make a broadcast in eclipse code of a similar format to this

    ******HEY YOU*******
    ******HEY YOU*******
    With configurable multiline support in config.yml

    also how do i create a placeholder like %player% or %coords% to display the coords they are at?
    #7 zDrakon, May 28, 2015
    Last edited by a moderator: May 28, 2015
  8. We are not here to spoon-feed you code, take a look at some docs.
  9. did you mean by
    if(killcount == setinterval * 2) {
    do stuff
  10. Omnivion


    Even you didn't know that at some point. Be a little less harsh, please :)

    Code (Text):
    String message = "taco <noob>";
    player.sendMessage(message.replace("<noob>", player.getName()));
    Post everything else you need in a reply, I'll help you out! It just got a little jumbled in the above posts.
    • Friendly Friendly x 3
    • Agree Agree x 1
  11. I want to be able to use placeholders in my config, how do I make a method that checks if the string %coords% or %player% is used in the config?
  12. .contains
    • Informative Informative x 1
  13. If it really works thank you, change of heart? =)?
  14. Omnivion


    • Agree Agree x 2