Current time scoreboard

Discussion in 'Plugin Development' started by 6zero, Sep 7, 2019.

  1. Offline

    6zero

    I have problem i dont now how to create current date on scoreboard, i have this and this "timer" create now line on this scoreboard.

    Code:
    @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            final Player p = e.getPlayer();
            int balance = (int) econ.getBalance(p);
            Date now = new Date();
            SimpleDateFormat date = new SimpleDateFormat("dd/MM/yyyy");
            SimpleDateFormat datesec = new SimpleDateFormat("HH:mm:ss");
            final org.bukkit.scoreboard.Scoreboard s = Bukkit.getScoreboardManager().getNewScoreboard();
            p.setScoreboard(s);
            final Objective o = s.registerNewObjective("sidebar", "dummy");
            new BukkitRunnable() {
                @Override
                public void run() {
                    if (p == null || !p.isOnline()) {
                        cancel();
                        return;
                    }
                    o.setDisplayName("§a§lTYKURWO");
                    o.setDisplaySlot(DisplaySlot.SIDEBAR);
                    o.getScore("§6§lName:").setScore(13);
                    o.getScore(p.getName()).setScore(12);
                    o.getScore(" ").setScore(11);
                    o.getScore("§6§lMONEY:").setScore(10);
                    o.getScore(balance + "").setScore(9);
                    o.getScore("  ").setScore(8);
                    o.getScore("§6§lPlayers Online:").setScore(7);
                    o.getScore(Bukkit.getOnlinePlayers().size() + " ").setScore(6);
                    o.getScore("   ").setScore(5);
                    o.getScore("§6§lServer:").setScore(4);
                    o.getScore("Ty kurwo").setScore(3);
                    o.getScore("    ").setScore(2);
                    o.getScore(ChatColor.YELLOW + date.format(now)).setScore(1);
                    o.getScore(ChatColor.YELLOW + datesec.format(System.currentTimeMillis())).setScore(0);
    
                }
            }.runTaskTimer(this, 1, 20);
        }
    }
     
  2. Offline

    KarimAKL

    @6zero What's your problem? What's happening when you try this code?
     
  3. Offline

    6zero

  4. Offline

    timtower Moderator Moderator

    @6zero You are not removing the old line.
     
  5. Offline

    6zero

    i don't know how, something like that :
    obj.getScoreboard().resetScores("scoreboard");?
     
  6. Offline

    timtower Moderator Moderator

    That is indeed a way to do it.
     
  7. Offline

    cdnyassuo34

    what about:

    Code:
    ScoreboardManager scm = Bukkit.getScoreboardManager();
    Scoreboard scb = scm.getNewScoreboard();
    Objective o = scb.registerNewObjective("ObjectiveName");
    Team teamName = scb.registerNewTeam("ScoreName");
            job.addEntry("The message");
            job.setPrefix("The prefix "); // update in real time
            job.setSuffix("The Suffix you want"); // update in real time too
    
    o.getScore("TheScoreName").setScore(13);
    
     

Share This Page