Help Me Scoreboard + Money

Discussion in 'Spigot Plugin Development' started by Cuthmf, May 31, 2016.

  1. Scoreboard It Appearing Money Of All players,
    quickly

    Code:
    final static Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
    final static Objective obj = board.registerNewObjective("noflicker", "dummy");
    Team Money = board.registerNewTeam("Money");
    Team pg = board.registerNewTeam("Ping");
    public void craftPingP(Player p) {
    int pings = ((CraftPlayer)p).getHandle().ping;
    pg.addEntry(ChatColor.DARK_PURPLE + "Ping §7> §d");
    pg.setSuffix("§d" + pings);
    board.getTeam("Ping").setSuffix("§d" + pings);
    }

    @SuppressWarnings("deprecation")
    public void craftMoneyP(Player p) {
    Money.addEntry(ChatColor.YELLOW + "Dinheiro: §2 ");
    Money.setSuffix("§2" + Main.economy.getBalance(p.getName()));
    board.getTeam("Money").setSuffix("§2" + Main.economy.getBalance(p.getName()));
    }
    @SuppressWarnings("deprecation")
    @EventHandler
    public void OnJoin(PlayerJoinEvent e) {
    e.setJoinMessage(null);
    final Player p=e.getPlayer();
    p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
    p.setScoreboard(board);
    craftMoneyP(p);
    craftPingP(p);

    new BukkitRunnable() {

    @Override
    public void run() {
    int pings = ((CraftPlayer)p).getHandle().ping;
    board.getTeam("Money").setSuffix("§2" + Main.economy.getBalance(p.getName()));
    board.getTeam("Ping").setSuffix("§d" + pings);
    }
    }.runTaskTimer(Main.pl, 20, 20);



    }

    public static void Craftscore() {
    obj.setDisplaySlot(DisplaySlot.SIDEBAR);


    Score es = obj.getScore(ChatColor.BLUE + " ");
    es.setScore(52);

    Score rank = obj.getScore("§bHorario: ");
    rank.setScore(51);

    Score es1 = obj.getScore(ChatColor.DARK_PURPLE + "Ping §7> §d");
    es1.setScore(50);

    Score money1 = obj.getScore(ChatColor.YELLOW + "Dinheiro: §2 ");
    money1.setScore(49);


    Score es3 = obj.getScore(ChatColor.AQUA + " ");
    es3.setScore(48);




    Score es5 = obj.getScore(ChatColor.AQUA.toString());
    es5.setScore(46);


    final Team Hor = board.registerNewTeam("Hora");
    Hor.addEntry("§bHorario: ");
    Hor.setSuffix(""+ Horario.tempo);
     
  2. It already starts at the beginning.
    Code (Text):
    final static Scoreboard
    Final means that an object cannot be changed afterwards, and since you want it to change:
    Code (Text):
    board.registerNewObjective
    You can't make it final. Same goes for the Objectice
     
  3. Add me on skype for I help you : MaxenceDevWeb
    It is easiest by skype
     
  4. Oh My God, I had forgotten this it.
     
  5. Please dont forget the code tags next time ;)
     
  6. @Cuthmf Take a look here;

    Code (Text):
        public void setScoreBoard(Player player){
            //Here we set the scoreboard for the player if player has no scoreboard yet!

            Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
            Objective obj = board.registerNewObjective("ThisCanBeYourServerName", "dummy");
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName("SwagCraft");//This is the displayname of scoreboard You know it I hope

            //Now we make a Score that is just there and wont update
            //Like » Online and below that one we show the onlineplayers (Using teams)

            Score onlineName = obj.getScore(ChatColor.GRAY + "» Online");
            onlineName.setScore(15);

            /*
             * Scoreboard looks now like:
             *
             * == Title ==
             * » Online
             */

            //Now we going to make the onlineCounter using teams (Wont be visible by /scoreboard teams list etc.


            Team onlineCounter = board.registerNewTeam("onlineCounter");
            //Register a new team called "onlineCounter"
            //We will need to use the "onlineCounter" later to update it! They are case Sensitive

            onlineCounter.addEntry(ChatColor.BLACK + "" + ChatColor.WHITE + "");
            //Now we add just a blank entry instead of a player.
            //Note that entry's for teams much be identical! You cant have 2 different teams with same entry!

            if(Bukkit.getOnlinePlayers().size() == 0){
                onlineCounter.setPrefix(ChatColor.DARK_RED + "" + "0" + ChatColor.RED + "/" + "" + ChatColor.DARK_RED + Bukkit.getServer().getMaxPlayers());
            }else{
                onlineCounter.setPrefix(String.valueOf(ChatColor.DARK_RED + "" + Bukkit.getOnlinePlayers().size() + "" + ChatColor.RED + "/" + "" + ChatColor.DARK_RED + "" + Bukkit.getServer().getMaxPlayers()));
            }
            //Here we set the prefix of the team.
            //This will look like:
            // onlineplayers/maxplayers
            //Example:  4/200
            //You can change it yourself!

            obj.getScore(ChatColor.BLACK + "" + ChatColor.WHITE + "").setScore(14);
            //Now we add the team into the scoreboard so it will display it!
            //Note that the getScore(""); must be the same as your team entry!
            //This one is the same as the onlineCounter entry!

            /*
             * Scoreboard will now look like:
             *
             * == Title ==
             * » Online
             * 4/200 (From example)
             */


            //Going to make a moneyCounter that will display your vault balance!

            Score money = obj.getScore(ChatColor.GRAY + "» Money");
            money.setScore(13);

            Team moneyCounter = board.registerNewTeam("moneyCounter");
            moneyCounter.addEntry(ChatColor.RED + "" + ChatColor.WHITE + "");
            moneyCounter.setPrefix(ChatColor.GREEN + "$" + economy.getBalance(player));
            obj.getScore(ChatColor.RED + "" + ChatColor.WHITE + "");

            /*
             * Scoreboard looks now like:
             *
             * == Title ==
             * » Online
             * 4/200
             * » Money
             * ${player's balance}
             */


            //Now we just set the scoreboard
            player.setScoreboard(board);

            //Scoreboard been set! Time to update!
            //Check the updateMethod :P

        }


        public void updateScoreBoard(Player player){

            //So now we are going to update the scoreboard for a player.
            //First we need to get the player's scoreboard
            Scoreboard board = player.getScoreboard();
            //Now we have that we can access the scoreboard shizzle
            //Now lets update the onlineCounter and the moneyCounter


            if(Bukkit.getOnlinePlayers().size() == 0){
                board.getTeam("onlineCounter").setPrefix(ChatColor.DARK_RED + "" + "0" + ChatColor.RED + "/" + "" + ChatColor.DARK_RED + Bukkit.getServer().getMaxPlayers());
            }else{
                board.getTeam("onlineCounter").setPrefix(String.valueOf(ChatColor.DARK_RED + "" + Bukkit.getOnlinePlayers().size() + "" + ChatColor.RED + "/" + "" + ChatColor.DARK_RED + "" + Bukkit.getServer().getMaxPlayers()));
            }

            //Here we get the team called "onlineCounter" and we update it by setting the new prefix
            //Now lets update the moneyCounter

            board.getTeam("moneyCounter").setPrefix(ChatColor.GREEN + "$" + economy.getBalance(player));


            //And now you have update the scoreboard!

        }