counter crashes?

Discussion in 'Plugin Development' started by guitargun, Mar 11, 2015.

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

    guitargun

    I have this counter:
    Code:
        public void timer() {
            scheduler = Scheduler.runAsyncTaskRepeat(new Runnable() {
                public void run() {
                    for (UUID p : players.keySet()) {
                        Player player = Bukkit.getPlayer(p);
                       
                        if(BarAPI.hasBar(player)){
                            BarAPI.removeBar(player);
                        }
                       
                        if (!countdown) {
                            minutes = time / 60;
                            int seconds = time - minutes * 60;
                            BarAPI.setMessage(player, ChatColor.BLUE + "Blue: "
                                    + blueteamkills + ChatColor.GRAY
                                    + "    Game starts in: " + minutes + ":"
                                    + seconds + ChatColor.RED + "    Red: "
                                    + redteamkills, 1);
                        } else {
                            minutes = time / 60;
                            int seconds = time - minutes * 60;
    
                            BarAPI.setMessage(player, ChatColor.BLUE + "Blue: "
                                    + blueteamkills + ChatColor.GREEN
                                    + "    Game time: " + minutes + ":" + seconds
                                    + ChatColor.RED + "    Red: " + redteamkills, 1);
                        }
                        players.get(p).setGold(players.get(p).getGold() + 3);
    
                        if (minutes == type.getMaxtime()) {
                            String team;
                            if (blueteamkills > redteamkills) {
                                team = "Blue";
                            } else if (redteamkills > blueteamkills) {
                                team = "Red";
                            } else {
                                team = "Tied";
                            }
                            endgame("Time", team);
                        }
                    }
                    if (!countdown) {
                        time--;
                        if (time == 0) {
                            countdown = true;
                        }
                    } else {
                        time++;
                    }
                }
            }, 1L, 1L);
        }
    now sometimes when a player dies or just during the game the counter stops working. After a amount of time it starts again from where it ended but sometimes it just completely stops working.
    scheduler I use:
    https://github.com/CodeLanx/Codelan.../com/codelanx/codelanxlib/util/Scheduler.java
     
  2. Try using a normal task.
     
  3. Offline

    guitargun

    @MaTaMoR_ what do you mean with normal task? the only way to use this scheduler is with these tasks otherwise I have to rely on the bukkit runnable which didn't work either
     
  4. Code:java
    1.  
    2. new BukkitRunnable() {
    3. @Override
    4. public void run() {
    5. //Stuff
    6. }
    7. }.runTaskTime(this, 1, 1);
    8.  
     
  5. Offline

    guitargun

    I looked at it and tested it. it still lags but it doesn't crash the scheduler instead somehow the server crashes.
     
  6. Offline

    Zombie_Striker

    If it crashes the server, then there is an InternalError. Is your server up to date? Is the Api up to date? Debug your code and see what it does before it crashes.

    BTW, use .getUnuqueId() instead of keySet();
     
  7. Offline

    guitargun

    @Zombie_Striker the timer works without the runnable etc. the problem is it lags with the old method.
    players is not a player but a hashmap just yo let you know.

    the barapi I did some searching can crash with minecraft 1.8 but as far as I know it happened also in 1.7
     
Thread Status:
Not open for further replies.

Share This Page