Advertisement
Ytnoos

Untitled

Dec 17th, 2021
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. import it.ytnoos.bedwarsforged.common.BedwarsCommon;
  2. import it.ytnoos.bedwarsforged.common.manager.DisguiseManager;
  3. import it.ytnoos.bedwarsforged.common.utils.Symbol;
  4. import it.ytnoos.dictation.api.bukkit.adapter.adapters.NameTagAdapter;
  5. import net.luckperms.api.LuckPermsProvider;
  6. import net.luckperms.api.model.user.User;
  7. import org.apache.commons.lang.StringUtils;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.potion.PotionEffectType;
  11. import org.bukkit.scoreboard.NameTagVisibility;
  12. import org.bukkit.scoreboard.Team;
  13.  
  14. import java.util.UUID;
  15. import java.util.concurrent.CompletableFuture;
  16.  
  17. public class BedwarsNameTagAdapter extends NameTagAdapter {
  18.  
  19. public final BedwarsCommon common;
  20.  
  21. public BedwarsNameTagAdapter(BedwarsCommon common) {
  22. super(common.getDictation().getNameTagModule());
  23. this.common = common;
  24. }
  25.  
  26. public static String getColorPrefix(String name) {
  27. User user = LuckPermsProvider.get().getUserManager().getUser(name);
  28. if (user == null) {
  29. UUID uuid = LuckPermsProvider.get().getUserManager().lookupUniqueId(name).join();
  30. if (uuid != null) {
  31. user = LuckPermsProvider.get().getUserManager().loadUser(uuid, name).join();
  32. } else return "";
  33. }
  34.  
  35. String prefix = user.getCachedData().getMetaData().getPrefix();
  36. if (prefix == null) return "";
  37.  
  38. prefix = ChatColor.translateAlternateColorCodes('&', prefix);
  39. return prefix.isEmpty() ? ChatColor.GRAY.toString() : (prefix.length() >= 3 ? prefix.substring(prefix.length() - 3, prefix.length() - 1) : ChatColor.GRAY.toString());
  40. }
  41.  
  42. public String getColorPrefix(Player player) {
  43. if (common.getDisguiseManager().isDisguised(player)) return ChatColor.GRAY + "";
  44.  
  45. User user = LuckPermsProvider.get().getUserManager().getUser(player.getName());
  46. if (user == null) return "";
  47.  
  48. String prefix = user.getCachedData().getMetaData().getPrefix();
  49. if (prefix == null) return "";
  50.  
  51. prefix = ChatColor.translateAlternateColorCodes('&', prefix);
  52. return prefix.isEmpty() ? ChatColor.GRAY.toString() : (prefix.length() >= 3 ? prefix.substring(prefix.length() - 3, prefix.length() - 1) : ChatColor.GRAY.toString());
  53. }
  54.  
  55. @Override
  56. public CompletableFuture<String> getSuffix(Player player) {
  57. if (common.getDisguiseManager().isDisguised(player)) return CompletableFuture.completedFuture("");
  58.  
  59. return common.getClanName(player).thenApply(clan -> {
  60. if (clan.isEmpty()) return clan;
  61.  
  62. clan = " [" + clan + "]";
  63. if (StringUtils.equalsIgnoreCase(clan, " [bellofigo]")) {
  64. return ChatColor.GOLD + clan;
  65. } else return ChatColor.GRAY + clan;
  66. });
  67. }
  68.  
  69. @Override
  70. public CompletableFuture<String> getDisplayName(Player player) {
  71. int level = common.getStatsCached(player.getName()).getLevel();
  72.  
  73. if (common.getDisguiseManager().isDisguised(player))
  74. level = DisguiseManager.DISGUISED.get(player.getSafeFakeName()).getLevel();
  75. String levelPrefix = getColor(level) + "[" + level + Symbol.STAR + "] ";
  76. return getChatPrefix(player).thenApply(prefix -> levelPrefix + prefix + player.getSafeFakeName());
  77. }
  78.  
  79. public void hideNameTag(Player player) {
  80. Team team = player.getScoreboard().getTeam(module.getTeamName(player));
  81. if (team != null) team.setNameTagVisibility(NameTagVisibility.NEVER);
  82. }
  83.  
  84. @Override
  85. public void onCreateTeam(Player player, Team team) {
  86. if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) hideNameTag(player);
  87. }
  88.  
  89. @Override
  90. public int getPriority(Player player) {
  91. return common.getDisguiseManager().isDisguised(player) ? 1000 : super.getPriority(player);
  92. }
  93.  
  94. private ChatColor getColor(int level) {
  95. if (level < 100) {
  96. return ChatColor.GRAY;
  97. } else if (level < 200) {
  98. return ChatColor.WHITE;
  99. } else if (level < 300) {
  100. return ChatColor.GOLD;
  101. } else if (level < 400) {
  102. return ChatColor.AQUA;
  103. } else if (level < 500) {
  104. return ChatColor.DARK_GREEN;
  105. } else if (level < 600) {
  106. return ChatColor.BLUE;
  107. } else if (level < 700) {
  108. return ChatColor.RED;
  109. } else if (level < 800) {
  110. return ChatColor.LIGHT_PURPLE;
  111. } else {
  112. return ChatColor.GRAY;
  113. }
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement