Solved Scoreboard Help

Discussion in 'Spigot Plugin Development' started by SupremeCoder101, Jan 10, 2020.

  1. This is my code for my scoreboard. It is not showing up. Help?

    Code (Java):
    package com.xenfo.sundewvalley;

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

            import java.lang.annotation.Annotation;

    public class ScoreboardClass implements Listener {

        public void onJoin(PlayerJoinEvent e) {
            Player player = e.getPlayer();

            ScoreboardManager manager = Bukkit.getScoreboardManager();
            org.bukkit.scoreboard.Scoreboard board = manager.getNewScoreboard();
            Objective obj = board.registerNewObjective("Test", "dummy", "Test");

            player.setScoreboard(board);
        }

    }
     
  2. all events need to be tagged with the eventhandler annotation. also dont see the relevant code so.. you also need to register the listener with the plugin manager.
     
    • Agree Agree x 2
  3. I had the same problem bro! Here is the solution.
    You have to set the DisplaySlot

    Code (Java):
    obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    This should work! :)
     
    • Like Like x 1
  4. This is the new code.

    Registering in Main
    Code (Java):
    getServer().getPluginManager().registerEvents(new ScoreboardClass(), this);
    Scoreboard
    Code (Java):
    package com.xenfo.sundewvalley;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class ScoreboardClass implements Listener {

        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player player = e.getPlayer();

            ScoreboardManager manager = Bukkit.getScoreboardManager();
            org.bukkit.scoreboard.Scoreboard board = manager.getNewScoreboard();
            Objective obj = board.registerNewObjective("Test", "dummy", "Test");

            player.setScoreboard(board);
        }

    }
     
  5. Please insert my code with the display slot :D
     
  6. I did still doesn’t work
     
  7. But you have to set the DisplaySlot! For sure!

    try to add this
    Code (Java):
    Score score = obj.getScore("Test");
    score.setScore(0);
    And please show your code after trying
     
  8. Check if the PlayerJoinEvent gets fired
     
  9. Nevermind it works. Thanks so much
     
    • Like Like x 1
  10. Add System.out.println("Debug"); or something like that and check the console.. :D