Solved Scoreboard

Discussion in 'Plugin Development' started by men8, Oct 21, 2014.

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

    men8

    Hi there. I'm trying to add scoreboard to my plugin but first I want to play with it. What I want is to update temp variable in this scoreboard. I don't know is there any other way to show updating string in scoreboard so I'm trying to do it this way:

    temp variable is simply temperature, but now I wan't to do it without HashMaps only for one player, and rest of plugin.
    Please help me understand this scoreboard thing because it's mystery for me. I made harder plugins than this, but scoreboards win this time :p Sorry for english btw.

    Code:java
    1. package me.men8.scoreboard;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.World;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.plugin.PluginManager;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.bukkit.scoreboard.DisplaySlot;
    15. import org.bukkit.scoreboard.Objective;
    16. import org.bukkit.scoreboard.Score;
    17. import org.bukkit.scoreboard.Scoreboard;
    18. import org.bukkit.scoreboard.ScoreboardManager;
    19. import org.bukkit.scoreboard.Team;
    20.  
    21. public class Main extends JavaPlugin implements Listener{
    22.  
    23. Scoreboard board;
    24. Objective objective;
    25. Score score8;
    26.  
    27. int temp = 0;
    28.  
    29.  
    30. public void onEnable(){
    31. PluginManager pm = Bukkit.getServer().getPluginManager();
    32. pm.registerEvents(this, this);
    33. scoreboard();
    34.  
    35. }
    36.  
    37. public void scoreboard(){
    38. ScoreboardManager manager = Bukkit.getScoreboardManager();
    39. board = manager.getNewScoreboard();
    40. objective = board.registerNewObjective("test", "dummy");
    41. objective.setDisplayName(ChatColor.RED + "STALKER PDA");
    42. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    43.  
    44. Team team = board.registerNewTeam("Team");
    45. team.setDisplayName(ChatColor.RED + "");
    46.  
    47. for (World w : Bukkit.getWorlds()){
    48. for (Player p : w.getPlayers()){
    49. if (w.getPlayers() != null){
    50.  
    51.  
    52.  
    53. Score score1 = objective.getScore("┌" + ChatColor.GOLD + " NAME:");
    54. score1.setScore(11);
    55. Score score2 = objective.getScore("└ " + ChatColor.GREEN + p.getName());
    56. score2.setScore(10);
    57. Score score3 = objective.getScore("┌" + ChatColor.GOLD + " FACTION:");
    58. score3.setScore(9);
    59. Score score4 = objective.getScore("└ jakies");
    60. score4.setScore(8);
    61. Score score5 = objective.getScore("┌" + ChatColor.GOLD + " MONEY:");
    62. score5.setScore(7);
    63. Score score6 = objective.getScore("└ kasa");
    64. score6.setScore(6);
    65. Score score7 = objective.getScore("┌" + ChatColor.GOLD + " TEMPERATURE:");
    66. score7.setScore(5);
    67.  
    68.  
    69. Score score9 = objective.getScore("┌" + ChatColor.GOLD + " OXYGEN:");
    70. score9.setScore(3);
    71. Score score10 = objective.getScore("└ O2");
    72. score10.setScore(2);
    73. Score score11 = objective.getScore("┌" + ChatColor.GOLD + " THIRST:");
    74. score11.setScore(1);
    75. Score score12 = objective.getScore("└ thirst");
    76. score12.setScore(0);
    77. }
    78. }
    79. }
    80. }
    81.  
    82. public void updateTemp(){
    83. Score score8 = objective.getScore("└ " + temp + " %");
    84. score8.setScore(4);
    85. //Something here but can't figure what ;_____;
    86.  
    87. }
    88.  
    89.  
    90. @EventHandler
    91. public void onInteract(PlayerInteractEvent e){
    92. if(e.getAction().equals(Action.LEFT_CLICK_AIR)){
    93. temp++;
    94. e.getPlayer().sendMessage("" + temp);
    95. updateTemp();
    96. }
    97. }
    98.  
    99. @EventHandler
    100. public void onJoin(PlayerJoinEvent e){
    101. Player p = e.getPlayer();
    102. p.setScoreboard(board);
    103. }
    104. }
    105.  
     
  2. Offline

    TheCodingCat

    So you are trying to put like player-statistics on the side bar or something? men8 Please explain a little more I'm still not 100% sure what you want (and btw your photo scares me O_O)
     
  3. Offline

    men8

    TheCodingCat Thanks for reply :)I want to update
    Code:java
    1. "└ "+ temp +" %" from
    2. Score score8 = objective.getScore("└ "+ temp +" %");

    I know it can be done because i saw this few times in internet but don't know how to do that.
    Here is screen from server how it should look:
    As you can see in line where is 0% I need to update it to show temperature of player (I wrote plugin for temperature). How to do that?[​IMG]

    bump, still need help with it

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

    men8

    bump
     
  5. Offline

    Monkey_Swag

    men8 did you make an entire different plugin to check the temperature?
     
  6. Offline

    men8

    Monkey_Swag Yes. I made it because I can't find anything that fits my future server. In this plugin I want to learn how to use this scoreboards because this is my 3rd try :p Originally I use BarAPI to show temperature and it works fine, but since 1.8 hack something goes wrong with nms code and Players can see dragon ;____; Normally I would use other way to show players their temperature but all bars are in use (lvl shows air in gas mask, exp shows thirst and there is nothing left to use :( ) So I figured to show all of the informations in scoreboard but I can live with this temperature only :p Problem is when I iterate variable temp. It normally shows in message to check if this works but in scoreboard it creates a new score every iterate so it looks weird and mess with how it looks :( Is there any chance to change score name when fire event? sry for english I wish it is readable :p
     
  7. Offline

    Monkey_Swag

    men8 what exactly is your problem? Do you need to refresh your scoreboard every time that your variable goes up/down? Is that the problem?
     
  8. Offline

    teej107

  9. Offline

    men8

    Monkey_Swag Yes, I want to refresh scoreboard every time value change so player can see this variable showed in score name and no in setScore()
     
  10. Offline

    men8

    teej107 How this getEntries work, because I looked for usage of this method and I'm still confused what it does lol? :p
     
  11. Offline

    teej107

    In your case, it will return a Set containing NAME:, men8, FACTION:, jakies, etc.....
     
  12. Offline

    men8

    teej107 Ok, thanks I'll try this

    teej107 So ok I've checked and it return what I've got in score name, but how to update it without creating new score to show percent every secound?

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

    teej107

    I always put a chat color at the end of a entry so I can distinguish between scores that change. Here is some pseudo code
    PHP:
    for loop through entries
    if string ends with <insert chat color here>
    remove entry
    add entry with 
    new name
     
  14. Offline

    men8

    teej107 So I think I can remove score (whent I fire interact event it dissaper), but I don't know why it don't want to show :(
    Code:java
    1. board.resetScores(score3.getEntry());
    2. score3 = objective.getScore("cos" + temp);
    3. score3.setScore(0);


    Ok, I fix it :) Uffff, only 4 days of thinking :D Thx for help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
Thread Status:
Not open for further replies.

Share This Page