Adding Scoreboard with Teams' Players' Names and Health in a different Class

Discussion in 'Plugin Development' started by RAFA_GATO_FOFO, Apr 5, 2014.

Thread Status:
Not open for further replies.
  1. Hey guys,

    So my problem/doubt is kind of confusing, hopefully you'll understand.

    First of all I want to code this in a different class for organization purposes but I don't really understand how to do it.


    Secondly, this is what I currently have. Nearly all of it came from @chasechocolat 's thread. All this code is currently in my Main.Java but I want to change it over to HealthBoard.Java. Also I placed it under onPlayerJoin since I don't know any other way to do it.
    Show Spoiler

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerJoin (final PlayerJoinEvent pje) {
    4. ScoreboardManager manager = Bukkit.getScoreboardManager();
    5. Scoreboard board = manager.getNewScoreboard();
    6. Team team = board.registerNewTeam("teamname");
    7. Player player = pje.getPlayer();
    8. //Adding players
    9. team.addPlayer(player);
    10.  
    11. //Removing players
    12.  
    13. //Adding prefixes (shows up in player list before the player's name, supports ChatColors)
    14. team.setPrefix("");
    15.  
    16. //Adding suffixes (shows up in player list after the player's name, supports ChatColors)
    17. team.setSuffix("");
    18.  
    19. //Setting the display name
    20. team.setDisplayName("display name");
    21.  
    22. //Making invisible players on the same team have a transparent body
    23. team.setCanSeeFriendlyInvisibles(true);
    24.  
    25. //Making it so players can't hurt others on the same team
    26. team.setAllowFriendlyFire(false);
    27.  
    28. Objective objective = board.registerNewObjective("test", "dummy");
    29. //Setting where to display the scoreboard/objective (either SIDEBAR, PLAYER_LIST or BELOW_NAME)
    30. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    31.  
    32. //Setting the display name of the scoreboard/objective
    33. objective.setDisplayName(ChatColor.RED + "Team Health");
    34.  
    35. Score score = objective.getScore(Bukkit.getOfflinePlayer(player.getDisplayName())); //Get a fake offline player
    36. score.setScore((int) player.getHealth());
    37.  
    38. player.setScoreboard(board);



    I'm using the plugin UltraHardcore to make teams with a random number of players. I've imported UltraHardcore as an external jar for my plugin development in Eclipse.
    What I'm looking to do in my plugin is having the scoreboard automatically update (which I have no idea how to do) whenever a player from the player's team loses health.
    I also want the team name as the title for the board.

    What I have right now allows the players to have a scoreboard with the title Team Health and the players health but it's not updating.

    So basically the layout would be:
    Scoreboard Title: <TeamName> (according to UltraHardcore plugin)
    Line 1: <PlayerName> <Health>
    Following Lines: <TeamMateName> <TeamMateHealth>


    If anyone is willing to help me please post away I'll take all the help I can get. I know this is sort of like a request but I believe it fits in this category since I'm requesting a piece of code and not an entire plugin.

    Anyway if you read all of this, cheers!

    Bring up the post, still looking for help...

    Up up up, still haven't figured out how to make the names fit the scoreboard.
    I've got the adjacent class working!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Still need help making names in the scoreboard...
     
Thread Status:
Not open for further replies.

Share This Page