Search in sources :

Example 1 with RegionLoader

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("");
    }
}
Also used : DisplaySlot(org.bukkit.scoreboard.DisplaySlot) Team(org.bukkit.scoreboard.Team) FloorLoader(mc.dragons.core.gameobject.floor.FloorLoader) HashMap(java.util.HashMap) Player(org.bukkit.entity.Player) Score(org.bukkit.scoreboard.Score) Objective(org.bukkit.scoreboard.Objective) Dragons(mc.dragons.core.Dragons) Scoreboard(org.bukkit.scoreboard.Scoreboard) Floor(mc.dragons.core.gameobject.floor.Floor) GameObjectType(mc.dragons.core.gameobject.GameObjectType) RegionLoader(mc.dragons.core.gameobject.region.RegionLoader) Map(java.util.Map) Region(mc.dragons.core.gameobject.region.Region) ChatColor(org.bukkit.ChatColor) Bukkit(org.bukkit.Bukkit) Floor(mc.dragons.core.gameobject.floor.Floor) Scoreboard(org.bukkit.scoreboard.Scoreboard) Region(mc.dragons.core.gameobject.region.Region) Team(org.bukkit.scoreboard.Team) RegionLoader(mc.dragons.core.gameobject.region.RegionLoader)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Dragons (mc.dragons.core.Dragons)1 GameObjectType (mc.dragons.core.gameobject.GameObjectType)1 Floor (mc.dragons.core.gameobject.floor.Floor)1 FloorLoader (mc.dragons.core.gameobject.floor.FloorLoader)1 Region (mc.dragons.core.gameobject.region.Region)1 RegionLoader (mc.dragons.core.gameobject.region.RegionLoader)1 Bukkit (org.bukkit.Bukkit)1 ChatColor (org.bukkit.ChatColor)1 Player (org.bukkit.entity.Player)1 DisplaySlot (org.bukkit.scoreboard.DisplaySlot)1 Objective (org.bukkit.scoreboard.Objective)1 Score (org.bukkit.scoreboard.Score)1 Scoreboard (org.bukkit.scoreboard.Scoreboard)1 Team (org.bukkit.scoreboard.Team)1