Bukkit Runnable

Discussion in 'Plugin Development' started by Jamscott, Sep 17, 2014.

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

    Jamscott

    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
    1. public class ParticleToggle implements CommandExecutor {
    2.  
    3. private Main plugin;
    4.  
    5. public ParticleToggle(Main plugin) {
    6. this.plugin = plugin;
    7. }
    8.  
    9. public int t;
    10.  
    11. public boolean onCommand(CommandSender sender, Command cmd,
    12. String commandLabel, String[] args) {
    13. final Player p = (Player) sender;
    14. if (cmd.getName().equalsIgnoreCase("particles")) {
    15. if (!(Ranks.main.getPlayerTeam(p) == Ranks.Admin || Ranks.main
    16. .getPlayerTeam(p) == Ranks.Owner)) {
    17. p.sendMessage(plugin.No_Permission);
    18. return true;
    19. } else {
    20. if (!(plugin.partoggle.contains(p.getName()))) {
    21. p.sendMessage(plugin.Server+ "§6You Enabled Particals for yourself!");
    22. plugin.partoggle.add(p.getName());
    23. } else {
    24. p.sendMessage(plugin.Server+ "§cYou Disabled Particals for yourself!");
    25. plugin.partoggle.remove(p.getName());
    26. }
    27. }
    28. }
    29. return true;
    30. }
    31.  
    32. public void ParticleRun(){
    33.  
    34. t = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    35.  
    36. @Override
    37. public void run() {
    38. for (Player p : plugin.getServer().getOnlinePlayers()) {
    39. if (plugin.partoggle.contains(p.getName())) {
    40. if(p.isSneaking()){
    41. ParticleEffect.RED_DUST.display(p.getLocation().add(0, 2, 0), 0,0, 0, 1, 10);
    42. return;
    43. }
    44. if (p.isFlying()) {
    45. ParticleEffect.ENCHANTMENT_TABLE.display(p.getLocation().add(0, 0.5, 0), 0,0, 0, 1, 10);
    46. } else {
    47. Location location1 = p.getEyeLocation();
    48. int particles = 10;
    49. float radius = 0.7f;
    50. for (int i = 0; i < particles; i++) {
    51. double angle, x, z;
    52. angle = 2 * Math.PI * i/ particles;
    53. x = Math.cos(angle) * radius;
    54. z = Math.sin(angle) * radius;
    55. location1.add(x, 0.5, z);
    56. ParticleEffect.HEART.display(location1, 0, 0, 0, 0,1);
    57. location1.subtract(x, 0.5, z);
    58. }
    59. }
    60. } else {
    61. Bukkit.getScheduler().cancelTask(t);
    62. }
    63. }
    64. }
    65. }, 5L, 10L);
    66. }
    67. }
     
  2. 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.
     
  3. Offline

    Garris0n

    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.
     
Thread Status:
Not open for further replies.

Share This Page