Scoreboard Help

Discussion in 'Plugin Development' started by Phishy, May 9, 2015.

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

    Phishy

    Hi, as part of my plugin, I am having 3 things on my scoreboard.

    Which are:
    Kills
    Deaths
    Killstreak


    I was thinking of having different Listeners for each of these. However, is there any method of calling the scoreboard from each of these.

    Or another method, not sure if it would work. In each of the event handlers, create the scoreboard with another objective, or would this replace the old scoreboard?


    Sorry at this isn't explained very well, if you would like some more explanation , please ask.
     
  2. Offline

    Gater12

    @Phishy
    Elaborate more on what you aim for.
    Do you want to update a player's scoreboard?
     
  3. Offline

    Phishy

    Okay, so I want a scoreboard, that has multiple objectives on it (Kills, deaths, killsteak) Would would I go about doing this basically?
     
  4. Offline

    caderape

    @Phishy
    Create a scoreboard for each player
    set the displayslot, the displayname, and register a new objectif.
    Then
    objectives.getscore("kill").setscore(int playerkill)
    objectives.getscore("death").setscore(int playerdeath)
     
  5. Offline

    Phishy

    Well, I was more wondering about how to go about doing it in Event Handlers
     
  6. Offline

    Gater12

    @Phishy
    Get the Player's scoreboard and update the scores.
     
  7. Offline

    Phishy

    How do you get a scoreboard (one that is already created)
     
  8. Here is how to create a scoreboard:
    It wont display yet.

    Code:
    public static void onSetScoreboardIngame(Player p){
    Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
            Objective ob = board.registerNewObjective("ingame", "dummy");
    ob.setDisplaySlot(DisplaySlot.SIDEBAR);
    ob.setDisplayName("TITLE HERE");
    int killdisplay = "" + kills;
    int deathdisplay = "" + deaths;
    int killstreakdisplay = "" + killstreak;
    Score kills = ob.getScore(Bukkit.getOfflinePlayer("Deaths:" + "" + killdisplay);
    kills.setScore(3);
    Score deaths = ob.getScore(Bukkit.getOfflinePlayer("Kills:" + "" + deathdisplay);
    deaths.setScore(2);
    Score killstreak = ob.getScore(Bukkit.getOfflinePlayer("Killstreak:" + "" + killstreakdisplay);
    killstreak.setScore(1);
    p.setScoreboard(board);
    }
    And here is how to update it
    Code:
    public static void onUpdateScoreboardIngame(Player p){
    Scoreboard board = p.getScoreboard();
    Objective ob = board.getObjective(DisplaySlot.SIDEBAR);
    ob.setDisplayName("TITLE HERE");
    int killdisplay = "" + kills;
    int deathdisplay = "" + deaths;
    int killstreakdisplay = "" + killstreak;
    ob.getScore(Bukkit.getOfflinePlayer("Deaths:" + "" + killdisplay).setScore(3);
    ob.getScore(Bukkit.getOfflinePlayer("Kills:" + "" + deathdisplay).setScore();
    ob.getScore(Bukkit.getOfflinePlayer("Killstreak:" + "" + killstreakdisplay).setScore(1);
    p.setScoreboard(board);
    }
    
    And to first give it you just use this code:

    Code:
    (class).onSetScoreboardIngame(player);
    And in order to update it:

    Code:
    (class).onUpdateScoreboardIngame(player);
    I hope this was helpfull.
    If you have any problems, please tell me.
     
Thread Status:
Not open for further replies.

Share This Page