Solved Other players canceling a players task.

Discussion in 'Plugin Development' started by marshmallowz, Nov 27, 2014.

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

    marshmallowz

    So I have this code and it works but it lets other players cancel a different players task instead of creating a new one for themselves.
    Code:java
    1. @EventHandler
    2. public void onSneak(PlayerToggleSneakEvent event)
    3. {
    4. final Player player = event.getPlayer();
    5. if(player.getEquipment().getHelmet().equals(Material.DIAMOND_HELMET))
    6. {
    7. if(player.isSneaking())
    8. {
    9. if(task == null)
    10. {
    11. task = new TestTask(player).runTaskTimer(this, 20L, 1L);
    12. }
    13. else
    14. {
    15. task.cancel();
    16. task = null;
    17. }
    18. }
    19. }
    20. else
    21. {
    22. if(task != null)
    23. task.cancel();
    24. }
    25. }
     
  2. Offline

    Dudemister1999

    marshmallowz You'd have to do something along the lines of creating a List of tasks, because that will just override the task every time two players sneak within the same time period.
     
  3. Offline

    marshmallowz

    Dudemister1999 Thank you! Why didn't I think of that! I appreciate the help.
     
  4. Offline

    Dudemister1999

Thread Status:
Not open for further replies.

Share This Page