Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.doctordark.hcf.tablist;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- import java.util.stream.Collectors;
- import org.bukkit.ChatColor;
- import org.bukkit.entity.Player;
- import com.doctordark.FactionsPlugin;
- import com.doctordark.hcf.faction.FactionMember;
- import com.doctordark.hcf.faction.type.PlayerFaction;
- import com.doctordark.hcf.tablist.reflection.tablist.TablistEntrySupplier;
- import net.minecraft.util.com.google.common.collect.HashBasedTable;
- import net.minecraft.util.com.google.common.collect.Table;
- public class HardcoreTablistProvider implements TablistEntrySupplier {
- public static final Comparator<PlayerFaction> FACTION_COMPARATOR = (faction1, faction2) -> {
- return Integer.compare(faction1.getOnlinePlayers().size(), faction2.getOnlinePlayers().size());
- };
- public static final Comparator<FactionMember> ROLE_COMPARATOR = (member1, member2) -> {
- return Integer.compare(member1.getRole().ordinal(), member2.getRole().ordinal());
- };
- private final FactionsPlugin plugin;
- public HardcoreTablistProvider(FactionsPlugin plugin) {
- this.plugin = plugin;
- }
- @Override
- public Table<Integer, Integer, String> getEntries(Player player) {
- Table<Integer, Integer, String> entries = HashBasedTable.<Integer, Integer, String>create();
- PlayerFaction faction = plugin.getFactionManager().getPlayerFaction(player);
- if (faction == null) {
- entries.put(0, 0, ChatColor.RED + "Player Info:");
- entries.put(0, 1, ChatColor.GRAY + "Kills: " + plugin.getUserManager().getUser(player.getUniqueId()).getKills());
- entries.put(0, 3, ChatColor.RED + "Your Location");
- entries.put(0, 4, plugin.getFactionManager().getFactionAt(player.getLocation()).getDisplayName(player));
- entries.put(0, 5, ChatColor.GRAY + "(" + player.getLocation().getBlockX() + ", " + player.getLocation().getBlockZ() + ") [" + getCardinalDirection(player) + ']');
- } else {
- entries.put(0, 0, ChatColor.RED + "Home:");
- entries.put(0, 1, ChatColor.GRAY + (faction.getHome() == null ? "Not set" : faction.getHome().getBlockX() + ", " + faction.getHome().getBlockY() + ", " + faction.getHome().getBlockZ()));
- entries.put(0, 3, ChatColor.RED + "Team Info:");
- entries.put(0, 4, ChatColor.GRAY + "DTR: " + String.format("%.2f", faction.getDeathsUntilRaidable()));
- entries.put(0, 5, ChatColor.GRAY + "Online: " + faction.getOnlineMembers().size() + "/" + faction.getMembers().size());
- entries.put(0, 6, ChatColor.GRAY + "Balance: $" + faction.getBalance());
- entries.put(0, 8, ChatColor.RED + "Player Info:");
- entries.put(0, 9, ChatColor.GRAY + "Kills: " + plugin.getUserManager().getUser(player.getUniqueId()).getKills());
- entries.put(0, 11, ChatColor.RED + "Your Location");
- entries.put(0, 12, plugin.getFactionManager().getFactionAt(player.getLocation()).getDisplayName(player));
- entries.put(0, 13, ChatColor.GRAY + "(" + player.getLocation().getBlockX() + ", " + player.getLocation().getBlockZ() + ") [" + getCardinalDirection(player) + ']');
- entries.put(0, 15, ChatColor.RED + "Team Rally:");
- entries.put(0, 16, ChatColor.GRAY + (faction.getRally() == null ? "Not set" : faction.getRally().getBlockX() + ", " + faction.getRally().getBlockY() + ", " + faction.getRally().getBlockZ()));
- entries.put(0, 17, ChatColor.GRAY + (faction.getRally() == null ? "" : "[" + ((int) player.getLocation().distance(faction.getRally())) + "m away]"));
- }
- entries.put(1, 0, plugin.getConfiguration().getScoreboardSidebarTitle());
- if (faction != null) {
- entries.put(1, 2, ChatColor.RED.toString() + faction.getName());
- List<FactionMember> factionMembers = new ArrayList<>(faction.getOnlineMembers().values().stream().collect(Collectors.toList()));
- Collections.sort(factionMembers, ROLE_COMPARATOR);
- for (int i = 3; i < 20; i ++) {
- int exact = i - 3;
- if (factionMembers.size() <= exact) {
- continue;
- }
- if (i == 19 && factionMembers.size() > 19) {
- entries.put(1, i, ChatColor.GREEN + "and " + (factionMembers.size() - 19) + " more...");
- continue;
- }
- FactionMember factionMember = factionMembers.get(exact);
- entries.put(1, i, plugin.getConfiguration().getRelationColourTeammate() + factionMember.getName() + ChatColor.GRAY + factionMember.getRole().getAstrix());
- }
- }
- entries.put(2, 0, ChatColor.RED.toString() + "Faction List");
- List<PlayerFaction> PlayerFactions = new ArrayList<>(plugin.getFactionManager().getFactions().stream().filter(x -> x instanceof PlayerFaction).map(x -> (PlayerFaction) x).filter(x -> x.getOnlineMembers().size() > 0).collect(Collectors.toSet()));
- Collections.sort(PlayerFactions, FACTION_COMPARATOR);
- Collections.reverse(PlayerFactions);
- for (int i = 0; i < 20; i ++) {
- if (i >= PlayerFactions.size()) {
- break;
- }
- PlayerFaction next = PlayerFactions.get(i);
- entries.put(2, i + 1, ChatColor.GRAY.toString() + (i + 1) + ". " + next.getDisplayName(player) + ChatColor.GRAY + " (" + next.getOnlinePlayers().size() + ")");
- }
- return entries;
- }
- public static String getCardinalDirection(Player player) {
- double rotation = (player.getLocation().getYaw() + 180F) % 360.0F;
- if (rotation < 0.0D) {
- rotation += 360.0D;
- }
- if ((0.0D <= rotation) && (rotation < 22.5D)) {
- return "N";
- }
- if ((22.5D <= rotation) && (rotation < 67.5D)) {
- return "NE";
- }
- if ((67.5D <= rotation) && (rotation < 112.5D)) {
- return "E";
- }
- if ((112.5D <= rotation) && (rotation < 157.5D)) {
- return "SE";
- }
- if ((157.5D <= rotation) && (rotation < 202.5D)) {
- return "S";
- }
- if ((202.5D <= rotation) && (rotation < 247.5D)) {
- return "SW";
- }
- if ((247.5D <= rotation) && (rotation < 292.5D)) {
- return "W";
- }
- if ((292.5D <= rotation) && (rotation < 337.5D)) {
- return "NW";
- }
- if ((337.5D <= rotation) && (rotation < 360.0D)) {
- return "N";
- }
- return "";
- }
- @Override
- public String getHeader(Player player) {
- return "";
- }
- @Override
- public String getFooter(Player player) {
- return "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement