Solved Place block by block

Discussion in 'Plugin Development' started by ZP18, Sep 12, 2015.

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

    ZP18

    Ok so I have a foreach loop for a list of locations and I am setting each one to stone, but what I want to achieve is a way to make it "animated" so the player can see the block by block building of the structure, I have tried doing scheduled delayed tasks, delayed tasks, delayed task asynchronous but none are working, there will just be a delay of when the blocks get placed, but they will all get placed all at once
     
  2. Offline

    Signatured

    Show us what you've tried so we can help you. I suggest having an arraylist of all the locations you want to place stone at, and have them in the order you want them to be placed. Then declare an int starting at 0, and using a scheduler with a small delay, get the location at the index of the int you declared. Then increase the int by 1 before its runs through the scheduler again.
     
  3. Offline

    mythbusterma


    But I can't do them correctly*

    You use a synchronous delayed task. That is the only way you do it.
     
  4. Offline

    ZP18

    @mythbusterma, I tried that first but I got some error in console, I will try it again tho
     
  5. Offline

    mythbusterma

  6. Offline

    ZP18

  7. Offline

    mythbusterma

    @ZP18

    NO.

    I don't mean "async," synchronous. There's a very big difference.
     
  8. Offline

    ZP18

    If you mean scheduleSyncDelayedTask I have tried that and it doesn't work

    @mythbusterma

    EDIT: Here is my code:
    Code:java
    1. for (Location block : vault){
    2. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    3. public void run() {
    4. block.getBlock().setType(Material.STONE);
    5. }
    6. }, 10);
    7. }
     
  9. Offline

    oceantheskatr

    @ZP18 show us your code, it will help us explain what you're doing wrong, and how to implement the correct way. (Post it on http://pastebin.com/ and link here please)
     
  10. Offline

    ZP18

  11. Offline

    mythbusterma

    @ZP18

    That will change all the blocks half a second later.

    Do you understand what the code you're writing does?
     
  12. Offline

    ZP18

    @mythbusterma Everything except the runnable stuff, I don't have experience with Runnables

    @mythbusterma what is the time measured in? Milliseconds?

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

    mythbusterma

    @ZP18

    Why are you making one of them for every block?
     
  14. Offline

    ZP18

    @mythbusterma like I said I don't have experience with Runnables
     
  15. Offline

    mythbusterma

    @ZP18

    You should use a repeating task instead. Only do a few every time.
     
  16. Offline

    ZP18

    If I do a repeating task won't it keep making that block stone even tho it is already stone?

    @mythbusterma
     
  17. Offline

    mythbusterma

    @ZP18

    But a different block each time.
     
  18. Offline

    ZP18

  19. Offline

    SyTeck

    Also Bukkit tasks operates with ticks, 20 ticks = 1 second.
     
    The_BloodHound likes this.
  20. Offline

    ZP18

  21. Offline

    xMrPoi

    You're creating all those tasks at the same time so they're all going to trigger one second after. You have to make the time it delays the action different for every block. You can achieve this by using a for loop that goes while X is less than vault.size() and then set the delay time to X*20.
     
  22. Offline

    ZP18

    @xMrPoi Thank you so much! It is working, now I would like to know how to cancel the runnable when it is done, because I want to send a message to the player when it is done, but the messages don't stop coming
     
  23. Offline

    Zombie_Striker

    @ZP18
    boolean is done = false;
    if(no more blocks && !is done){
    is done = true;
    Send message
    }


    Scheduler.cancel();

    If you don't know how to use something, GOOGLE IT. Google is your friend.
    CLICK HERE!

    .
     
  24. Offline

    ZP18

    @Zombie_Striker I know about google, one of my best friends, but I normally just ask on the forums for something, I have no scheduler variable in my code, I mean how do I do it using my code?
     
  25. Offline

    Zombie_Striker

    @ZP18
    I think what you're looking for is something like this

    Code:
    for(int i = 0; i < size; i++){
    Schedulers stuff {
    public void run(){
    ArrayList.get(i).setBlock(Block);
    }
    
    },0- delay, (20L * (i+1)) meaning ever second a new block will be placed.
    }
     
  26. Offline

    ZP18

    Last edited by a moderator: Jun 11, 2016
Thread Status:
Not open for further replies.

Share This Page