[Need Help] - Scoreboard

Discussion in 'Spigot Plugin Development' started by Skud31, May 7, 2015.

  1. Hey guy's
    I'm here because I would like a scoreboard who show statistics for each players.
    Example:
    Deaths:
    Kills:
    Ratio:
    I have already tried, but my code doesn't work. It's my first plugin with Scoreboard.
    Thanks.

    Skud31
    EDIT: Sorry for my bad English :3​
     
    • Like Like x 1
  2. You must post what you currently have even if "it doesn't work"
    We won't speenfood you
     
    • Like Like x 1
  3. Your current code? I don't support spoon feeding but I do support learning PM me for a scoreboard but I would really reccomend that you learn to make one yourself
     
  4. Main Class:

    Code (Text):
    public class Main
    extends JavaPlugin
    {
        Events ev = new Events(this);
        Language handler = new Language(this);
       
        HashMap<OfflinePlayer, Score> scores = new HashMap<OfflinePlayer, Score>();
       
        public Location lobbyLocation;
        private Logger log = Logger.getLogger("Minecraft");
        boolean ok = false;
        boolean inGame = false;
        boolean GameFinish = false;
        String prefix = ChatColor.GRAY + "[" + ChatColor.RED + "Battle On Heads" + ChatColor.GRAY + "]: ";
        String motd;
        ScoreboardManager manager;
        Scoreboard board;
        Team blue;
        Team red;
        Team morts;
        Objective health;
        Objective points;
        Objective playerpoints;
        Score bluePlayers;
        Score redPlayers;
        Score bluePoints;
        Score redPoints;
        Score deaths;

       
        @SuppressWarnings("deprecation")
        public void onEnable()
        {
            List<String> s = getConfig().getStringList("scores");
            this.manager = getServer().getScoreboardManager();
            this.board = this.manager.getNewScoreboard();
            this.blue = this.board.registerNewTeam("blue");
            this.red = this.board.registerNewTeam("red");
            this.morts = this.board.registerNewTeam("morts");
            this.health = this.board.registerNewObjective("Mort", "deathCount");
            this.points = this.board.registerNewObjective("Points", "dummy");
            this.playerpoints = this.board.registerNewObjective("PlayerPoints", "playerKillCount");
            this.blue.setPrefix(ChatColor.AQUA + "");
            this.red.setPrefix(ChatColor.GOLD + "");
            this.points.getScore(ChatColor.GRAY + "--------").setScore(-1);
            this.points.setDisplaySlot(DisplaySlot.SIDEBAR);
            this.points.setDisplayName(ChatColor.GREEN + this.handler.getCaption("PointsScoreboard"));
            this.bluePoints = this.points.getScore(Bukkit.getOfflinePlayer(ChatColor.AQUA +  "Cyan:"));
            this.redPoints = this.points.getScore(Bukkit.getOfflinePlayer(ChatColor.GOLD + "Orange: "));
            this.points.getScore(ChatColor.RED + "Morts" + ChatColor.WHITE + ": ");
            this.bluePoints.setScore(0);
            this.redPoints.setScore(0);
            for (Player online : Bukkit.getOnlinePlayers())
            {
                Score score = this.points.getScore(online);
                score.setScore(0);
            }
    //More code after
    }
    EventHandler Class:

    Code (Text):
    public class Events
    implements Listener
    {

        private final Main plugin;

        public Events(Main plugin)
        {
            this.plugin = plugin;
        }

    @EventHandler
        public void onDeath(final PlayerDeathEvent event){
    Player p = event.getPlayer();
    Player killer = p.getKiller().getPlayer();

      this.plugin.scores.get(player).setScore(this.plugin.scores.get(player).getScore() + 1);
                event.setDeathMessage(player + " is dead!");
                this.plugin.morts.addPlayer(player);
                event.getDrops().clear();
                event.setDroppedExp(0);
    }
     
     
  5. Hey, I assume that this is for a minigame (sort of).

    If it is so:
    • Create a HashMap with a playername /uuid and score. I would recommend you creating multiple hm's (kills, deaths etc)
    • Update your HashMap when need to.
    • Create a scoreboard and set a objective and set 3 scores. Get the value of the HashMap pro player.
    • Last: send the scoreboard to the player.
    Now write it in Java language :)
     
  6. Woaw , It's hard, someone can help me or not ?
     
  7. @Skud31 any progress since your last post? (no, not going to spoon feed you)
     
  8. It's not that hard. Look what I've written, then check javadocs if you dont understand!
     
    • Agree Agree x 1
  9. I tried, but the SB show a lot of random number
    Example: 2854544861 :confused:
     
  10. Code?
     
  11. Possibly a screenshot of the scoreboard?
     
  12. Can you show us the code in a pastebin or something? That may help us figure out what is wrong
     
  13. There are a lot of post of this. Plz google and if you don't find nothing, post it.
     
  14. I've created something similar to this, but in English.

    The way I had it done was saving the player's kills and deaths in their own config file. When a player joins, the UUID of the player is taken and grabs the kills and deaths, makes a new scoreboard for the player with the kills, deaths and ratio, then sets the player's scoreboard to the new scoreboard. On each death, the configuration increments the player's death and adds a kill to the killer (if it is a player). This also then updates the scoreboard for the killer (if it is a player) and the dead.

    As for the random number, try to make the "morts" a dummy value, then use what I mentioned above to set their deaths. I gave the above if you wanted to make something similar to mine, I don't know if you do or don't. Just thought I'd throw that out there.
     
  15. Yeah, I would done it also like your saying.. But it's a minigame, so I don't think for a minigame a config is good ?
     
  16. I would create the hashmap like this:
    public static HashMap<String, Integer> deaths = new HashMap<String, Integer>();

    Set your morts score like this:
    int killcount = deaths.get(p.getName());
    Use killcount to set your score.

    Change your lines to increasedeaths
    Just simple do:

    deaths.put(p.getName(), deaths.get(p.getName() + 1));

    EDIT: Remove your deathScore int variable, it is not necessary.
     
  17. The int deathCount is in Main class ?
    and the deaths.put(p.getName(), deaths.get(p.getName) + 1)); too ?
     
  18. No, you creating a deathcount and specified a number to it. So your adding numbers to the deathcount if a player makes a kill. That is not what you want. So you need to specify the deathcount to the players hashmap Integer.

    Where is that? Didnt saw that .. ganna look again!

    EDIT: Your 'put' needs to be in your EventHandler not Main. when someone dies its ganna add 1 to it.