Scoreboard and onEnable issue?

Discussion in 'Spigot Plugin Development' started by RandomPanda30, May 3, 2015.

  1. Now I know that the onEnable handles when the server loads and stuff like that. However, I'm working on a plugin that places the scoreboard to all the players who are online so they don't have to login and stuff like that.

    However, of course I need to place a method in the onEnable that gets all the online players buuuuut I can't do this straight away so I've made a timer here to try to see if it will do it after the onEnable has finished.

    Main class -

    Code (Text):
    ScoreboardHandler.getHandler().onlineInit();
    And the method:

    Code (Text):
        public void onlineInit() {
            Bukkit.getServer().getScheduler()
                    .scheduleSyncDelayedTask(MurgeData.getPlugin(), new Runnable() {
                        @Override
                        public void run() {
                            for (Player player : Bukkit.getOnlinePlayers()) {
                                ScoreboardHandler.getHandler().doScoreboard(player);
                            }
                        }
                    }, 30L);
        }
    And of course it doesn't work...Doesn't place le scoreboard. So erm, help I guess? xD

    ~ Panda
     
  2. @RandomPanda30 have you debugged your code? Does doScoreboard get called?
     
  3. Oh yes, tired that and it calls it but doesn't display it. Just doesn't like to work here...Hm
     
  4. Code (Text):
        if (!MurgeData.isPurge()) {
                if (StatsHandler.inPlayers(uuid)) {
                    Scoreboard board = Bukkit.getScoreboardManager()
                            .getNewScoreboard();
                    Objective obj = board.registerNewObjective("scoreboard",
                            "dummy");
                    obj.setDisplaySlot(DisplaySlot.SIDEBAR);
                    ScoreboardManager sm = Bukkit.getServer()
                            .getScoreboardManager();
                    player.setScoreboard(sm.getNewScoreboard());
                    String isPurge = (MurgeData.isPurge() ? "        %B&lActive      "
                            : "      %G&lInactive      ");
                    obj.setDisplayName(StringMethods.formatMessage(isPurge));

                    Score gap0 = obj.getScore(" ");
                    gap0.setScore(6);

                    String inBalance = StringMethods.formatMessage("%N&lMoney: %A")
                            + StringCollection.getCollection().getMoneyString()
                            + Integer.toString(0);
                    Score inBalanceScore = obj.getScore(Bukkit
                            .getOfflinePlayer(inBalance));
                    inBalanceScore.setScore(5);

                    Score gap1 = obj.getScore("  ");
                    gap1.setScore(4);

                    String inKills = StringMethods
                            .formatMessage("%N&lTotal Kills: %A"
                                    + Integer.toString(KillsCollection
                                            .getCollection().getValue(uuid)));
                    Score playerKillsScore = obj.getScore(Bukkit
                            .getOfflinePlayer(inKills));
                    playerKillsScore.setScore(3);

                    String inDeaths = StringMethods
                            .formatMessage("%N&lTotal Deaths: %A"
                                    + Integer.toString(DeathsCollection
                                            .getCollection().getValue(uuid)));
                    Score inDeathsScore = obj.getScore(Bukkit
                            .getOfflinePlayer(inDeaths));
                    inDeathsScore.setScore(2);

                    Score gap2 = obj.getScore("   ");
                    gap2.setScore(1);

                    String inPurgesSurvived = StringMethods
                            .formatMessage("%N&lPurges survived: %A"
                                    + Integer.toString(SurvivalsCollection
                                            .getCollection().getValue(uuid)));
                    Score inPurgesSurvivedScore = obj.getScore(Bukkit
                            .getOfflinePlayer(inPurgesSurvived));
                    inPurgesSurvivedScore.setScore(0);

                    player.setScoreboard(board);
                }
            }
    All this essentially. Although that all works fine even though it needs tweaks and a bit of a recode doing to it. It just doesn't like to work when I try and call the timed method in the onEnable
     
  5. @RandomPanda30 either of the first two if statements seems to fail.
     
  6. Yup........The one that checks if the player's in the list was failing because I didn't add them in the onEnable...Well I'm an idiot. Thank you for pointing this out for me!