Difference between revisions of "BKCommonLib/Scoreboards"

From BergerHealer Wiki
Jump to navigation Jump to search
 
(No difference)

Latest revision as of 00:20, 10 June 2021

« Go back

ScoreBoards

Scoreboards are new functions that came with mc 1.5. It allows you to popup a gui in the screen of a player and put custom inferomation inside of it. This already has a very weak api in NMS but we decided to redo it and support global settings as well. The Scoreboards from BKCommonLib allows you to merge with orther plugins unlike the NMS api.

Here is an example:

Player player = Bukkit.getOnlinePlayers()[0]; //just get an online player as example
CommonScoreboard  board = CommonScoreboard.get(player); //Get the scoreboard form the player
CommonObjective sidebar = board.getObjective(Display.SIDEBAR); //Get the sidebar scoreboard
sidebar.show(); //Shwo the sidebar (use siderbar.hide() to hide)
sidebar.createScore("kills", 17); //Create a new score called 'kills' and make the value 17

You can also edit the score if the value needs to be changed.

CommonScore kills = siderbar.getScore("kills");
kills.setValue(18); //Change the value to 18 kills
kills.update(); //Don't forget ot update the score after changing it!

And if the display name from the sidebar is not the thing you want, you can allways call this:

sidebar.setDisplayName("PvP Info");

You can also create Scoreboard teams:

CommonTeam team = CommonScoreboard.getTeam("example");
if(team == nul) {
    team = CommonScoreboard.createTeam("example");
    team.setSendToAll(true); //set if team is visible for everyone
    team.show(); //Create team
    team.setDisplayName("Example"); //Not sure where this is used for
    team.setPrefix(ChatColor.RED.toString()); //Prefix (in front of name)
    team.setSuffix(" - Example");
}

team.addPlayer(player);

These are all available displays:

  • LIST - Tab list (i think)
  • SIDEBAR - Right sidebar of your screen
  • BELOWNAME - Below nametags

Showing off a BELOWNAME example:

Player player = event.getPlayer(); //Player who will see the food from lenis0012
Player lenis0012 = Bukkit.getPlayer("lenis0012"); //Example player to show food from
CommonObjective obj = CommonScoreboard.get(player).getObjective(Display.BELOWNAME);
obj.setDisplayName("Hunger");
obj.show(); //Allways call this
obj.createScore("lenis0012", "lenis0012", (int) lenis0012.getFoodLevel());

Result of nametag:

lenis0012

20 Hunger