Solved Creating a Scoreboard unique per person.

Discussion in 'Plugin Help/Development/Requests' started by Scorpionvssub, Dec 1, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Scorpionvssub

    Trying to create a Scoreboard that will run induvidual for each person that joins the arena but is able to cancel and tell the time it took a person to finish it with some sort of math like 600 seconds being this many minutes but While i managed to make the scoreboard count the seconds up(Repeating every second) im not sure if its unique to the player and how to cancel the event when they finish/leave the arena.

    Code:
        private static int time;
    
        public void setTime(int time) {
            Scoreboardmanager.time = time;
        }
    
        public static void Scoreboard(final Player p, final String name) {
            Main.get().getServer().getScheduler().scheduleSyncRepeatingTask(Main.get(), new Runnable() {
                @Override
                public void run() {
                    ScoreboardManager manager = Bukkit.getScoreboardManager();
                    Scoreboard board = manager.getNewScoreboard();
                    Objective ob = board.registerNewObjective("test", "dummy");
                    ob.setDisplaySlot(DisplaySlot.SIDEBAR);
                    ob.setDisplayName(name);
    
                    time = (time + 1);
    
    
                    Score score = ob.getScore(Main.get().color1 + "Time:");
                    score.setScore(time);
    
                    p.setScoreboard(board);
                }
            }, 0L, 20L);
        }
    
        public static void removeScoreboard(Player p) {
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            Objective ob = board.registerNewObjective("test", "dummy");
            ob.setDisplaySlot(DisplaySlot.SIDEBAR);
            p.setScoreboard(manager.getNewScoreboard());
        }
    }
    The code is started via:
    Code:
                            Scoreboardmanager.Scoreboard(p, s.getLine(1));
    
    Update:

    Tried to add
    Code:
                    if (Main.get().arena.containsKey(p.getUniqueId())) {
                        p.setScoreboard(board);
                    } else {
                        p.setScoreboard(manager.getNewScoreboard());
                        p.sendMessage("Time taken in seconds: " + time);
                    }

    which did make the scoreboard disappear but how the hell do i stop the timer :confused:
     
    Last edited: Dec 1, 2015
  2. Offline

    ObviousEmeralds

    You could use packets
    [​IMG]
    I do not know how to use them though.
     
  3. Offline

    Firestar311

    Just go on YouTube and search "Bukkit coding per player scoreboard" and you will get a few results
     
  4. Offline

    Scorpionvssub

    Code:
        public static void Scoreboard(final Player p, final String name) {
            if (!Main.get().timer.containsKey(p.getUniqueId())) {
                Main.get().timer.put(p.getUniqueId(), 0);
            }
            Main.get().getServer().getScheduler().scheduleSyncRepeatingTask(Main.get(), new Runnable() {
                @Override
                public void run() {
                    ScoreboardManager manager = Bukkit.getScoreboardManager();
                    Scoreboard board = manager.getNewScoreboard();
                    Objective ob = board.registerNewObjective("test", "dummy");
                    ob.setDisplaySlot(DisplaySlot.SIDEBAR);
                    ob.setDisplayName(ChatColor.BLUE + "Arena: " + ChatColor.RESET + name);
    
    
                    Score score = ob.getScore(Main.get().color1 + "Time:");
                    score.setScore(Main.get().timer.get(p.getUniqueId()));
    
                    if (Main.get().arena.containsKey(p.getUniqueId())) {
                        Main.get().timer.put(p.getUniqueId(), Main.get().timer.get(p.getUniqueId()) + 1);
                        p.setScoreboard(board);
                    } else {
                        p.setScoreboard(manager.getNewScoreboard());
                            Main.get().timer.put(p.getUniqueId(), 0);
                    }
                }
            }, 0L, 20L);
        }
    I got the scoreboard to go per person by that i mean the timer initializes and counts up unique per person which is good, however there is a slight bug in this where if u join the arena often enough the time duplicates or doubles someone suggested or pointed out that its because of a loop that never ends, but how do i cancel a timer that...well...starts like this x)
     
Thread Status:
Not open for further replies.

Share This Page