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 package me.top2001.OreCloudParticles; import org.bukkit.Bukkit;import org.bukkit.Effect;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerJoinEvent;import org.bukkit.plugin.PluginManager;import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin implements Listener{ public void onEnable() { getLogger().info("Plugin Enabled!"); PluginManager pm = getServer().getPluginManager(); pm.registerEvents(this, this); } public void onDisable() { getLogger().info("Plugin Disabled!"); } @EventHandler public void onPlayerJoin(PlayerJoinEvent e) { final Player player = (Player) e.getPlayer(); if(player.hasPermission("staffparticles.fire")){ Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { public void run() { player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 2004); } }, 20, 20); } }}
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.
top2001 First things first, I'd go with Rocoty. Anyways, this is how you would do it: Code:java private BukkitTask task; public void hi() {task = //blah this is your runnable} public void cancel() {if(task != null) {task.cancel();}}
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.)
top2001 scheduleSyncRepeatingTask() returns id that is used to cancel the scheduler. Just put that id in the cancelTask() method's parameter.