Advertisement
SenpaiSkidzv1

HardCoreTablistProvider.java

Jun 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. package com.doctordark.hcf.tablist;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5. import java.util.Comparator;
  6. import java.util.List;
  7. import java.util.stream.Collectors;
  8.  
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.entity.Player;
  11.  
  12. import com.doctordark.FactionsPlugin;
  13. import com.doctordark.hcf.faction.FactionMember;
  14. import com.doctordark.hcf.faction.type.PlayerFaction;
  15. import com.doctordark.hcf.tablist.reflection.tablist.TablistEntrySupplier;
  16.  
  17. import net.minecraft.util.com.google.common.collect.HashBasedTable;
  18. import net.minecraft.util.com.google.common.collect.Table;
  19.  
  20. public class HardcoreTablistProvider implements TablistEntrySupplier {
  21.  
  22. public static final Comparator<PlayerFaction> FACTION_COMPARATOR = (faction1, faction2) -> {
  23. return Integer.compare(faction1.getOnlinePlayers().size(), faction2.getOnlinePlayers().size());
  24. };
  25.  
  26. public static final Comparator<FactionMember> ROLE_COMPARATOR = (member1, member2) -> {
  27. return Integer.compare(member1.getRole().ordinal(), member2.getRole().ordinal());
  28. };
  29.  
  30. private final FactionsPlugin plugin;
  31.  
  32. public HardcoreTablistProvider(FactionsPlugin plugin) {
  33. this.plugin = plugin;
  34. }
  35.  
  36. @Override
  37. public Table<Integer, Integer, String> getEntries(Player player) {
  38. Table<Integer, Integer, String> entries = HashBasedTable.<Integer, Integer, String>create();
  39. PlayerFaction faction = plugin.getFactionManager().getPlayerFaction(player);
  40.  
  41. if (faction == null) {
  42. entries.put(0, 0, ChatColor.RED + "Player Info:");
  43. entries.put(0, 1, ChatColor.GRAY + "Kills: " + plugin.getUserManager().getUser(player.getUniqueId()).getKills());
  44.  
  45. entries.put(0, 3, ChatColor.RED + "Your Location");
  46. entries.put(0, 4, plugin.getFactionManager().getFactionAt(player.getLocation()).getDisplayName(player));
  47. entries.put(0, 5, ChatColor.GRAY + "(" + player.getLocation().getBlockX() + ", " + player.getLocation().getBlockZ() + ") [" + getCardinalDirection(player) + ']');
  48.  
  49. } else {
  50. entries.put(0, 0, ChatColor.RED + "Home:");
  51. entries.put(0, 1, ChatColor.GRAY + (faction.getHome() == null ? "Not set" : faction.getHome().getBlockX() + ", " + faction.getHome().getBlockY() + ", " + faction.getHome().getBlockZ()));
  52.  
  53. entries.put(0, 3, ChatColor.RED + "Team Info:");
  54. entries.put(0, 4, ChatColor.GRAY + "DTR: " + String.format("%.2f", faction.getDeathsUntilRaidable()));
  55. entries.put(0, 5, ChatColor.GRAY + "Online: " + faction.getOnlineMembers().size() + "/" + faction.getMembers().size());
  56. entries.put(0, 6, ChatColor.GRAY + "Balance: $" + faction.getBalance());
  57.  
  58. entries.put(0, 8, ChatColor.RED + "Player Info:");
  59. entries.put(0, 9, ChatColor.GRAY + "Kills: " + plugin.getUserManager().getUser(player.getUniqueId()).getKills());
  60.  
  61. entries.put(0, 11, ChatColor.RED + "Your Location");
  62. entries.put(0, 12, plugin.getFactionManager().getFactionAt(player.getLocation()).getDisplayName(player));
  63. entries.put(0, 13, ChatColor.GRAY + "(" + player.getLocation().getBlockX() + ", " + player.getLocation().getBlockZ() + ") [" + getCardinalDirection(player) + ']');
  64.  
  65. entries.put(0, 15, ChatColor.RED + "Team Rally:");
  66. entries.put(0, 16, ChatColor.GRAY + (faction.getRally() == null ? "Not set" : faction.getRally().getBlockX() + ", " + faction.getRally().getBlockY() + ", " + faction.getRally().getBlockZ()));
  67. entries.put(0, 17, ChatColor.GRAY + (faction.getRally() == null ? "" : "[" + ((int) player.getLocation().distance(faction.getRally())) + "m away]"));
  68. }
  69.  
  70. entries.put(1, 0, plugin.getConfiguration().getScoreboardSidebarTitle());
  71.  
  72. if (faction != null) {
  73. entries.put(1, 2, ChatColor.RED.toString() + faction.getName());
  74. List<FactionMember> factionMembers = new ArrayList<>(faction.getOnlineMembers().values().stream().collect(Collectors.toList()));
  75. Collections.sort(factionMembers, ROLE_COMPARATOR);
  76. for (int i = 3; i < 20; i ++) {
  77. int exact = i - 3;
  78. if (factionMembers.size() <= exact) {
  79. continue;
  80. }
  81. if (i == 19 && factionMembers.size() > 19) {
  82. entries.put(1, i, ChatColor.GREEN + "and " + (factionMembers.size() - 19) + " more...");
  83. continue;
  84. }
  85. FactionMember factionMember = factionMembers.get(exact);
  86. entries.put(1, i, plugin.getConfiguration().getRelationColourTeammate() + factionMember.getName() + ChatColor.GRAY + factionMember.getRole().getAstrix());
  87. }
  88. }
  89. entries.put(2, 0, ChatColor.RED.toString() + "Faction List");
  90. 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()));
  91. Collections.sort(PlayerFactions, FACTION_COMPARATOR);
  92. Collections.reverse(PlayerFactions);
  93. for (int i = 0; i < 20; i ++) {
  94. if (i >= PlayerFactions.size()) {
  95. break;
  96. }
  97. PlayerFaction next = PlayerFactions.get(i);
  98. entries.put(2, i + 1, ChatColor.GRAY.toString() + (i + 1) + ". " + next.getDisplayName(player) + ChatColor.GRAY + " (" + next.getOnlinePlayers().size() + ")");
  99. }
  100. return entries;
  101. }
  102.  
  103.  
  104. public static String getCardinalDirection(Player player) {
  105. double rotation = (player.getLocation().getYaw() + 180F) % 360.0F;
  106. if (rotation < 0.0D) {
  107. rotation += 360.0D;
  108. }
  109. if ((0.0D <= rotation) && (rotation < 22.5D)) {
  110. return "N";
  111. }
  112. if ((22.5D <= rotation) && (rotation < 67.5D)) {
  113. return "NE";
  114. }
  115. if ((67.5D <= rotation) && (rotation < 112.5D)) {
  116. return "E";
  117. }
  118. if ((112.5D <= rotation) && (rotation < 157.5D)) {
  119. return "SE";
  120. }
  121. if ((157.5D <= rotation) && (rotation < 202.5D)) {
  122. return "S";
  123. }
  124. if ((202.5D <= rotation) && (rotation < 247.5D)) {
  125. return "SW";
  126. }
  127. if ((247.5D <= rotation) && (rotation < 292.5D)) {
  128. return "W";
  129. }
  130. if ((292.5D <= rotation) && (rotation < 337.5D)) {
  131. return "NW";
  132. }
  133. if ((337.5D <= rotation) && (rotation < 360.0D)) {
  134. return "N";
  135. }
  136. return "";
  137. }
  138.  
  139. @Override
  140. public String getHeader(Player player) {
  141. return "";
  142. }
  143.  
  144. @Override
  145. public String getFooter(Player player) {
  146. return "";
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement