Cancelling Particles

Discussion in 'Plugin Development' started by top2001, Dec 7, 2014.

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

    top2001

    Hello Bukkit!

    I was wondering how I would remove the particles from the world when the player leaves the server with the following code I written.

    Code:java
    1. package me.top2001.OreCloudParticles;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Effect;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9. import org.bukkit.plugin.PluginManager;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Main extends JavaPlugin implements Listener{
    13.  
    14. public void onEnable() {
    15. getLogger().info("Plugin Enabled!");
    16. PluginManager pm = getServer().getPluginManager();
    17. pm.registerEvents(this, this);
    18. }
    19.  
    20. public void onDisable() {
    21. getLogger().info("Plugin Disabled!");
    22. }
    23.  
    24. @EventHandler
    25. public void onPlayerJoin(PlayerJoinEvent e) {
    26. final Player player = (Player) e.getPlayer();
    27. if(player.hasPermission("staffparticles.fire")){
    28. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    29. public void run() {
    30. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 2004);
    31. }
    32. }, 20, 20);
    33. }
    34. }
    35. }
    36.  
     
  2. Offline

    WesJD

    top2001 Make the scheduler equal to a BukkitTask and cancel it.
     
  3. Offline

    top2001


    How do I do that? I'm kind of new to the Bukkit API.
     
  4. Offline

    Rocoty

    top2001 You should look into BukkitRunnable. It's a lot more flexible when it comes to scheduling and cancelling tasks. You should also somehow store a reference to the task or BukkitRunnable mapped with the player. So that you can retrieve it and cancel it when the player leaves.
     
  5. Offline

    WesJD

    top2001
    First things first, I'd go with Rocoty.

    Anyways, this is how you would do it:

    Code:java
    1. private BukkitTask task;
    2.  
    3. public void hi() {
    4. task = //blah this is your runnable
    5. }
    6.  
    7. public void cancel() {
    8. if(task != null) {
    9. task.cancel();
    10. }
    11. }
     
  6. Offline

    Tehmaker

    You could just make an integer variable, and set it equal to your repeatingtask, then to cancel it you can use Bukkit.getScheduler().cancelTask(intvariable)

    (not sure if that is the exact method, but it should be something along those lines.)
     
  7. Offline

    top2001


    How would I do this in the code I provided? I am just getting lost here :p
     
  8. Offline

    Skionz

    top2001 scheduleSyncRepeatingTask() returns id that is used to cancel the scheduler. Just put that id in the cancelTask() method's parameter.
     
    Tehmaker likes this.
Thread Status:
Not open for further replies.

Share This Page