Countdown until logout

Discussion in 'Plugin Development' started by bars96, Dec 21, 2013.

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

    bars96

    How to make 10 seconds countdown (timer) when player interact with item and then kick player if he don't move before countdown reaches 0?

    If player move (or when countdown reaches 0), countdown task must be cancelled.

    Where is my mistake?
    Code:java
    1. public void doSafeLogout(Player pl) {
    2. final Player p = pl;
    3. logout.put(p, p.getLocation());
    4. new BukkitRunnable() {
    5. Location l = logout.get(p);
    6. int n = 10;
    7. @Override
    8. public void run() {
    9. if (l != p.getLocation()) {
    10. logout.remove(p);
    11. p.sendMessage("§cВы сдвинулись с места, выход отменён");
    12. cancel();
    13. }
    14. if (n == 0) {
    15. logout.remove(p);
    16. p.kickPlayer("§aВы успешно вышли с сервера");
    17. cancel();
    18. }
    19. p.sendMessage("§aДо выхода осталось: " + n);
    20. n--;
    21. }
    22. }.runTaskTimer(this, 0L, 20L);
    23. }

    It's prints me in chat that:
    Вы сдвинулись с места, выход отменён
    До выхода осталось: 10

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page