Jump to content

[1.7.2] Grabbing information from the scoreboard


NomNuggetNom

Recommended Posts

Here's my example:

R8rr16xx.png

 

So I want to strip the following information:

- The title. In this case, "[1/3] Ends in 19:03"

- The two teams, "Red" and "Blue"

- The score of each team, 0 and 0 here.

I was poking around in the scoreboard code and just could not figure it out. Any help is greatly appreciated.

 

Here's what I've gotten so far:

- The title.

- Getting the objective names returns "§9Blue" and "§cRed"

- Checking these values returns 0, even when Blue team has 1 point:

ScoreObjective blueObjective = board.getObjective("§9Blue");
System.out.println(board.func_96529_a("§9Blue", blueObjective).getScorePoints());

Link to comment
Share on other sites

Managed to get the title of the scoreboard like this:

		ScoreObjective scoreobjective = this.mc.theWorld.getScoreboard().func_96539_a(1);
		String scoreTitle = scoreobjective.getDisplayName();

 

EDIT:

Actually this seems to be crashing sometimes :\. Changed it to this:

	        if (this.mc.theWorld.getScoreboard().func_96539_a(0) != null) {
			boardTitle = this.mc.theWorld.getScoreboard().func_96539_a(0).getDisplayName();
        } else {
        	boardTitle = this.mc.theWorld.getScoreboard().func_96539_a(1).getDisplayName();
        }

Link to comment
Share on other sites

I did it! :D. I even wrote some functions for it:

 

Getting the title, in my case "[1/3] Ends in 19:03":

/**
 * Returns the "title" of the scoreboard's display.
 */
public static String getBoardTitle(Scoreboard board) {
	// Grab the main objective of the scoreboard.
        ScoreObjective titleObjective = board.func_96539_a(1);
        
        // Null check. For some reason, sometimes _a(0) works and other times _a(1) works.
        if (board.func_96539_a(0) != null) {
		return board.func_96539_a(0).getDisplayName();
        } else {
        	return board.func_96539_a(1).getDisplayName();
        }
        }

 

In my example, I would just need to do:

	        System.out.println(Stats.getBoardTitle(this.mc.theWorld.getScoreboard()));

 

Getting the score of the teams:

/**
 * Returns the score of the "team" (really a fake player) on the scoreboard.
 */
public static int getTeamScore(String team, Scoreboard board) {
	// Grab the main objective of the scoreboard.
        ScoreObjective objective = board.func_96539_a(1);
        
        // Collection of all scoreboard entries.
        Collection collection = board.func_96534_i(objective);
        
        // Iterate through the collection of entries.
        Iterator iterator1 = collection.iterator();
        while (iterator1.hasNext()) {
        Score score = (Score)iterator1.next();
        
        // Check if the name of the "team" (player) is what we're looking for.
        // In actuality, it would be better to use an equals check e.g.:
        // if (score1.getPlayerName().equals(team)) {
        if (score.getPlayerName().contains(team)) {
        	
        	// Get the score of the "team" (player) and return it.
	        return score.getScorePoints();
        }
        }
        return -1;
}

 

So, for my example, I could just do:

        System.out.println(Stats.getTeamScore("Blue", board));
        System.out.println(Stats.getTeamScore("Red", board));

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.