use of net.md_5.bungee.api.chat.ClickEvent in project Denizen-For-Bukkit by DenizenScript.
the class FormattedTextHelper method parse.
public static BaseComponent[] parse(String str, ChatColor baseColor, boolean cleanBase) {
if (str == null) {
return null;
}
str = CoreUtilities.clearNBSPs(str);
int firstChar = str.indexOf(ChatColor.COLOR_CHAR);
if (firstChar == -1) {
if (str.contains("://")) {
firstChar = 0;
} else {
TextComponent base = new TextComponent();
// This is for compat with how Spigot does parsing of plaintext.
base.addExtra(new TextComponent(str));
return new BaseComponent[] { base };
}
}
str = cleanRedundantCodes(str);
if (cleanBase && str.length() < 512 && !str.contains(ChatColor.COLOR_CHAR + "[") && !str.contains("://")) {
return parseSimpleColorsOnly(str);
}
TextComponent root = new TextComponent();
TextComponent base = new TextComponent();
if (cleanBase) {
base.setBold(false);
base.setItalic(false);
base.setStrikethrough(false);
base.setUnderlined(false);
base.setObfuscated(false);
base.setColor(baseColor);
if (firstChar > 0) {
root.addExtra(new TextComponent(str.substring(0, firstChar)));
}
} else {
base.setText(str.substring(0, firstChar));
}
root.addExtra(base);
str = str.substring(firstChar);
char[] chars = str.toCharArray();
int started = 0;
TextComponent nextText = new TextComponent();
TextComponent lastText;
for (int i = 0; i < chars.length; i++) {
if (chars[i] == ChatColor.COLOR_CHAR && i + 1 < chars.length) {
char code = chars[i + 1];
if (!allowedCharCodes.isMatch(code)) {
continue;
}
if (code == '[') {
int endBracket = str.indexOf(']', i + 2);
if (endBracket == -1) {
continue;
}
String innards = str.substring(i + 2, endBracket);
List<String> innardParts = CoreUtilities.split(innards, ';');
List<String> innardBase = CoreUtilities.split(innardParts.get(0), '=', 2);
innardParts.remove(0);
String innardType = CoreUtilities.toLowerCase(innardBase.get(0));
if (innardBase.size() == 2) {
nextText.setText(nextText.getText() + str.substring(started, i));
base.addExtra(nextText);
lastText = nextText;
nextText = copyFormatToNewText(lastText);
nextText.setText("");
if (innardType.equals("score") && innardParts.size() == 2) {
ScoreComponent component = new ScoreComponent(unescape(innardBase.get(1)), unescape(innardParts.get(0)), unescape(innardParts.get(1)));
lastText.addExtra(component);
} else if (innardType.equals("keybind")) {
KeybindComponent component = new KeybindComponent();
component.setKeybind(unescape(innardBase.get(1)));
lastText.addExtra(component);
} else if (innardType.equals("selector")) {
SelectorComponent component = new SelectorComponent(unescape(innardBase.get(1)));
lastText.addExtra(component);
} else if (innardType.equals("translate")) {
TranslatableComponent component = new TranslatableComponent();
component.setTranslate(unescape(innardBase.get(1)));
for (String extra : innardParts) {
for (BaseComponent subComponent : parse(unescape(extra), baseColor, false)) {
component.addWith(subComponent);
}
}
lastText.addExtra(component);
} else if (innardType.equals("click") && innardParts.size() == 1) {
int endIndex = findEndIndexFor(str, "click", i + 5);
if (endIndex == -1) {
continue;
}
TextComponent clickableText = new TextComponent();
clickableText.setClickEvent(new ClickEvent(ClickEvent.Action.valueOf(innardBase.get(1).toUpperCase()), unescape(innardParts.get(0))));
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex), baseColor, false)) {
clickableText.addExtra(subComponent);
}
lastText.addExtra(clickableText);
endBracket = endIndex + "&[/click".length();
} else if (innardType.equals("hover")) {
int endIndex = findEndIndexFor(str, "hover", i + 5);
if (endIndex == -1) {
continue;
}
TextComponent hoverableText = new TextComponent();
HoverEvent.Action action = HoverEvent.Action.valueOf(innardBase.get(1).toUpperCase());
if (HoverFormatHelper.processHoverInput(action, hoverableText, innardParts.get(0))) {
continue;
}
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex), baseColor, false)) {
hoverableText.addExtra(subComponent);
}
lastText.addExtra(hoverableText);
endBracket = endIndex + "&[/hover".length();
} else if (innardType.equals("insertion")) {
int endIndex = str.indexOf(ChatColor.COLOR_CHAR + "[/insertion]", i);
int backupEndIndex = str.indexOf(ChatColor.COLOR_CHAR + "[insertion=", i + 5);
if (backupEndIndex > 0 && backupEndIndex < endIndex) {
endIndex = backupEndIndex;
}
if (endIndex == -1) {
continue;
}
TextComponent insertableText = new TextComponent();
insertableText.setInsertion(unescape(innardBase.get(1)));
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex), baseColor, false)) {
insertableText.addExtra(subComponent);
}
lastText.addExtra(insertableText);
endBracket = endIndex + "&[/insertion".length();
} else if (innardType.equals("reset")) {
if (innardBase.get(1).length() == 1) {
char subCode = innardBase.get(1).charAt(0);
if (subCode == 'k' || subCode == 'K') {
nextText.setObfuscated(false);
} else if (subCode == 'l' || subCode == 'L') {
nextText.setBold(false);
} else if (subCode == 'm' || subCode == 'M') {
nextText.setStrikethrough(false);
} else if (subCode == 'n' || subCode == 'N') {
nextText.setUnderlined(false);
} else if (subCode == 'o' || subCode == 'O') {
nextText.setItalic(false);
}
} else if (innardBase.get(1).equals("font")) {
nextText.setFont(base.getFont());
} else {
nextText.setColor(base.getColor());
}
} else if (innardType.equals("color")) {
String colorChar = innardBase.get(1);
ChatColor color = null;
if (colorChar.length() == 1) {
color = ChatColor.getByChar(colorChar.charAt(0));
} else if (colorChar.length() == 7) {
color = ChatColor.of(colorChar);
} else if (Debug.verbose) {
Debug.echoError("Text parse issue: cannot interpret color '" + innardBase.get(1) + "'.");
}
if (color != null) {
int endIndex = findEndIndexFor(str, "[color=", "[reset=color]", i + 1);
if (endIndex == -1) {
nextText.setColor(color);
} else {
TextComponent colorText = new TextComponent();
colorText.setColor(color);
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex), color, false)) {
colorText.addExtra(subComponent);
}
lastText.addExtra(colorText);
endBracket = endIndex + "&[reset=color".length();
}
}
} else if (innardType.equals("font")) {
int endIndex = findEndIndexFor(str, "[font=", "[reset=font]", i + 1);
if (endIndex == -1) {
nextText.setFont(innardBase.get(1));
} else {
TextComponent fontText = new TextComponent();
fontText.setFont(innardBase.get(1));
for (BaseComponent subComponent : parse(str.substring(endBracket + 1, endIndex), baseColor, false)) {
fontText.addExtra(subComponent);
}
lastText.addExtra(fontText);
endBracket = endIndex + "&[reset=font".length();
}
} else {
if (Debug.verbose) {
Debug.echoError("Text parse issue: cannot interpret type '" + innardType + "' with " + innardParts.size() + " parts.");
}
}
}
i = endBracket;
started = endBracket + 1;
continue;
} else if (code == 'r' || code == 'R') {
nextText.setText(nextText.getText() + str.substring(started, i));
if (!nextText.getText().isEmpty()) {
base.addExtra(nextText);
}
nextText = new TextComponent();
nextText.setColor(baseColor);
} else if (colorCodesOrReset.isMatch(code)) {
nextText.setText(nextText.getText() + str.substring(started, i));
if (!nextText.getText().isEmpty()) {
base.addExtra(nextText);
}
nextText = new TextComponent();
nextText.setColor(ChatColor.getByChar(code));
} else if (code == 'x') {
if (i + 13 >= chars.length) {
continue;
}
StringBuilder color = new StringBuilder(12);
color.append("#");
for (int c = 1; c <= 6; c++) {
if (chars[i + c * 2] != ChatColor.COLOR_CHAR) {
color = null;
break;
}
char hexPart = chars[i + 1 + c * 2];
if (!hexMatcher.isMatch(hexPart)) {
color = null;
break;
}
color.append(hexPart);
}
if (color == null) {
continue;
}
nextText.setText(nextText.getText() + str.substring(started, i));
if (!nextText.getText().isEmpty()) {
base.addExtra(nextText);
}
nextText = new TextComponent();
nextText.setColor(ChatColor.of(color.toString()));
i += 13;
started = i + 1;
continue;
} else {
nextText.setText(nextText.getText() + str.substring(started, i));
if (!nextText.getText().isEmpty()) {
base.addExtra(nextText);
}
nextText = copyFormatToNewText(nextText);
if (code == 'k' || code == 'K') {
nextText.setObfuscated(true);
} else if (code == 'l' || code == 'L') {
nextText.setBold(true);
} else if (code == 'm' || code == 'M') {
nextText.setStrikethrough(true);
} else if (code == 'n' || code == 'N') {
nextText.setUnderlined(true);
} else if (code == 'o' || code == 'O') {
nextText.setItalic(true);
}
}
i++;
started = i + 1;
} else if (i + "https://a.".length() < chars.length && chars[i] == 'h' && chars[i + 1] == 't' && chars[i + 2] == 't' && chars[i + 3] == 'p') {
String subStr = str.substring(i, i + "https://a.".length());
if (subStr.startsWith("https://") || subStr.startsWith("http://")) {
int nextSpace = CoreUtilities.indexOfAny(str, i, ' ', '\t', '\n');
if (nextSpace == -1) {
nextSpace = str.length();
}
String url = str.substring(i, nextSpace);
nextText.setText(nextText.getText() + str.substring(started, i));
base.addExtra(nextText);
lastText = nextText;
nextText = new TextComponent(lastText);
nextText.setText("");
TextComponent clickableText = new TextComponent(url);
clickableText.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
lastText.addExtra(clickableText);
i = nextSpace;
started = nextSpace;
continue;
}
}
}
nextText.setText(nextText.getText() + str.substring(started));
if (!nextText.getText().isEmpty()) {
base.addExtra(nextText);
}
return new BaseComponent[] { cleanBase ? root : base };
}
use of net.md_5.bungee.api.chat.ClickEvent in project EliteMobs by MagmaGuy.
the class Minidungeon method installSchematicMinidungeon.
private void installSchematicMinidungeon(Player player) {
player.performCommand("schematic load " + dungeonPackagerConfigFields.getSchematicName());
new BukkitRunnable() {
@Override
public void run() {
for (int i = 0; i < 20; i++) player.sendMessage("");
player.sendMessage(ChatColorConverter.convert("&2-------------------------------------------------"));
player.sendMessage(ChatColorConverter.convert("&7[EliteMobs] &2Ready to install " + dungeonPackagerConfigFields.getDungeonSizeCategory().toString().toLowerCase() + "!"));
TextComponent pasteString = new TextComponent(ChatColorConverter.convert("&aClick here to place the &lbuilding and bosses &awhere you're standing!"));
pasteString.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/em setup minidungeon " + dungeonPackagerConfigFields.getFilename()));
pasteString.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(ChatColorConverter.convert("&2Click me!"))));
TextComponent noPasteString = new TextComponent(ChatColorConverter.convert("&4&lOr &4click here to &lonly set the bosses with no building&4!"));
noPasteString.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/em setup minidungeonNoPaste " + dungeonPackagerConfigFields.getFilename()));
noPasteString.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(ChatColorConverter.convert("&cOnly click if you're already standing at the bulding's anchor point!"))));
player.spigot().sendMessage(pasteString);
player.spigot().sendMessage(noPasteString);
player.sendMessage(ChatColorConverter.convert("&2-------------------------------------------------"));
}
}.runTaskLater(MetadataHandler.PLUGIN, 20);
initializeWormholeWorld();
}
use of net.md_5.bungee.api.chat.ClickEvent in project EliteMobs by MagmaGuy.
the class Minidungeon method finalizeMinidungeonInstallation.
public void finalizeMinidungeonInstallation(Player player, boolean pastedSchematic) {
dungeonPackagerConfigFields.setEnabled(true, player.getLocation());
this.relativeBossLocations = new RelativeDungeonLocations(dungeonPackagerConfigFields.getRelativeBossLocations(), true);
this.relativeTreasureChestLocations = new RelativeDungeonLocations(dungeonPackagerConfigFields.getRelativeTreasureChestLocations(), false);
this.realDungeonLocations = new RealDungeonLocations();
commitLocations();
this.isInstalled = true;
if (dungeonPackagerConfigFields.isProtect()) {
Location realCorner1 = getRotatedFinalLocation(dungeonPackagerConfigFields.getAnchorPoint(), dungeonPackagerConfigFields.getCorner1());
Location realCorner2 = getRotatedFinalLocation(dungeonPackagerConfigFields.getAnchorPoint(), dungeonPackagerConfigFields.getCorner2());
WorldGuardCompatibility.defineMinidungeon(realCorner1, realCorner2, dungeonPackagerConfigFields.getAnchorPoint(), dungeonPackagerConfigFields.getSchematicName(), this);
}
teleportLocation = getRotatedFinalLocation(dungeonPackagerConfigFields.getAnchorPoint(), dungeonPackagerConfigFields.getTeleportPoint());
for (int i = 0; i < 20; i++) player.sendMessage("");
player.sendMessage(ChatColorConverter.convert("&2" + dungeonPackagerConfigFields.getName() + " installed!"));
TextComponent setupOptions = new TextComponent(ChatColorConverter.convert("&4Click here to uninstall!"));
if (pastedSchematic)
setupOptions.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/em setup unminidungeon " + dungeonPackagerConfigFields.getFilename()));
else
setupOptions.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/em setup unminidungeonNoPaste " + dungeonPackagerConfigFields.getFilename()));
player.spigot().sendMessage(setupOptions);
quantifySchematicBosses(true);
}
use of net.md_5.bungee.api.chat.ClickEvent in project EliteMobs by MagmaGuy.
the class BossTrackingPage method bossTrackingPage.
protected static TextComponent[] bossTrackingPage(Player player) {
TextComponent configTextComponent = new TextComponent();
for (int i = 0; i < 3; i++) {
TextComponent line = new TextComponent(PlayerStatusMenuConfig.getBossTrackerTextLines()[i] + "\n");
if (!PlayerStatusMenuConfig.getBossTrackerHoverLines()[i].isEmpty())
PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.getBossTrackerHoverLines()[i]);
if (!PlayerStatusMenuConfig.getBossTrackerCommandLines()[i].isEmpty())
line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.getBossTrackerCommandLines()[i]));
configTextComponent.addExtra(line);
}
ArrayList<TextComponent> textComponents = new ArrayList<>();
int counter = 0;
for (CustomBossEntity customBossEntity : CustomBossEntity.getTrackableCustomBosses()) {
try {
textComponents.add(SpigotMessage.commandHoverMessage(customBossEntity.getCustomBossBossBar().bossBarMessage(player, customBossEntity.getCustomBossesConfigFields().getLocationMessage()) + "\n", PlayerStatusMenuConfig.getOnBossTrackHover(), "/elitemobs trackcustomboss " + customBossEntity.getEliteUUID()));
counter++;
} catch (Exception ex) {
new WarningMessage("Failed to correctly get elements for boss tracking page!");
ex.printStackTrace();
}
}
TextComponent[] textComponent;
if (counter == 0) {
textComponent = new TextComponent[1];
textComponent[0] = configTextComponent;
} else {
textComponent = new TextComponent[(int) Math.floor(counter / 6D) + 1];
int internalCounter = 0;
textComponent[0] = configTextComponent;
for (TextComponent text : textComponents) {
int currentPage = (int) Math.floor(internalCounter / 6D);
if (textComponent[currentPage] == null)
textComponent[currentPage] = new TextComponent();
textComponent[currentPage].addExtra(text);
internalCounter++;
}
}
return textComponent;
}
use of net.md_5.bungee.api.chat.ClickEvent in project EliteMobs by MagmaGuy.
the class StatsPage method statsPage.
protected static TextComponent statsPage(Player targetPlayer) {
TextComponent textComponent = new TextComponent();
for (int i = 0; i < 13; i++) {
TextComponent line = new TextComponent(PlayerStatusMenuConfig.getStatsTextLines()[i].replace("$money", EconomyHandler.checkCurrency(targetPlayer.getUniqueId()) + "").replace("$guildtier", PlayerStatusScreen.convertLightColorsToBlack(AdventurersGuildConfig.getShortenedRankName(GuildRank.getGuildPrestigeRank(targetPlayer), GuildRank.getActiveGuildRank(targetPlayer)))).replace("$kills", PlayerData.getKills(targetPlayer.getUniqueId()) + "").replace("$highestkill", PlayerData.getHighestLevelKilled(targetPlayer.getUniqueId()) + "").replace("$deaths", PlayerData.getDeaths(targetPlayer.getUniqueId()) + "").replace("$quests", PlayerData.getQuestsCompleted(targetPlayer.getUniqueId()) + "").replace("$score", PlayerData.getScore(targetPlayer.getUniqueId()) + "") + "\n");
if (!PlayerStatusMenuConfig.getStatsHoverLines()[i].isEmpty())
PlayerStatusScreen.setHoverText(line, PlayerStatusMenuConfig.getStatsHoverLines()[i]);
if (!PlayerStatusMenuConfig.getStatsCommandLines()[i].isEmpty())
line.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, PlayerStatusMenuConfig.getStatsCommandLines()[i]));
textComponent.addExtra(line);
}
return textComponent;
}
Aggregations