Jump to content

1.12.2 Set scoreboard objective display slot


ptolemy2002

Recommended Posts

I am having problems setting the scoreboard objective display slot. I have a simple score called "score" (for testing purposes), and I want to set the slot to be in the sidebar. I created the score through my code using this method:

 

/**
	 * Set the specified score of the entity. Will create score is score does not exist.
	 * 
	 * @param world
	 * @param entity
	 * @param objective
	 * @param value
	 */
	public static void setScore(World world, Entity entity, String objective, int value) {
		if (entity instanceof EntityPlayer) {
			 world.getScoreboard().getOrCreateScore(entity.getName(), world.getScoreboard().getObjective(objective)).setScorePoints(value);
			 //world.getScoreboard().broadcastScoreUpdate(entity.getName(), world.getScoreboard().getObjective(objective));
		} else {
			 world.getScoreboard().getOrCreateScore(entity.getCachedUniqueIdString(), world.getScoreboard().getObjective(objective)).setScorePoints(value);
			 //world.getScoreboard().broadcastScoreUpdate(entity.getCachedUniqueIdString(), world.getScoreboard().getObjective(objective));
		}
	}

 

When I try to run the command for this, I get the error that the score doesn't exist. When I try to do it from this method:

/**
	 * Set the display slot of the score.
	 * 
	 * Can be list, sidebar, or belowName.
	 * 
	 * @param world
	 * @param slot
	 * @param objective
	 */
	public static void setScoreDisplaySlot(World world, String slot, String objective) {
		Scoreboard scoreboard = world.getScoreboard();
		
		int i = Scoreboard.getObjectiveDisplaySlotNumber(slot);
		
		ScoreObjective objectiveToUse = scoreboard.getObjective(objective);
		
		scoreboard.setObjectiveInDisplaySlot(i, objectiveToUse);
	}

 

(I got that method from the CommandScore class)

 

nothing happens.

 

If I try to create the score in the function using this code:

 

if (!scoreboard.getObjectiveNames().contains(objective)) {
			scoreboard.addScoreObjective(objective, IScoreCriteria.DUMMY);
		}

 

the code in my statement runs, but I get an error that the score already existed.

 

If the score already existed, then the command would have been able to sense it, and my code to create the objective should not have run.

 

Getting and setting the score seems to work perfectly fine in the code.

Edited by ptolemy2002
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.