TextComponentFactory.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. package com.gmail.nossr50.util;
  2. import com.gmail.nossr50.config.AdvancedConfig;
  3. import com.gmail.nossr50.config.Config;
  4. import com.gmail.nossr50.config.RankConfig;
  5. import com.gmail.nossr50.datatypes.interactions.NotificationType;
  6. import com.gmail.nossr50.datatypes.json.McMMOUrl;
  7. import com.gmail.nossr50.datatypes.json.McMMOWebLinks;
  8. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  9. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  10. import com.gmail.nossr50.datatypes.skills.SubSkillType;
  11. import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
  12. import com.gmail.nossr50.listeners.InteractionManager;
  13. import com.gmail.nossr50.locale.LocaleLoader;
  14. import com.gmail.nossr50.util.skills.RankUtils;
  15. import net.md_5.bungee.api.ChatColor;
  16. import net.md_5.bungee.api.ChatMessageType;
  17. import net.md_5.bungee.api.chat.*;
  18. import org.bukkit.entity.Player;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. /**
  22. * This class handles many of the JSON components that mcMMO makes and uses
  23. */
  24. public class TextComponentFactory {
  25. /**
  26. * Makes a text component using strings from a locale and supports passing an undefined number of variables to the LocaleLoader
  27. * @param localeKey target locale string address
  28. * @param notificationType type of notification
  29. * @param values vars to be passed to the locale loader
  30. * @return
  31. */
  32. public static TextComponent getNotificationMultipleValues(String localeKey, NotificationType notificationType, String... values)
  33. {
  34. String preColoredString = LocaleLoader.getString(localeKey, (Object[]) values);
  35. TextComponent msg = new TextComponent(preColoredString);
  36. return new TextComponent(msg);
  37. }
  38. public static TextComponent getNotificationTextComponentFromLocale(String localeKey, NotificationType notificationType)
  39. {
  40. return getNotificationTextComponent(LocaleLoader.getString(localeKey));
  41. }
  42. public static TextComponent getNotificationLevelUpTextComponent(McMMOPlayer player, PrimarySkillType skill, int currentLevel)
  43. {
  44. //player.sendMessage(LocaleLoader.getString(StringUtils.getCapitalized(primarySkill.toString()) + ".Skillup", levelsGained, getSkillLevel(primarySkill)));
  45. TextComponent textComponent = new TextComponent(LocaleLoader.getString("JSON."+StringUtils.getCapitalized(skill.toString()))
  46. +" "+LocaleLoader.getString("JSON.LevelUp"));
  47. textComponent.setColor(AdvancedConfig.getInstance().getJSONActionBarColor(NotificationType.LEVEL_UP_MESSAGE));
  48. TextComponent childComponent = new TextComponent(" "+currentLevel);
  49. //TODO: Config
  50. childComponent.setColor(ChatColor.GREEN);
  51. childComponent.setBold(true);
  52. textComponent.addExtra(childComponent);
  53. return textComponent;
  54. }
  55. private static TextComponent getNotificationTextComponent(String text)
  56. {
  57. //textComponent.setColor(getNotificationColor(notificationType));
  58. return new TextComponent(text);
  59. }
  60. public static void sendPlayerSubSkillWikiLink(Player player, String subskillformatted)
  61. {
  62. if(!Config.getInstance().getUrlLinksEnabled())
  63. return;
  64. Player.Spigot spigotPlayer = player.spigot();
  65. TextComponent wikiLinkComponent = new TextComponent(LocaleLoader.getString("Overhaul.mcMMO.MmoInfo.Wiki"));
  66. wikiLinkComponent.setUnderlined(true);
  67. String wikiUrl = "https://mcmmo.org/wiki/"+subskillformatted;
  68. wikiLinkComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, wikiUrl));
  69. ComponentBuilder componentBuilder = new ComponentBuilder(subskillformatted).append("\n").append(wikiUrl).color(ChatColor.GRAY).italic(true);
  70. wikiLinkComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, componentBuilder.create()));
  71. spigotPlayer.sendMessage(ChatMessageType.SYSTEM, wikiLinkComponent);
  72. }
  73. public static void sendPlayerUrlHeader(Player player) {
  74. if(!Config.getInstance().getUrlLinksEnabled())
  75. return;
  76. Player.Spigot spigotPlayer = player.spigot();
  77. TextComponent prefix = new TextComponent(LocaleLoader.getString("Overhaul.mcMMO.Url.Wrap.Prefix") + " ");
  78. /*prefix.setColor(ChatColor.DARK_AQUA);*/
  79. TextComponent suffix = new TextComponent(" "+LocaleLoader.getString("Overhaul.mcMMO.Url.Wrap.Suffix"));
  80. /*suffix.setColor(ChatColor.DARK_AQUA);*/
  81. TextComponent emptySpace = new TextComponent(" ");
  82. BaseComponent[] baseComponents = {new TextComponent(prefix),
  83. getWebLinkTextComponent(McMMOWebLinks.WEBSITE),
  84. emptySpace,
  85. getWebLinkTextComponent(McMMOWebLinks.DISCORD),
  86. emptySpace,
  87. getWebLinkTextComponent(McMMOWebLinks.PATREON),
  88. emptySpace,
  89. getWebLinkTextComponent(McMMOWebLinks.WIKI),
  90. emptySpace,
  91. getWebLinkTextComponent(McMMOWebLinks.SPIGOT),
  92. emptySpace,
  93. getWebLinkTextComponent(McMMOWebLinks.HELP_TRANSLATE),
  94. new TextComponent(suffix)};
  95. spigotPlayer.sendMessage(baseComponents);
  96. }
  97. public static void sendPlayerSubSkillList(Player player, List<TextComponent> textComponents)
  98. {
  99. TextComponent emptySpace = new TextComponent(" ");
  100. ArrayList<BaseComponent> bulkMessage = new ArrayList<>();
  101. int newLineCount = 0; //Hacky solution to wordwrap problems
  102. for (TextComponent textComponent : textComponents) {
  103. //Don't send more than 3 subskills per line to avoid MOST wordwrap problems
  104. if(newLineCount > 2)
  105. {
  106. TextComponent[] bulkArray = new TextComponent[bulkMessage.size()];
  107. bulkArray = bulkMessage.toArray(bulkArray);
  108. player.spigot().sendMessage(bulkArray);
  109. bulkMessage = new ArrayList<>();
  110. newLineCount = 0;
  111. }
  112. //Style the skills into @links
  113. final String originalTxt = textComponent.getText();
  114. TextComponent stylizedText = new TextComponent("@");
  115. stylizedText.setColor(ChatColor.YELLOW);
  116. addChild(stylizedText, originalTxt);
  117. if(textComponent.getHoverEvent() != null)
  118. stylizedText.setHoverEvent(textComponent.getHoverEvent());
  119. if(textComponent.getClickEvent() != null)
  120. stylizedText.setClickEvent(textComponent.getClickEvent());
  121. bulkMessage.add(stylizedText);
  122. bulkMessage.add(emptySpace);
  123. newLineCount++;
  124. }
  125. /*
  126. * Convert our list into an array
  127. */
  128. TextComponent[] bulkArray = new TextComponent[bulkMessage.size()];
  129. bulkArray = bulkMessage.toArray(bulkArray);
  130. player.spigot().sendMessage(bulkArray);
  131. }
  132. private static TextComponent getWebLinkTextComponent(McMMOWebLinks webLinks)
  133. {
  134. TextComponent webTextComponent;
  135. switch(webLinks)
  136. {
  137. case WEBSITE:
  138. webTextComponent = new TextComponent("@");
  139. webTextComponent.setColor(ChatColor.YELLOW);
  140. addChild(webTextComponent, "Web");
  141. webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlWebsite));
  142. break;
  143. case SPIGOT:
  144. webTextComponent = new TextComponent("@");
  145. webTextComponent.setColor(ChatColor.YELLOW);
  146. addChild(webTextComponent, "Spigot");
  147. webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlSpigot));
  148. break;
  149. case DISCORD:
  150. webTextComponent = new TextComponent("@");
  151. webTextComponent.setColor(ChatColor.YELLOW);
  152. addChild(webTextComponent, "Discord");
  153. webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlDiscord));
  154. break;
  155. case PATREON:
  156. webTextComponent = new TextComponent("@");
  157. webTextComponent.setColor(ChatColor.YELLOW);
  158. addChild(webTextComponent, "Patreon");
  159. webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlPatreon));
  160. break;
  161. case WIKI:
  162. webTextComponent = new TextComponent("@");
  163. webTextComponent.setColor(ChatColor.YELLOW);
  164. addChild(webTextComponent, "Wiki");
  165. webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlWiki));
  166. break;
  167. case HELP_TRANSLATE:
  168. webTextComponent = new TextComponent("@");
  169. webTextComponent.setColor(ChatColor.YELLOW);
  170. addChild(webTextComponent, "Lang");
  171. webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlTranslate));
  172. break;
  173. default:
  174. webTextComponent = new TextComponent("NOT DEFINED");
  175. }
  176. addNewHoverComponentToTextComponent(webTextComponent, getUrlHoverEvent(webLinks));
  177. webTextComponent.setInsertion(webLinks.getUrl());
  178. return webTextComponent;
  179. }
  180. private static void addChild(TextComponent webTextComponent, String childName) {
  181. TextComponent childComponent = new TextComponent(childName);
  182. childComponent.setColor(ChatColor.BLUE);
  183. webTextComponent.addExtra(childComponent);
  184. }
  185. private static BaseComponent[] getUrlHoverEvent(McMMOWebLinks webLinks)
  186. {
  187. ComponentBuilder componentBuilder = new ComponentBuilder(webLinks.getNiceTitle());
  188. switch(webLinks)
  189. {
  190. case WEBSITE:
  191. addUrlHeaderHover(webLinks, componentBuilder);
  192. componentBuilder.append("\n\n").italic(false);
  193. componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN);
  194. componentBuilder.append("\nDev Blogs, and information related to mcMMO can be found here").color(ChatColor.GRAY);
  195. break;
  196. case SPIGOT:
  197. addUrlHeaderHover(webLinks, componentBuilder);
  198. componentBuilder.append("\n\n").italic(false);
  199. componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN);
  200. componentBuilder.append("\nI post regularly in the discussion thread here!").color(ChatColor.GRAY);
  201. break;
  202. case PATREON:
  203. addUrlHeaderHover(webLinks, componentBuilder);
  204. componentBuilder.append("\n\n").italic(false);
  205. componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN);
  206. componentBuilder.append("\n");
  207. componentBuilder.append("Show support by buying me a coffee :)").italic(false).color(ChatColor.GRAY);
  208. break;
  209. case WIKI:
  210. addUrlHeaderHover(webLinks, componentBuilder);
  211. componentBuilder.append("\n\n").italic(false);
  212. componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN);
  213. componentBuilder.append("\n");
  214. componentBuilder.append("I'm looking for more wiki staff, contact me on our discord!").italic(false).color(ChatColor.DARK_GRAY);
  215. break;
  216. case DISCORD:
  217. addUrlHeaderHover(webLinks, componentBuilder);
  218. componentBuilder.append("\n\n").italic(false);
  219. componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN);
  220. break;
  221. case HELP_TRANSLATE:
  222. addUrlHeaderHover(webLinks, componentBuilder);
  223. componentBuilder.append("\n\n").italic(false);
  224. componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN);
  225. componentBuilder.append("\n");
  226. componentBuilder.append("You can use this website to help translate mcMMO into your language!" +
  227. "\nIf you want to know more contact me in discord.").italic(false).color(ChatColor.DARK_GRAY);
  228. }
  229. return componentBuilder.create();
  230. }
  231. private static void addUrlHeaderHover(McMMOWebLinks webLinks, ComponentBuilder componentBuilder) {
  232. componentBuilder.append("\n");
  233. componentBuilder.append(webLinks.getUrl()).color(ChatColor.GRAY).italic(true);
  234. }
  235. private static ClickEvent getUrlClickEvent(String url)
  236. {
  237. return new ClickEvent(ClickEvent.Action.OPEN_URL, url);
  238. }
  239. private static TextComponent getSubSkillTextComponent(Player player, SubSkillType subSkillType)
  240. {
  241. //Get skill name
  242. String skillName = subSkillType.getLocaleName();
  243. TextComponent textComponent;
  244. //Setup Text Component
  245. if(RankUtils.hasUnlockedSubskill(player, subSkillType))
  246. {
  247. textComponent = new TextComponent(skillName);
  248. textComponent.setColor(ChatColor.DARK_AQUA);
  249. textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mmoinfo "+subSkillType.getNiceNameNoSpaces(subSkillType)));
  250. }
  251. else {
  252. textComponent = new TextComponent("???");
  253. textComponent.setColor(ChatColor.DARK_GRAY);
  254. textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mmoinfo ???"));
  255. }
  256. //Hover Event
  257. addNewHoverComponentToTextComponent(textComponent, getSubSkillHoverComponent(player, subSkillType));
  258. //Insertion
  259. textComponent.setInsertion(skillName);
  260. return textComponent;
  261. }
  262. private static void addNewHoverComponentToTextComponent(TextComponent textComponent, BaseComponent[] baseComponent) {
  263. textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, baseComponent));
  264. }
  265. private static TextComponent getSubSkillTextComponent(Player player, AbstractSubSkill abstractSubSkill)
  266. {
  267. //String key = abstractSubSkill.getConfigKeyName();
  268. String skillName = abstractSubSkill.getNiceName();
  269. //Setup Text Component
  270. TextComponent textComponent;
  271. //Setup Text Component
  272. if(RankUtils.hasUnlockedSubskill(player, abstractSubSkill))
  273. {
  274. textComponent = new TextComponent(skillName);
  275. textComponent.setColor(ChatColor.DARK_AQUA);
  276. textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mmoinfo "+abstractSubSkill.getConfigKeyName()));
  277. }
  278. else {
  279. textComponent = new TextComponent("???");
  280. textComponent.setColor(ChatColor.DARK_GRAY);
  281. textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mmoinfo ???"));
  282. }
  283. //Hover Event
  284. addNewHoverComponentToTextComponent(textComponent, getSubSkillHoverComponent(player, abstractSubSkill));
  285. //Insertion
  286. textComponent.setInsertion(skillName);
  287. return textComponent;
  288. }
  289. private static BaseComponent[] getSubSkillHoverComponent(Player player, AbstractSubSkill abstractSubSkill)
  290. {
  291. return getSubSkillHoverEventJSON(abstractSubSkill, player);
  292. }
  293. private static BaseComponent[] getSubSkillHoverComponent(Player player, SubSkillType subSkillType)
  294. {
  295. return getSubSkillHoverEventJSON(subSkillType, player);
  296. }
  297. /**
  298. * Used for the skill in the new skill system (Deriving from AbstractSubSkill)
  299. * @param abstractSubSkill this subskill
  300. * @param player the player who owns this subskill
  301. * @return the hover basecomponent object for this subskill
  302. */
  303. private static BaseComponent[] getSubSkillHoverEventJSON(AbstractSubSkill abstractSubSkill, Player player)
  304. {
  305. String skillName = abstractSubSkill.getNiceName();
  306. /*
  307. * Hover Event BaseComponent color table
  308. */
  309. ChatColor ccSubSkillHeader = ChatColor.GOLD;
  310. ChatColor ccRank = ChatColor.BLUE;
  311. ChatColor ccCurRank = ChatColor.GREEN;
  312. ChatColor ccPossessive = ChatColor.WHITE;
  313. ChatColor ccNumRanks = ccCurRank;
  314. //ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE;
  315. //ChatColor ccDescription = ChatColor.WHITE;
  316. ChatColor ccLocked = ChatColor.DARK_GRAY;
  317. ChatColor ccLevelRequirement = ChatColor.BLUE;
  318. ChatColor ccLevelRequired = ChatColor.RED;
  319. ComponentBuilder componentBuilder;
  320. //SubSkillType Name
  321. if(RankUtils.hasUnlockedSubskill(player, abstractSubSkill))
  322. componentBuilder = getNewComponentBuilder(skillName, ccSubSkillHeader);
  323. else
  324. componentBuilder = getNewComponentBuilder("???", ccSubSkillHeader);
  325. if(!RankUtils.hasUnlockedSubskill(player, abstractSubSkill))
  326. {
  327. //Skill is not unlocked yet
  328. addLocked(abstractSubSkill, ccLocked, ccLevelRequirement, ccLevelRequired, componentBuilder);
  329. } else {
  330. addSubSkillTypeToHoverEventJSON(abstractSubSkill, componentBuilder);
  331. //RANK
  332. addRanked(ccRank, ccCurRank, ccPossessive, ccNumRanks, componentBuilder, abstractSubSkill.getNumRanks(), RankUtils.getRank(player, abstractSubSkill));
  333. componentBuilder.append(LocaleLoader.getString("JSON.DescriptionHeader"));
  334. componentBuilder.append("\n").append(abstractSubSkill.getDescription()).append("\n");
  335. //Empty line
  336. componentBuilder.append("\n").bold(false);
  337. componentBuilder.append("\n");
  338. //Finally, add details to the tooltip
  339. abstractSubSkill.addStats(componentBuilder, player);
  340. }
  341. return componentBuilder.create();
  342. }
  343. private static ComponentBuilder getNewComponentBuilder(String skillName, ChatColor ccSubSkillHeader) {
  344. ComponentBuilder componentBuilder = new ComponentBuilder(skillName);
  345. componentBuilder.bold(true).color(ccSubSkillHeader);
  346. componentBuilder.append("\n");
  347. return componentBuilder;
  348. }
  349. private static void addRanked(ChatColor ccRank, ChatColor ccCurRank, ChatColor ccPossessive, ChatColor ccNumRanks, ComponentBuilder componentBuilder, int numRanks, int rank) {
  350. if (numRanks > 0) {
  351. //Rank
  352. componentBuilder.append(LocaleLoader.getString("JSON.Rank") + ": ").bold(false).color(ccRank);
  353. //x of y
  354. componentBuilder.append(String.valueOf(rank)).color(ccCurRank);
  355. componentBuilder.append(" " + LocaleLoader.getString("JSON.RankPossesive") + " ").color(ccPossessive);
  356. componentBuilder.append(String.valueOf(numRanks)).color(ccNumRanks);
  357. }
  358. }
  359. private static void addLocked(SubSkillType subSkillType, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) {
  360. addLocked(ccLocked, ccLevelRequirement, componentBuilder);
  361. componentBuilder.append(String.valueOf(RankConfig.getInstance().getSubSkillUnlockLevel(subSkillType, 1))).color(ccLevelRequired);
  362. //componentBuilder.append("\n");
  363. }
  364. private static void addLocked(AbstractSubSkill abstractSubSkill, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) {
  365. addLocked(ccLocked, ccLevelRequirement, componentBuilder);
  366. componentBuilder.append(String.valueOf(RankConfig.getInstance().getSubSkillUnlockLevel(abstractSubSkill, 1))).color(ccLevelRequired);
  367. //componentBuilder.append("\n");
  368. }
  369. private static void addLocked(ChatColor ccLocked, ChatColor ccLevelRequirement, ComponentBuilder componentBuilder) {
  370. componentBuilder.append(LocaleLoader.getString("JSON.Locked")).color(ccLocked).bold(true);
  371. componentBuilder.append("\n").append("\n").bold(false);
  372. componentBuilder.append(LocaleLoader.getString("JSON.LevelRequirement") + ": ").color(ccLevelRequirement);
  373. }
  374. @Deprecated
  375. private static BaseComponent[] getSubSkillHoverEventJSON(SubSkillType subSkillType, Player player)
  376. {
  377. String skillName = subSkillType.getLocaleName();
  378. /*
  379. * Hover Event BaseComponent color table
  380. */
  381. ChatColor ccSubSkillHeader = ChatColor.GOLD;
  382. ChatColor ccRank = ChatColor.BLUE;
  383. ChatColor ccCurRank = ChatColor.GREEN;
  384. ChatColor ccPossessive = ChatColor.WHITE;
  385. ChatColor ccNumRanks = ccCurRank;
  386. ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE;
  387. ChatColor ccDescription = ChatColor.DARK_GRAY;
  388. ChatColor ccLocked = ChatColor.DARK_GRAY;
  389. ChatColor ccLevelRequirement = ChatColor.BLUE;
  390. ChatColor ccLevelRequired = ChatColor.RED;
  391. ComponentBuilder componentBuilder;
  392. //SubSkillType Name
  393. if(RankUtils.hasUnlockedSubskill(player, subSkillType))
  394. componentBuilder = getNewComponentBuilder(skillName, ccSubSkillHeader);
  395. else
  396. componentBuilder = getNewComponentBuilder("???", ccSubSkillHeader);
  397. if(!RankUtils.hasUnlockedSubskill(player, subSkillType))
  398. {
  399. //Skill is not unlocked yet
  400. addLocked(subSkillType, ccLocked, ccLevelRequirement, ccLevelRequired, componentBuilder);
  401. } else {
  402. //addSubSkillTypeToHoverEventJSON(subSkillType, componentBuilder);
  403. //RANK
  404. if(subSkillType.getNumRanks() > 0)
  405. {
  406. addRanked(ccRank, ccCurRank, ccPossessive, ccNumRanks, componentBuilder, subSkillType.getNumRanks(), RankUtils.getRank(player, subSkillType));
  407. //Empty line
  408. componentBuilder.append("\n").bold(false);
  409. }
  410. componentBuilder.append(LocaleLoader.getString("JSON.DescriptionHeader"));
  411. componentBuilder.color(ccDescriptionHeader);
  412. componentBuilder.append("\n");
  413. componentBuilder.append(subSkillType.getLocaleDescription());
  414. componentBuilder.color(ccDescription);
  415. }
  416. return componentBuilder.create();
  417. }
  418. private static void addSubSkillTypeToHoverEventJSON(AbstractSubSkill abstractSubSkill, ComponentBuilder componentBuilder)
  419. {
  420. if(abstractSubSkill.isSuperAbility())
  421. {
  422. componentBuilder.append(LocaleLoader.getString("JSON.Type.SuperAbility")).color(ChatColor.LIGHT_PURPLE);
  423. componentBuilder.bold(true);
  424. } else if(abstractSubSkill.isActiveUse())
  425. {
  426. componentBuilder.append(LocaleLoader.getString("JSON.Type.Active")).color(ChatColor.DARK_RED);
  427. componentBuilder.bold(true);
  428. } else {
  429. componentBuilder.append(LocaleLoader.getString("JSON.Type.Passive")).color(ChatColor.GREEN);
  430. componentBuilder.bold(true);
  431. }
  432. componentBuilder.append("\n");
  433. }
  434. public static void getSubSkillTextComponents(Player player, List<TextComponent> textComponents, PrimarySkillType parentSkill) {
  435. for(SubSkillType subSkillType : SubSkillType.values())
  436. {
  437. if(subSkillType.getParentSkill() == parentSkill)
  438. {
  439. if(Permissions.isSubSkillEnabled(player, subSkillType))
  440. {
  441. if(!InteractionManager.hasSubSkill(subSkillType))
  442. textComponents.add(TextComponentFactory.getSubSkillTextComponent(player, subSkillType));
  443. }
  444. }
  445. }
  446. /* NEW SKILL SYSTEM */
  447. for(AbstractSubSkill abstractSubSkill : InteractionManager.getSubSkillList())
  448. {
  449. if(abstractSubSkill.getPrimarySkill() == parentSkill)
  450. {
  451. if(Permissions.isSubSkillEnabled(player, abstractSubSkill))
  452. textComponents.add(TextComponentFactory.getSubSkillTextComponent(player, abstractSubSkill));
  453. }
  454. }
  455. }
  456. public static TextComponent getSubSkillUnlockedNotificationComponents(Player player, SubSkillType subSkillType)
  457. {
  458. TextComponent unlockMessage = new TextComponent("");
  459. unlockMessage.setText(LocaleLoader.getString("JSON.SkillUnlockMessage", subSkillType.getLocaleName(), RankUtils.getRank(player, subSkillType)));
  460. unlockMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, getSubSkillHoverComponent(player, subSkillType)));
  461. unlockMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/"+subSkillType.getParentSkill().toString().toLowerCase()));
  462. return unlockMessage;
  463. }
  464. }