Run the same task multiple times at once?

Discussion in 'Plugin Development' started by pope_on_dope, Jul 21, 2013.

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

    pope_on_dope

    Can you run a Runnable multiple times at the same time? For example, if I want to make a block regenerate after X seconds, and do something like this:
    Code:java
    1. Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    2.  
    3. public void run() {
    4. blockMined.setType(material.blah)
    5. }
    6.  
    7. }, 0L, XL;

    will each individual block execute the runnable as it's own? Or will the Runnable only be able to handle one mined block at a time?
     
  2. Offline

    Samthelord1

  3. Offline

    pope_on_dope

    I have tested it, but the results are sketchy. most of the time it works, mining blocks and they will replenish, though everyone once in a while one won't replenish. and I don't know if it's because of the way i'm handling the blocks, or the Runnable
     
  4. Offline

    Samthelord1

    Hmm, you should take a look at the sources of some other plugins, I'm sure you'll find something.
     
  5. Offline

    StrangeOne101

    If your testing for blocks a player has mined, why not use the PlayerInteractEvent?
     
  6. Offline

    pope_on_dope

    it's not whether or not I can get the block or regen it, i'm debating on whether a Runnable can handle multiple tasks at once
     
  7. Offline

    StrangeOne101

    pope_on_dope
    You might be able to, but you will probably have to define them under different tasks. I haven't yet tested this though, so please don't count on it.
    Code:
    int id = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { },0,1L);
    int id2 = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { }, 0,1L);
    int id3 = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { },0,1L);
    Edit: Opps, forgot the timing stuff on the end.
     
  8. Offline

    pope_on_dope

    yeah, that might work, but I what if there's more than 3 blocks being mined? I want it to be able endless amounts of ores mined, not just a few
     
  9. Offline

    Samthelord1

    Just make like 300 repeating tasks > : D
     
  10. Offline

    StrangeOne101

    It wouldn't necessarily be only 3 if it's a repeating task? But if you are wanting events where the players mine blocks and get infinite amounts of ores, then I would recommend using the PlayerInteractEvent. It's so much smoother and easier to use.

    One good way to crash a server .;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  11. Offline

    pope_on_dope

    i think you're not understanding what i'm trying to find out :p i know how to handle all the blocks and do the things like that, the main objective of this thread was to find out whether Runnables can handle multiple tasks at once without specifying each of them individually if that makes any sense at all
     
  12. Offline

    StrangeOne101

    I imagine it's possible, but I'm just saying I don't recommend it. Running hundreds of tasks per second can cause lots of server lag. :/
     
Thread Status:
Not open for further replies.

Share This Page