Scoreboard help?

Discussion in 'Plugin Development' started by Wantsome909, Sep 2, 2013.

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

    Wantsome909

    how can i get it so when some one kills some one it will say 1 on player kills and so on?
    Code:java
    1. //Scoreboard
    2. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    3. public void run() {
    4. Player[] players = main.this.getServer().getOnlinePlayers();
    5. for (Player p : players) {
    6. ScoreboardManager sbm = Bukkit.getScoreboardManager();
    7. Scoreboard b = sbm.getNewScoreboard();
    8. Objective obj = b.registerNewObjective("kills", "dummy");
    9. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    10. obj.setDisplayName("MCRust");
    11. Score pkills = obj.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Murders"));
    12. pkills.setScore(0);
    13. Score zkills = obj.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Zombie Killed"));
    14. zkills.setScore(0);
    15. p.setScoreboard(b);
    16. }
    17. }
    18. }, 20, 20);
     
  2. Offline

    mydeblob

    Wantsome909
    Maybe use a hashset, and make a onEntityDeathEvent and add 1 to the hashset everytime someone dies, and when you are creating your score bored just retrieve the hashset
     
  3. Offline

    Wantsome909

  4. Offline

    mydeblob

    Wantsome909
    To code efficiently in bukkit you must have a good knowledge of java. A hash set is similar to an array list but can't hold 2 of the same data sets (correct me if I'm wrong). You would use the code like so.
    Creating the hashset (This would go where you declare all your variables in the main class, or if you don't want to use getter and setter's whatever class your using the hashset in):
    Code:java
    1. HashSet<String> name = new HashSet<String>();

    The "name" in this code is whatever you want your hashset to be called.
    You would then make a player death event:
    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent event){
    3. Player player = (Player) event.getEntity();
    4. name.add(player.getName());
    5. }

    Again, in this code the "name" you would replace with whatever you named your hashset.
    Then when you are adding this to the score board you would replace this:
    Code:java
    1. pkills.setScore(0);

    With this
    Code:java
    1. pkills.setScore(name);

    And again, you would replace "name" with the name of your hashset.
     
  5. Offline

    Wantsome909

    mydeblob so i cant have a sperate class with events and runnables? they have to be in the same class

    mydeblob i mean like this

    main class:
    Code:java
    1. //Scoreboard
    2. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    3. public void run() {
    4. Player[] players = main.this.getServer().getOnlinePlayers();
    5. for (Player p : players) {
    6. ScoreboardManager sbm = Bukkit.getScoreboardManager();
    7. Scoreboard b = sbm.getNewScoreboard();
    8. Objective obj = b.registerNewObjective("kills", "dummy");
    9. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    10. obj.setDisplayName("MCRust");
    11. Score pkills = obj.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Murders"));
    12. pkills.setScore(kills);
    13. Score zkills = obj.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Zombie Killed"));
    14. zkills.setScore(0);
    15. p.setScoreboard(b);
    16. }
    17. }
    18. }, 20, 20);


    listener class:
    Code:java
    1.  
    2. HashSet<String> kills = new HashSet<String>();
    3.  
    4. @EventHandler
    5. public void onPlayerDeath(PlayerDeathEvent event){
    6. Player player = (Player) event.getEntity();
    7. kills.add(player.getName());
    8. }
    9.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  6. Offline

    mydeblob

    Wantsome909
    Yes, but remember to add your event in your onenable. And for the scoreboard you probably will have to use a getter method to access the hashset
     
Thread Status:
Not open for further replies.

Share This Page