Advertisement
qDaaz

Untitled

Jan 30th, 2021
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 17.50 KB | None | 0 0
  1. package me.daaz.vapor.tablist.v1_8;
  2.  
  3. import java.util.*;
  4. import java.util.function.Function;
  5. import java.util.stream.Collectors;
  6.  
  7. import me.daaz.vapor.Vapor;
  8. import me.daaz.vapor.factions.FactionMember;
  9. import me.daaz.vapor.factions.type.PlayerFaction;
  10. import me.daaz.vapor.factions.type.WarzoneFaction;
  11. import me.daaz.vapor.user.FactionUser;
  12. import me.daaz.vapor.utils.CC;
  13. import me.daaz.vapor.utils.Color;
  14. import net.minecraft.util.com.google.common.collect.Lists;
  15. import org.bukkit.Bukkit;
  16. import org.bukkit.ChatColor;
  17. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
  18. import org.bukkit.entity.HumanEntity;
  19. import org.bukkit.entity.Player;
  20.  
  21.  
  22. public class TabProvider_v1_8 implements TabAdapter {
  23.    
  24.     private Vapor plugin;
  25.    
  26.     public TabProvider_v1_8(Vapor plugin) {
  27.         this.plugin = plugin;
  28.     }
  29.  
  30.     public static Comparator<PlayerFaction> FACTION_COMPARATOR;
  31.     public static Comparator<FactionMember> ROLE_COMPARATOR;
  32.  
  33.     static {
  34.         TabProvider_v1_8.FACTION_COMPARATOR = ((playerFaction, targetFaction) -> Integer.compare(playerFaction.getOnlinePlayers().size(), targetFaction.getOnlinePlayers().size()));
  35.         TabProvider_v1_8.ROLE_COMPARATOR = ((playerMember, targetMember) -> Integer.compare(playerMember.getRole().ordinal(), targetMember.getRole().ordinal()));
  36.     }
  37.  
  38.     private static String getCardinalDirection(Player player) {
  39.         double rotation = (player.getLocation().getYaw() - 90) % 360;
  40.  
  41.         if (rotation < 0) {
  42.             rotation += 360.0;
  43.         }
  44.  
  45.         if (0 <= rotation && rotation < 22.5) {
  46.             return "W";
  47.         } else if (22.5 <= rotation && rotation < 67.5) {
  48.             return "NW";
  49.         } else if (67.5 <= rotation && rotation < 112.5) {
  50.             return "N";
  51.         } else if (112.5 <= rotation && rotation < 157.5) {
  52.             return "NE";
  53.         } else if (157.5 <= rotation && rotation < 202.5) {
  54.             return "E";
  55.         } else if (202.5 <= rotation && rotation < 247.5) {
  56.             return "SE";
  57.         } else if (247.5 <= rotation && rotation < 292.5) {
  58.             return "S";
  59.         } else if (292.5 <= rotation && rotation < 337.5) {
  60.             return "SW";
  61.         } else if (337.5 <= rotation && rotation < 360.0) {
  62.             return "W";
  63.         } else {
  64.             return null;
  65.         }
  66.     }
  67.  
  68.     @SuppressWarnings({"deprecation", "unchecked", "rawtypes"})
  69.     public String factions(Player player, String path) {
  70.         @SuppressWarnings("unused")
  71.         Map<PlayerFaction, Integer> factionOnlineMap = new HashMap<PlayerFaction, Integer>();
  72.         PlayerFaction playerFaction = Vapor.get().getFactionManager().getPlayerFaction(player.getUniqueId());
  73.         FactionUser user = Vapor.get().getUserManager().getUser(player.getUniqueId());
  74.  
  75.         Map<PlayerFaction, Integer> map = new HashMap<PlayerFaction, Integer>();
  76.         for (Player players : Bukkit.getOnlinePlayers()) {
  77.             PlayerFaction pFac = Vapor.get().getFactionManager().getPlayerFaction(players);
  78.             if (pFac != null) {
  79.                 map.put(pFac, map.getOrDefault(pFac, 0) + 1);
  80.             }
  81.         }
  82.         if (path.contains("%player_kills%")) {
  83.             path = path.replace("%player_kills%", String.valueOf(user.getKills()));
  84.         }
  85.         if (path.contains("%player_deaths%")) {
  86.             path = path.replace("%player_deaths%", String.valueOf(user.getDeaths()));
  87.         }
  88.         if (path.contains("%player_balance%")) {
  89.             path = path.replace("%player_balance%", String.valueOf(Vapor.get().getEconomyManager().getBalance(player.getUniqueId())));
  90.         }
  91.         if (path.contains("%player_lives%")) {
  92.             path = path.replace("%player_lives%", String.valueOf(Vapor.get().getDeathbanManager().getLives(player.getUniqueId())));
  93.         }
  94.         if (path.contains("%faction_location%")) {
  95.             path = path.replace("%faction_location%", Vapor.get().getFactionManager().getClaimAt(player.getLocation()).getFaction().getDisplayName(player));
  96.         }
  97.         if (path.contains("%player_location%")) {
  98.             path = path.replace("%player_location%", "(" + player.getLocation().getBlockX() + ", " + player.getLocation().getBlockZ() + ") [" + getCardinalDirection(player) + "]");
  99.         }
  100.         List<PlayerFaction> PlayerTeams = new ArrayList<>(Vapor.get().getFactionManager().getFactions().stream().filter(x -> x instanceof PlayerFaction).map(x -> (PlayerFaction) x).filter(x -> x.getOnlineMembers().size() > 0).collect(Collectors.toSet()));
  101.         Collections.sort(PlayerTeams, FACTION_COMPARATOR);
  102.         Collections.reverse(PlayerTeams);
  103.  
  104.         for (int i = 0; i < 20; i++) {
  105.             if (i >= PlayerTeams.size()) {
  106.  
  107.                 path = path.replace("%f_list_" + i + "%", "");
  108.             } else {
  109.                 PlayerFaction next = PlayerTeams.get(i);
  110.                 path = path.replace("%f_list_" + (i + 1) + "%", CC.WHITE + (i + 1) + CC.WHITE + ") " + next.getDisplayName(player) + CC.GRAY + " (" + CC.WHITE + next.getOnlinePlayers().size() + CC.GRAY + ")");
  111.             }
  112.         }
  113.         if (path.contains("%online_players%")) {
  114.             path = path.replace("%online_players%", String.valueOf(Bukkit.getServer().getOnlinePlayers().size()));
  115.         }
  116.         if (path.contains("%player_ping%")) {
  117.             path = path.replace("%player_ping%", String.valueOf(((CraftPlayer) player).getHandle().ping));
  118.         }
  119.         if (Vapor.get().getFactionManager().getPlayerFaction(player) != null) {
  120.             if (path.contains("%faction_info%")) {
  121.                 path = path.replace("%faction_info%", Color.translate(Vapor.get().getTabFile().getString("FACTION.FACTION-INFO")));
  122.             }
  123.             if (path.contains("%faction_name%")) {
  124.                 path = path.replace("%faction_name%", Color.translate(Vapor.get().getTabFile().getString("FACTION.NAME").replace("%name%", Vapor.get().getFactionManager().getPlayerFaction(player).getName())));
  125.             }
  126.             if (path.contains("%faction_points%")) {
  127.                 path = path.replace("%faction_points%", Color.translate(Vapor.get().getTabFile().getString("FACTION.POINTS").replace("%points%", String.valueOf(Vapor.get().getFactionManager().getPlayerFaction(player).getPoints()))));
  128.             }
  129.             if (path.contains("%faction_dtr%")) {
  130.                 path = path.replace("%faction_dtr%", Color.translate(Vapor.get().getTabFile().getString("FACTION.DTR").replace("%dtr%", new StringBuilder(String.valueOf(Vapor.get().getFactionManager().getPlayerFaction(player.getUniqueId()).getDtrColour().toString() + Vapor.get().getFactionManager().getPlayerFaction(player).getDeathsUntilRaidable())))));
  131.             }
  132.             if (path.contains("%faction_home%")) {
  133.                 if (Vapor.get().getFactionManager().getPlayerFaction(player).getHome() != null) {
  134.                     path = path.replace("%faction_home%", Color.translate(Vapor.get().getTabFile().getString("FACTION.HOME").replace("%home%", Vapor.get().getFactionManager().getPlayerFaction(player).getHome().getBlockX() + ", " + Vapor.get().getFactionManager().getPlayerFaction(player).getHome().getBlockY() + ", " + Vapor.get().getFactionManager().getPlayerFaction(player).getHome().getBlockZ())));
  135.                 } else {
  136.                     path = path.replace("%faction_home%", Vapor.get().getTabFile().getString("NO-FACTION.HOME"));
  137.                 }
  138.             }
  139.             if (path.contains("%faction_leader%")) {
  140.                 path = path.replace("%faction_leader%", Color.translate(Vapor.get().getTabFile().getString("FACTION.LEADER").replace("%leader%", Vapor.get().getFactionManager().getPlayerFaction(player).getLeader().getName())));
  141.             }
  142.             if (path.contains("%faction_balance%")) {
  143.                 path = path.replace("%faction_balance%", Color.translate(Vapor.get().getTabFile().getString("FACTION.BALANCE").replace("%balance%", String.valueOf(Vapor.get().getFactionManager().getPlayerFaction(player).getBalance()))));
  144.             }
  145.  
  146.             List<Player> online = Lists.newArrayList(playerFaction.getOnlinePlayers());
  147.             online.sort(Comparator.comparing((Function<? super Player, ? extends Comparable>) HumanEntity::getName));
  148.             online.sort(Comparator.comparingInt(o -> playerFaction.getMember(o).getRole().ordinal()));
  149.             for (int j = 0; j < 20; ++j) {
  150.                 if (j >= online.size()) {
  151.                     path = path.replace("%f_member_" + j + "%", "");
  152.                 } else {
  153.                     path = path.replace("%f_member_" + (j + 1) + "%", "&a" + playerFaction.getMember(online.get(j)).getRole().getAstrix() + online.get(j).getName());
  154.                 }
  155.             }
  156.         } else {
  157.             if (path.contains("%faction_name%")) {
  158.                 path = path.replace("%faction_name%", Color.translate(Vapor.get().getTabFile().getString("NO-FACTION.NAME")));
  159.             }
  160.             if (path.contains("%faction_info%")) {
  161.                 path = path.replace("%faction_info%", Color.translate(Vapor.get().getTabFile().getString("NO-FACTION.FACTION-INFO")));
  162.             }
  163.             if (path.contains("%faction_dtr%")) {
  164.                 path = path.replace("%faction_dtr%", Color.translate(Vapor.get().getTabFile().getString("NO-FACTION.DTR")));
  165.             }
  166.             if (path.contains("%faction_home%")) {
  167.                 path = path.replace("%faction_home%", Color.translate(Vapor.get().getTabFile().getString("NO-FACTION.HOME")));
  168.             }
  169.             if (path.contains("%faction_leader%")) {
  170.                 path = path.replace("%faction_leader%", Color.translate(Vapor.get().getTabFile().getString("NO-FACTION.LEADER")));
  171.             }
  172.             if (path.contains("%faction_points%")) {
  173.                 path = path.replace("%faction_points%", Color.translate(Vapor.get().getTabFile().getString("NO-FACTION.POINTS")));
  174.             }
  175.             if (path.contains("%faction_balance%")) {
  176.                 path = path.replace("%faction_balance%", Color.translate(Vapor.get().getTabFile().getString("NO-FACTION.BALANCE")));
  177.             }
  178.             for (int k = 1; k < 31; ++k) {
  179.                 path = path.replace("%f_member_" + k + "%", "");
  180.             }
  181.         }
  182.         return path;
  183.     }
  184.    
  185.     @Override
  186.     public String getHeader(Player player) {
  187.         return Vapor.get().getTabFile().getString("HEADER-TEXT");
  188.     }
  189.  
  190.     @Override
  191.     public String getFooter(Player player) {
  192.         return Vapor.get().getTabFile().getString("FOOTER-TEXT");
  193.     }
  194.  
  195.  
  196.     @Override
  197.     public List<TabEntry> getLines(Player player) {
  198.         List<TabEntry> tab = new ArrayList<>();
  199.         tab.add(new TabEntry(0, 0, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-1"))));
  200.         tab.add(new TabEntry(0, 1, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-2"))));
  201.         tab.add(new TabEntry(0, 2, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-3"))));
  202.         tab.add(new TabEntry(0, 3, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-4"))));
  203.         tab.add(new TabEntry(0, 4, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-5"))));
  204.         tab.add(new TabEntry(0, 5, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-6"))));
  205.         tab.add(new TabEntry(0, 6, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-7"))));
  206.         tab.add(new TabEntry(0, 7, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-8"))));
  207.         tab.add(new TabEntry(0, 8, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-9"))));
  208.         tab.add(new TabEntry(0, 9, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-10"))));
  209.         tab.add(new TabEntry(0, 10, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-11"))));
  210.         tab.add(new TabEntry(0, 11, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-12"))));
  211.         tab.add(new TabEntry(0, 12, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-13"))));
  212.         tab.add(new TabEntry(0, 13, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-14"))));
  213.         tab.add(new TabEntry(0, 14, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-15"))));
  214.         tab.add(new TabEntry(0, 15, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-16"))));
  215.         tab.add(new TabEntry(0, 16, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-17"))));
  216.         tab.add(new TabEntry(0, 17, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-18"))));
  217.         tab.add(new TabEntry(0, 18, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-19"))));
  218.         tab.add(new TabEntry(0, 19, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.1-20"))));
  219.  
  220.         tab.add(new TabEntry(1, 0, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-1"))));
  221.         tab.add(new TabEntry(1, 1, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-2"))));
  222.         tab.add(new TabEntry(1, 2, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-3"))));
  223.         tab.add(new TabEntry(1, 3, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-4"))));
  224.         tab.add(new TabEntry(1, 4, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-5"))));
  225.         tab.add(new TabEntry(1, 5, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-6"))));
  226.         tab.add(new TabEntry(1, 6, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-7"))));
  227.         tab.add(new TabEntry(1, 7, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-8"))));
  228.         tab.add(new TabEntry(1, 8, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-9"))));
  229.         tab.add(new TabEntry(1, 9, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-10"))));
  230.         tab.add(new TabEntry(1, 10, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-11"))));
  231.         tab.add(new TabEntry(1, 11, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-12"))));
  232.         tab.add(new TabEntry(1, 12, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-13"))));
  233.         tab.add(new TabEntry(1, 13, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-14"))));
  234.         tab.add(new TabEntry(1, 14, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-15"))));
  235.         tab.add(new TabEntry(1, 15, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-16"))));
  236.         tab.add(new TabEntry(1, 16, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-17"))));
  237.         tab.add(new TabEntry(1, 17, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-18"))));
  238.         tab.add(new TabEntry(1, 18, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-19"))));
  239.         tab.add(new TabEntry(1, 19, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.2-20"))));
  240.  
  241.         tab.add(new TabEntry(2, 0, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-1"))));
  242.         tab.add(new TabEntry(2, 1, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-2"))));
  243.         tab.add(new TabEntry(2, 2, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-3"))));
  244.         tab.add(new TabEntry(2, 3, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-4"))));
  245.         tab.add(new TabEntry(2, 4, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-5"))));
  246.         tab.add(new TabEntry(2, 5, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-6"))));
  247.         tab.add(new TabEntry(2, 6, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-7"))));
  248.         tab.add(new TabEntry(2, 7, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-8"))));
  249.         tab.add(new TabEntry(2, 8, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-9"))));
  250.         tab.add(new TabEntry(2, 9, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-10"))));
  251.         tab.add(new TabEntry(2, 10, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-11"))));
  252.         tab.add(new TabEntry(2, 11, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-12"))));
  253.         tab.add(new TabEntry(2, 12, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-13"))));
  254.         tab.add(new TabEntry(2, 13, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-14"))));
  255.         tab.add(new TabEntry(2, 14, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-15"))));
  256.         tab.add(new TabEntry(2, 15, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-16"))));
  257.         tab.add(new TabEntry(2, 16, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-17"))));
  258.         tab.add(new TabEntry(2, 17, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-18"))));
  259.         tab.add(new TabEntry(2, 18, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-19"))));
  260.         tab.add(new TabEntry(2, 19, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.3-20"))));
  261.  
  262.         tab.add(new TabEntry(3, 0, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-1"))));
  263.         tab.add(new TabEntry(3, 1, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-2"))));
  264.         tab.add(new TabEntry(3, 2, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-3"))));
  265.         tab.add(new TabEntry(3, 3, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-4"))));
  266.         tab.add(new TabEntry(3, 4, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-5"))));
  267.         tab.add(new TabEntry(3, 5, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-6"))));
  268.         tab.add(new TabEntry(3, 6, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-7"))));
  269.         tab.add(new TabEntry(3, 7, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-8"))));
  270.         tab.add(new TabEntry(3, 8, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-9"))));
  271.         tab.add(new TabEntry(3, 9, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-10"))));
  272.         tab.add(new TabEntry(3, 10, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-11"))));
  273.         tab.add(new TabEntry(3, 11, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-12"))));
  274.         tab.add(new TabEntry(3, 12, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-13"))));
  275.         tab.add(new TabEntry(3, 13, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-14"))));
  276.         tab.add(new TabEntry(3, 14, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-15"))));
  277.         tab.add(new TabEntry(3, 15, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-16"))));
  278.         tab.add(new TabEntry(3, 16, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-17"))));
  279.         tab.add(new TabEntry(3, 17, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-18"))));
  280.         tab.add(new TabEntry(3, 18, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-19"))));
  281.         tab.add(new TabEntry(3, 19, factions(player, Vapor.get().getTabFile().getString("TAB.LINES.4-20"))));
  282.  
  283.         return tab;
  284.     }
  285.  
  286. }
  287.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement