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):
    And the method:

    Code (Text):
        public void onlineInit() {
                    .scheduleSyncDelayedTask(MurgeData.getPlugin(), new Runnable() {
                        public void run() {
                            for (Player player : Bukkit.getOnlinePlayers()) {
                    }, 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()
                    Objective obj = board.registerNewObjective("scoreboard",
                    ScoreboardManager sm = Bukkit.getServer()
                    String isPurge = (MurgeData.isPurge() ? "        %B&lActive      "
                            : "      %G&lInactive      ");

                    Score gap0 = obj.getScore(" ");

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

                    Score gap1 = obj.getScore("  ");

                    String inKills = StringMethods
                            .formatMessage("%N&lTotal Kills: %A"
                                    + Integer.toString(KillsCollection
                    Score playerKillsScore = obj.getScore(Bukkit

                    String inDeaths = StringMethods
                            .formatMessage("%N&lTotal Deaths: %A"
                                    + Integer.toString(DeathsCollection
                    Score inDeathsScore = obj.getScore(Bukkit

                    Score gap2 = obj.getScore("   ");

                    String inPurgesSurvived = StringMethods
                            .formatMessage("%N&lPurges survived: %A"
                                    + Integer.toString(SurvivalsCollection
                    Score inPurgesSurvivedScore = obj.getScore(Bukkit

    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!