use of mc.dragons.core.gameobject.region.RegionLoader in project DragonsOnline by UniverseCraft.
the class SidebarManager method updateScoreboard.
public void updateScoreboard(Player player) {
if (player == null) {
return;
}
Scoreboard scoreboard = player.getScoreboard();
if (scoreboard == null) {
instance.getLogger().warning("Attempted to update scoreboard for " + player.getName() + " but they did not have a scoreboard");
return;
}
RegionLoader regionLoader = GameObjectType.REGION.getLoader();
User user = UserLoader.fromPlayer(player);
if (user == null || !user.isInitialized()) {
instance.getLogger().verbose("Skipping scoreboard update for uninitialized player " + player.getName());
return;
}
Team floor = scoreboard.getTeam("FLOOR");
floor.setPrefix(ChatColor.GRAY + "Floor: ");
Floor currentFloor = FloorLoader.fromWorld(player.getWorld());
String floorName = currentFloor == null ? ChatColor.RED + "Unknown" : currentFloor.getDisplayName();
floor.setSuffix(getScrolledFrameAndIncrement(player, "Floor", floorName));
Team server = scoreboard.getTeam("SERVER");
server.setPrefix(ChatColor.GRAY + "Server: " + ChatColor.WHITE);
server.setSuffix(instance.getServerName());
Team online = scoreboard.getTeam("ONLINE");
online.setPrefix(ChatColor.GRAY + "Online: " + ChatColor.WHITE);
online.setSuffix(String.valueOf(Bukkit.getOnlinePlayers().stream().filter(p -> p.canSee(p)).count()) + " / " + Bukkit.getMaxPlayers());
Team level = scoreboard.getTeam("LEVEL");
level.setPrefix(ChatColor.GRAY + "Level: " + ChatColor.WHITE);
level.setSuffix((user.getLevelColor() == ChatColor.GRAY ? "" : user.getLevelColor().toString()) + user.getLevel());
Team xp = scoreboard.getTeam("XP");
xp.setPrefix(ChatColor.GRAY + "XP: " + ChatColor.WHITE);
xp.setSuffix(String.valueOf(user.getXP()) + " (" + (int) Math.floor(user.getLevelProgress() * 100.0F) + "%)");
Team rank = scoreboard.getTeam("RANK");
rank.setPrefix(ChatColor.GRAY + "Rank: " + ChatColor.WHITE);
rank.setSuffix((user.getRank().getNameColor() == ChatColor.GRAY ? "" : user.getRank().getNameColor()) + user.getRank().getShortName());
Team gold = scoreboard.getTeam("GOLD");
gold.setPrefix(ChatColor.GRAY + "Gold: " + ChatColor.WHITE);
gold.setSuffix(ChatColor.GOLD + "" + user.getGold());
Team location = scoreboard.getTeam("LOCATION");
location.setPrefix(ChatColor.GRAY + "Location: " + ChatColor.WHITE);
location.setSuffix(String.valueOf(player.getLocation().getBlockX()) + ", " + player.getLocation().getBlockZ());
Team region = scoreboard.getTeam("REGION");
Region smallestRegion = regionLoader.getSmallestRegionByLocation(player.getLocation(), false);
String regionName = smallestRegion == null ? "None" : smallestRegion.getFlags().getString("fullname");
region.setPrefix(ChatColor.GRAY + "Region: " + ChatColor.WHITE);
region.setSuffix(getScrolledFrameAndIncrement(player, "Region", regionName));
Team staffStatus = scoreboard.getTeam("STAFF_STATUS");
if (user.getSystemProfile() != null) {
staffStatus.setPrefix(ChatColor.DARK_GREEN + "- " + ChatColor.GREEN + "ON DUTY");
staffStatus.setSuffix(ChatColor.DARK_GREEN + " -");
} else {
staffStatus.setPrefix("");
staffStatus.setSuffix("");
}
}
Aggregations