Delayed particle spawn?

Discussion in 'Plugin Development' started by GreatMinerZ, Feb 24, 2014.

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

    GreatMinerZ

    Hey, i have a question about delaying particle trails.
    When i create a particle trail using an BlockIterator, it will spawn the particles all at the same time.
    But i want them to spawn really quick after eachother. Is this possible, and how would i do this?

    Thanks!
     
  2. Offline

    lukewizzy

    Create a scheduleSyncDelayedTask :)
     
  3. Offline

    GreatMinerZ

    lukewizzy Where should i place this, before, after or in this part of code? I'm a noob at shedulers...
    Code:java
    1. while(blocksToAdd.hasNext()) {
    2. blockToAdd = blocksToAdd.next().getLocation(); //set blocktoadd
    3. if (blockToAdd.getBlock().getType() != Material.AIR) {
    4. break;
    5. }
     
  4. Offline

    lukewizzy

    I believe you could put it just inside the while statement (so lines 2 to 5 in that snip would be inside the task).
     
  5. Offline

    GreatMinerZ

    Code:java
    1. while(blocksToAdd.hasNext()) {
    2. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    3. scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
    4. blockToAdd = blocksToAdd.next().getLocation(); //set blocktoadd
    5. if (blockToAdd.getBlock().getType() != Material.AIR) {
    6. break;
    7. }, 20L);
    8.  
    9. }


    If i do this, it gives me errors like "Syntax error, insert ; to complete statement."
     
  6. Offline

    Alshain01

    Your delay is in the wrong place, it's on the if closing bracket. And may I just add, your avatar freaks me out.
     
    NathanWolf likes this.
  7. Offline

    GreatMinerZ

    Alshain01 Where should i place the delay then, and my avatar is actually a clown from the dutch tv series "Bassie & Adriaan" Made for kids under 10 year old.. ;)
     
  8. Offline

    Alshain01

    On the next bracket down.

    Code:java
    1. while(blocksToAdd.hasNext()) {
    2. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    3. scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
    4. blockToAdd = blocksToAdd.next().getLocation(); //set blocktoadd
    5. if (blockToAdd.getBlock().getType() != Material.AIR) {
    6. break;
    7. }
    8. }, 20L);
    9. }


    (And yeah, clowns just freak me out in general)[/quote]
     
  9. Offline

    GreatMinerZ

  10. Offline

    Alshain01

    EDIT: this was really wrong.
     
  11. Offline

    GreatMinerZ

    Alshain01 The method scheduleSyncRepeatingTask(Plugin, Runnable, long, long) in the type BukkitScheduler is not applicable for the arguments (WandUse, Runnable)

    and

    }, 20L);

    The left-hand side of an assignment must be a variable ^
     
  12. Offline

    Alshain01

    Oh! I totally don't know what I was doing. No, my previous code was right. What was the syntax error?
     
  13. Offline

    GreatMinerZ

    Alshain01 Syntax error, insert "AssignmentOperator Expression" to complete Expression

    at }, 20L);
     
  14. Offline

    Alshain01

    I think the problem is scope actually. I'm trying to think of how to do this, I think the scheduler inside the loop is the issue.

    Ok, what is the break statement for? Your trying to break out of a while loop from another class basically, which can't be done.

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

    GreatMinerZ

    Alshain01
    Code:java
    1. public class WandUse implements Listener {
    2. static Main plugin;
    3.  
    4. public WandUse(Main instance) {
    5. plugin = instance;
    6. }
    7.  
    8. @EventHandler
    9. public void onWandShot(PlayerInteractEvent e) {
    10. Player p = e.getPlayer();
    11.  
    12. //wand
    13. String Wandname = ChatColor.DARK_RED + "[" + ChatColor.GOLD + "" + ChatColor.BOLD + "Toverstaf" + ChatColor.DARK_RED + "]";
    14.  
    15.  
    16. //spell effect
    17. if(p.getItemInHand().getType().equals(Material.BLAZE_ROD)){
    18. if(p.getItemInHand().getItemMeta().getDisplayName() == null){
    19. e.setCancelled(true);
    20. }
    21.  
    22. if(p.getItemInHand().getItemMeta().getDisplayName() != null){
    23. if(p.getItemInHand().getItemMeta().getDisplayName().contains(Wandname)){
    24.  
    25. if(e.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_AIR ||
    26. e.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK){
    27.  
    28. Location eloc = p.getEyeLocation(); //Get player's eye location
    29. BlockIterator blocksToAdd = new BlockIterator(eloc, 0D, 50); //intialize the blockiterator
    30. Location blockToAdd; //intialize a location called blockToAdd
    31.  
    32. while(blocksToAdd.hasNext()) {
    33. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    34. scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
    35. blockToAdd = blocksToAdd.next().getLocation(); //set blocktoadd
    36. if (blockToAdd.getBlock().getType() != Material.AIR) {
    37. break;
    38. }, 20L);
    39.  
    40.  
    41. ParticleEffects.sendToLocation(ParticleEffects.GREEN_SPARKLE, blockToAdd, 0.5F, 0.5F, 1.0F, 0, 20); //play effect
    42. }
    43. }
    44. }
    45. }
    46. }
    47. }
    48. }
     
  16. Offline

    Alshain01

    Ok, I think I understand what you want. I was totally thinking something else. Try this.

    Code:java
    1. while(blocksToAdd.hasNext()) {
    2. blockToAdd = blocksToAdd.next().getLocation(); //set blocktoadd
    3. if (blockToAdd.getBlock().getType() != Material.AIR) { break; }
    4.  
    5. new BukkitRunnable({
    6. ParticleEffects.sendToLocation(ParticleEffects.GREEN_SPARKLE, blockToAdd, 0.5F, 0.5F, 1.0F, 0, 20); //play effect
    7. }).runTaskLater(this, 20L * count);
    8. count++;
    9. }
    10.  


    You need to set up the "count". This will schedule it once a second until it hits non air (assuming I didn't miss anything).
     
  17. Offline

    GreatMinerZ

    Alshain01 "Cannot instantiate the type BukkitRunnable" & "Syntax error on token "long", delete this token" and how would i set up the count? I'm noob using schedulers.
     
  18. Offline

    Alshain01

    just create an int named count. Your actually scheduling all of these at once time (or withing milliseconds technically) but your going to delay it by 20 * count. So count needs to start at 0 and increment for each iteration through the loop. So up where you created your variables before the while loop, do: int count = 0;

    For the other issue, I did miss something

    Code:java
    1. int count = 0;
    2. while(blocksToAdd.hasNext()) {
    3. blockToAdd = blocksToAdd.next().getLocation(); //set blocktoadd
    4. if (blockToAdd.getBlock().getType() != Material.AIR) { break; }
    5.  
    6. new BukkitRunnable() {
    7. @Override
    8. public void run() {
    9. ParticleEffects.sendToLocation(ParticleEffects.GREEN_SPARKLE, blockToAdd, 0.5F, 0.5F, 1.0F, 0, 20); //play effect
    10. }
    11. }.runTaskLater(this, 20L * count);
    12. count++;
    13. }
     
Thread Status:
Not open for further replies.

Share This Page