Scoreboard ain't working.

Discussion in 'Spigot Plugin Development' started by JimmYTje, May 29, 2017.

  1. I made a Class Sb and have a main class
    If im done with the scoreboard it isnt working the scoreboard isnt showing up at the sidebar of my screen
    Main:
    Code (Text):

    package me.iDevq.TestPlugin;

    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.iDevq.Sb.Sb;

    public class Main extends JavaPlugin {
       
       
       
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
           
            getCommand("main").setExecutor(new BasisCommand());
            getCommand("hello").setExecutor(new CMessage());
            getCommand("fine").setExecutor(new Fine());
           
            pm.registerEvents(new Sb(), this);
           

        }
    }
     
    Sb code:
    Code (Text):

    package me.iDevq.Sb;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Sb extends JavaPlugin implements Listener {
       
        static Plugin plugin;
       
        public void onEnable() {
            plugin = this;
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
           
        }
       
       
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        final Scoreboard board = manager.getNewScoreboard();
        final Objective objective = board.registerNewObjective("test", "dummy");

       
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {

           
            final Player p = e.getPlayer();

           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Sb.plugin, new Runnable() {
                public void run() {
                   
                    ScoreboardManager manager = Bukkit.getScoreboardManager();
                    final Scoreboard board = manager.getNewScoreboard();
                    final Objective objective = board.registerNewObjective("test", "dummy");
                   
                    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
                    objective.setDisplayName(ChatColor.RED + "EpsilonMC");

                    Score score = objective.getScore(ChatColor.AQUA + "Player name:");
                    score.setScore(10);
                   
                    Score score1 = objective.getScore(ChatColor.GRAY + p.getName());
                    score1.setScore(9);
                   
                    Score score2 = objective.getScore(ChatColor.AQUA + "Health:");
                    score2.setScore(8);
                   
                    long health = Math.round(p.getHealth());
                   
                    Score score3 = objective.getScore(ChatColor.GRAY + String.valueOf(health));
                    score3.setScore(7);
                   
                    p.setScoreboard(board);

                }
            },0, 20 * 10);
           
        }

    }
     
    T
     
  2. two classes can not extend javaplugin, and ur plugin is ur main class, not sb class
     
  3. Well your problem is that both of your classes extend JavaPlugin ONLY your Main class needs that and you have two onEnable() one in each class remove extends JavaPlugin and onEnable() from your scoreboard class
     
    • Agree Agree x 1
    • Useful Useful x 1
  4. BEAT U TO IT!!!!!
     
    • Like Like x 1
    • Funny Funny x 1
  5. Did this:
    Code (Text):

    package me.iDevq.Sb;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Sb implements Listener {
       
        static Plugin plugin;
       
           
       
       
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        final Scoreboard board = manager.getNewScoreboard();
        final Objective objective = board.registerNewObjective("test", "dummy");

       
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {

           
            final Player p = e.getPlayer();

           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Sb.plugin, new Runnable() {
                public void run() {
                   
                    ScoreboardManager manager = Bukkit.getScoreboardManager();
                    final Scoreboard board = manager.getNewScoreboard();
                    final Objective objective = board.registerNewObjective("test", "dummy");
                   
                    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
                    objective.setDisplayName(ChatColor.RED + "EpsilonMC");

                    Score score = objective.getScore(ChatColor.AQUA + "Player name:");
                    score.setScore(10);
                   
                    Score score1 = objective.getScore(ChatColor.GRAY + p.getName());
                    score1.setScore(9);
                   
                    Score score2 = objective.getScore(ChatColor.AQUA + "Health:");
                    score2.setScore(8);
                   
                    long health = Math.round(p.getHealth());
                   
                    Score score3 = objective.getScore(ChatColor.GRAY + String.valueOf(health));
                    score3.setScore(7);
                   
                    p.setScoreboard(board);

                }
            },0, 20 * 10);
           
        }

    }
     
    Fixed?
     
  6. Code (Text):

    Could not pass event PlayerJoinEvent to TestPlugin v1.0
    org.bukkit.event.EventException
     
    Getting that error in my console btw
     
  7. That's better :D have you tested it to see if it's working now?
     
  8. Is that the whole error ?
     
  9. Code (Text):

    Could not pass event PlayerJoinEvent to TestPlugin v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[server.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[server.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerList.onPlayerJoin(PlayerList.java:327) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerList.a(PlayerList.java:160) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.LoginListener.b(LoginListener.java:147) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.LoginListener.F_(LoginListener.java:57) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.NetworkManager.a(NetworkManager.java:233) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.ServerConnection.c(ServerConnection.java:140) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:842) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[server.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.scheduler.CraftScheduler.validate(CraftScheduler.java:400) ~[server.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:126) ~[server.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:122) ~[server.jar:git-Spigot-3fb9445-6e3cec8]
            at me.iDevq.Sb.Sb.PlayerJoin(Sb.java:35) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[server.jar:git-Spigot-3fb9445-6e3cec8]
     
     
  10. Mas

    Mas

    Your 'plugin' field in the 'Sb' class is just sitting as a null value.
    You should probably learn the basics of Object Oriented Programming before attempting to make plugins. It will help in the long run.
     
    • Agree Agree x 1
  11. Ah you're not passing an Instance of your Main class
    static Plugin plugin; is nothing

    add this

    Code (Text):
    Remove "static Plugin plugin"
    and add this v

    private Main plugin;
    public Sb(Main pl) {
    this.plugin = pl;
    }

    then replace sb.plugin in your repeatingtask to "plugin"

    and in your main class change pm.registerEvent(new Sb(this), this);
     
    • Useful Useful x 1
  12. k Thanks.
     
  13. U mean
    Code (Text):

        public void sb(Main pl) {
     
    xd?
     
  14. Code (Text):
    In your Main class also change

    old
    pm.registerEvents(new Sb(), this);
    new
    pm.registerEvents(new Sb(this), this);
    No like this xD

    Code (Text):
    package me.iDevq.Sb;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Sb implements Listener {
     
        private Main plugin;
        public Sb(Main pl) {
        this.plugin = pl;
        }  
         
     
     
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        final Scoreboard board = manager.getNewScoreboard();
        final Objective objective = board.registerNewObjective("test", "dummy");

     
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {

         
            final Player p = e.getPlayer();

         
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                public void run() {
                 
                    ScoreboardManager manager = Bukkit.getScoreboardManager();
                    final Scoreboard board = manager.getNewScoreboard();
                    final Objective objective = board.registerNewObjective("test", "dummy");
                 
                    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
                    objective.setDisplayName(ChatColor.RED + "EpsilonMC");

                    Score score = objective.getScore(ChatColor.AQUA + "Player name:");
                    score.setScore(10);
                 
                    Score score1 = objective.getScore(ChatColor.GRAY + p.getName());
                    score1.setScore(9);
                 
                    Score score2 = objective.getScore(ChatColor.AQUA + "Health:");
                    score2.setScore(8);
                 
                    long health = Math.round(p.getHealth());
                 
                    Score score3 = objective.getScore(ChatColor.GRAY + String.valueOf(health));
                    score3.setScore(7);
                 
                    p.setScoreboard(board);

                }
            },0, 20 * 10);
         
        }

    }
     
    • Useful Useful x 1
  15. Code (Text):

    package me.iDevq.Sb;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.craftbukkit.Main;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Sb implements Listener {
       
        private Main plugin;
        public void sb(Main pl) {
        this.plugin = pl;
        }
           
       
       
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        final Scoreboard board = manager.getNewScoreboard();
        final Objective objective = board.registerNewObjective("test", "dummy");

       
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {

           
            final Player p = e.getPlayer();

           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                public void run() {
                   
                    ScoreboardManager manager = Bukkit.getScoreboardManager();
                    final Scoreboard board = manager.getNewScoreboard();
                    final Objective objective = board.registerNewObjective("test", "dummy");
                   
                    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
                    objective.setDisplayName(ChatColor.RED + "EpsilonMC");

                    Score score = objective.getScore(ChatColor.AQUA + "Player name:");
                    score.setScore(10);
                   
                    Score score1 = objective.getScore(ChatColor.GRAY + p.getName());
                    score1.setScore(9);
                   
                    Score score2 = objective.getScore(ChatColor.AQUA + "Health:");
                    score2.setScore(8);
                   
                    long health = Math.round(p.getHealth());
                   
                    Score score3 = objective.getScore(ChatColor.GRAY + String.valueOf(health));
                    score3.setScore(7);
                   
                    p.setScoreboard(board);

                }
            },0, 20 * 10);
           
        }

    }
     
    i did that but im getting an error at scheduleSyncRepeatingTask "The method scheduleSyncRepeatingTask(Plugin, Runnable, long, long) in the type BukkitScheduler is not applicable for the arguments (Main, new Runnable(){}, int, int)"
    And at the mainclass
    Code (Text):

    package me.iDevq.TestPlugin;

    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.iDevq.Sb.Sb;

    public class Main extends JavaPlugin {
       
       
       
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
           
            getCommand("main").setExecutor(new BasisCommand());
            getCommand("hello").setExecutor(new CMessage());
            getCommand("fine").setExecutor(new Fine());
           
            pm.registerEvents(new sb(), this);
           

        }
    }
     
    Getting an error at pm.registerEvents(new getting here error>sb(), this);
    error:"sb cannot be resolved to a type"
     
  16. change it to this pm.registerEvents(new sb(this), this);
     
    • Useful Useful x 1
  17. Still getting the Warning
     
  18. Thanks worked
    had to do Sb
     
  19. You're welcome glad it's working now :D
     
  20. Got already new error i was making a Kills / kdr / death counter
    Now this is happening.
    Code (Text):

    [17:34:35 ERROR]: Could not pass event PlayerJoinEvent to TestPlugin v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[server.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[server.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerList.onPlayerJoin(PlayerList.java:327) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerList.a(PlayerList.java:160) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.LoginListener.b(LoginListener.java:147) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.LoginListener.F_(LoginListener.java:57) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.NetworkManager.a(NetworkManager.java:233) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.ServerConnection.c(ServerConnection.java:140) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:842) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [server.jar:git-Spigot-3fb9445-6e3cec8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.StackOverflowError
            at me.iDevq.TestPlugin.Main.getIntance(Main.java:27) ~[?:?]
            at me.iDevq.TestPlugin.Main.getIntance(Main.java:27) ~[?:?]
            at me.iDevq.TestPlugin.Main.getIntance(Main.java:27) ~[?:?]
            at me.iDevq.TestPlugin.Main.getIntance(Main.java:27) ~[?:?]
            at me.iDevq.TestPlugin.Main.getIntance(Main.java:27) ~[?:?]
            at me.iDevq.TestPlugin.Main.getIntance(Main.java:27) ~[?:?]
            at me.iDevq.TestPlugin.Main.getIntance(Main.java:27) ~[?:?]
            at me.iDevq.TestPlugin.Main.getIntance(Main.java:27) ~[?:?]
            at me.iDevq.TestPlugin.Main.getIntance(Main.java:27) ~[?:?]
     
    And here is my board
    Code (Text):

    package me.iDevq.Sb;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerLevelChangeEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    import me.iDevq.TestPlugin.Main;

    public class Sb implements Listener {
       
        @EventHandler
        private void on(PlayerQuitEvent e) {
            for(Player all: Bukkit.getOnlinePlayers()) {
                iDevqSB(all);
            }
        }
       
        @EventHandler
        private void on(PlayerRespawnEvent e) {
                Player p = e.getPlayer();
                iDevqSB(p);
            }
       
        @EventHandler
        private void on(PlayerLevelChangeEvent e) {
                Player p = e.getPlayer();
                iDevqSB(p);
            }  
       
        @EventHandler
        private void on(PlayerDeathEvent e) {
                Player p = (Player) e.getEntity();
                Player k = p.getKiller();
                iDevqSB(p);
                iDevqSB(k);
            }
       
        public static void iDevqSB(Player p) {
        }  
         
        private Main plugin;
        public Sb(Main pl) {
        this.plugin = pl;
        }
       
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        final Scoreboard board = manager.getNewScoreboard();
        final Objective objective = board.registerNewObjective("test", "dummy");

        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {


         
            final Player p = e.getPlayer();
           
            int kills = Main.getIntance().getConfig().getInt("Stats." + p.getName() + ".Kills");
            int deaths = Main.getIntance().getConfig().getInt("Stats." + p.getName() + ".Deaths");
            double kdr = kills/deaths;
            String out = String.format("%.1f", Double.valueOf(kdr));
           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                public void run() {
                 
                    ScoreboardManager manager = Bukkit.getScoreboardManager();
                    final Scoreboard board = manager.getNewScoreboard();
                    final Objective objective = board.registerNewObjective("test", "dummy");
                 
                    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
                    objective.setDisplayName(ChatColor.RED + "        " + ChatColor.BOLD + "iDevq Board" + "        ");

                    Score score11 = objective.getScore(ChatColor.DARK_RED + "Player name:");
                    score11.setScore(10);
                 
                    Score name = objective.getScore(ChatColor.RED + p.getName());
                    name.setScore(9);
                 
                    Score score2 = objective.getScore(ChatColor.DARK_RED + "Health:");
                    score2.setScore(8);
                 
                    long health = Math.round(p.getHealth());
                 
                    Score score3 = objective.getScore(ChatColor.RED + String.valueOf(health));
                    score3.setScore(7);
                   
                    Score k = objective.getScore(ChatColor.DARK_RED + "Kills: " + ChatColor.GRAY + kills);
                    k.setScore(6);
                   
                    Score d = objective.getScore(ChatColor.DARK_RED + "Deaths: " + ChatColor.GRAY + deaths);
                    d.setScore(6);
         
                    Score kd = objective.getScore(ChatColor.DARK_RED + "KDR: " + ChatColor.GRAY + out);
                    kd.setScore(6);
                   
                    Score s = objective.getScore(ChatColor.DARK_RED + "Deaths: " + ChatColor.GRAY + p.getLevel());
                    s.setScore(6);
                   
                    p.setScoreboard(board);

                }
            },0, 20 * 10);
         
        }

    }