Hello, i have made a plugin for me and my friends on our server and could someone help me fix it? The Runnable only runs once! Code:java public class ParticleToggle implements CommandExecutor { private Main plugin; public ParticleToggle(Main plugin) { this.plugin = plugin; } public int t; public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { final Player p = (Player) sender; if (cmd.getName().equalsIgnoreCase("particles")) { if (!(Ranks.main.getPlayerTeam(p) == Ranks.Admin || Ranks.main .getPlayerTeam(p) == Ranks.Owner)) { p.sendMessage(plugin.No_Permission); return true; } else { if (!(plugin.partoggle.contains(p.getName()))) { p.sendMessage(plugin.Server+ "§6You Enabled Particals for yourself!"); plugin.partoggle.add(p.getName()); } else { p.sendMessage(plugin.Server+ "§cYou Disabled Particals for yourself!"); plugin.partoggle.remove(p.getName()); } } } return true; } public void ParticleRun(){ t = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { for (Player p : plugin.getServer().getOnlinePlayers()) { if (plugin.partoggle.contains(p.getName())) { if(p.isSneaking()){ ParticleEffect.RED_DUST.display(p.getLocation().add(0, 2, 0), 0,0, 0, 1, 10); return; } if (p.isFlying()) { ParticleEffect.ENCHANTMENT_TABLE.display(p.getLocation().add(0, 0.5, 0), 0,0, 0, 1, 10); } else { Location location1 = p.getEyeLocation(); int particles = 10; float radius = 0.7f; for (int i = 0; i < particles; i++) { double angle, x, z; angle = 2 * Math.PI * i/ particles; x = Math.cos(angle) * radius; z = Math.sin(angle) * radius; location1.add(x, 0.5, z); ParticleEffect.HEART.display(location1, 0, 0, 0, 0,1); location1.subtract(x, 0.5, z); } } } else { Bukkit.getScheduler().cancelTask(t); } } } }, 5L, 10L); }}
Jamscott You cancel the task if any of the players aren't in the list of yours. I'd assume at least one player is not, which is why it's stopping the task.
First of all, you shouldn't have a method named "ParticleRun". Read this. Second, you should be saving collections of player UUIDs, not player names. You should also be using a set (HashSet, I suppose) instead of a list. I can't tell which you're using, so disregard that if you're already using a set. Third, you cancel the runnable if any player online doesn't have their name in the "partoggle" collection.