1.8.8 Create Scoreboard

Discussion in 'Spigot Plugin Development' started by Chronuak, Feb 29, 2020.

  1. Hello everyone,
    I wanted to create a scoreboard.
    In one line should be written how many coins you have.
    However there are some problems :
    Code (Text):
    public class ScoreboardHandler implements Listener {

        public static void updater() {
            new BukkitRunnable() {

                @Override
                public void run() {
                    for (Scoreboard board : Main.boards.keySet()) {
                        Player p = Main.boards.get(board);
                        //what here?
                    }

                }
            }.runTaskTimer(Main.getInstance(), 0, 1);
        }

        public void setScoreboard(Player p) {
            final Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
            final Objective obj = scoreboard.registerNewObjective("scoreboard", "dummy");

            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName("┬ž6┬žlCHRONUAK.NET");
            obj.getScore(CoinsAPI.getCoins(p)).setScore(5);
            //The method getCoins(String) in the type CoinsAPI is not applicable for the arguments (Player)
            Main.boards.put(scoreboard, p);
            p.setScoreboard(scoreboard);
        }

        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            if (p.getWorld().getName().equalsIgnoreCase(Main.world1) || p.getWorld().getName().equalsIgnoreCase(Main.world2)
                    || p.getWorld().getName().equalsIgnoreCase(Main.world3)
                    || p.getWorld().getName().equalsIgnoreCase(Main.world4)
                    || p.getWorld().getName().equalsIgnoreCase(Main.world5)
                    || p.getWorld().getName().equalsIgnoreCase(Main.pworld1)
                    || p.getWorld().getName().equalsIgnoreCase(Main.pworld2)
                    || p.getWorld().getName().equalsIgnoreCase(Main.pworld3)
                    || p.getWorld().getName().equalsIgnoreCase(Main.vworld1)) {
                createScoreboard(p);
                //The method createScoreboard(Player) is undefined for the type ScoreboardHandler
            }
        }

    }
    Can anyone help me to fix these problems?
     
  2. You would need to check and update the scoreboard also 1tick is a bit overkill for refresh rate


    Also do you have a method to create the scoreboard? Or are you asumming it just magically get created?
     
  3. ah, ok. And what should I write in the method?
    And what about the CoinsAPI?
     
  4. CoinsApi says that method requires a string so most likely requires a name rather than a player so
    CoinsAPI.getCoins(playerTabName or display depending how you saved the player) should do it



    Also while its nice seeing attempts i think you are aiming too high,you should first start from some tutorials and then try working with scoreboards and apis