Parse format tokens in objective message

This commit is contained in:
PikaMug 2024-01-11 17:23:39 -05:00
parent 3413895abf
commit 3e59fc5659
2 changed files with 38 additions and 34 deletions

View File

@ -57,8 +57,8 @@ public class BukkitQuestJournal {
} }
public List<BaseComponent[]> getPages() { public List<BaseComponent[]> getPages() {
final Player player = owner.getPlayer();
if (owner.getCurrentQuests().isEmpty()) { if (owner.getCurrentQuests().isEmpty()) {
final Player player = owner.getPlayer();
final String title = BukkitLang.get(player, "journalTitle"); final String title = BukkitLang.get(player, "journalTitle");
return Collections.singletonList(new BookUtil.PageBuilder().add(new TextComponent(ChatColor.DARK_RED return Collections.singletonList(new BookUtil.PageBuilder().add(new TextComponent(ChatColor.DARK_RED
+ BukkitLang.get(player, "journalNoQuests").replace("<journal>", title))).build()); + BukkitLang.get(player, "journalNoQuests").replace("<journal>", title))).build());
@ -74,47 +74,50 @@ public class BukkitQuestJournal {
final BookUtil.PageBuilder builder = new BookUtil.PageBuilder().add(title).newLine(); final BookUtil.PageBuilder builder = new BookUtil.PageBuilder().add(title).newLine();
for (final Objective obj : owner.getCurrentObjectives(quest, false, false)) { for (final Objective obj : owner.getCurrentObjectives(quest, false, false)) {
final BukkitObjective objective = (BukkitObjective) obj; final BukkitObjective objective = (BukkitObjective) obj;
if (!plugin.getConfigSettings().canShowCompletedObjs() if (objective.getMessage() == null) {
&& objective.getMessage().startsWith(ChatColor.GRAY.toString())) {
continue; continue;
} }
if (objective.getMessage() != null) { final String message = "- " + BukkitLang.BukkitFormatToken.convertString(player,
String[] split = null; objective.getMessage());
if (objective.getMessage().contains("<item>") && objective.getGoalAsItem() != null) { if (!plugin.getConfigSettings().canShowCompletedObjs()
split = objective.getMessage().split("<item>"); && message.startsWith(ChatColor.GRAY.toString())) {
builder.add(split[0]); continue;
final ItemStack goal = objective.getGoalAsItem(); }
if (goal.getItemMeta() != null && goal.getItemMeta().hasDisplayName()) { String[] split = null;
builder.add("" + ChatColor.DARK_AQUA + ChatColor.ITALIC if (message.contains("<item>") && objective.getGoalAsItem() != null) {
+ goal.getItemMeta().getDisplayName()); split = message.split("<item>");
} else { builder.add(split[0]);
if (plugin.getConfigSettings().canTranslateNames()) { final ItemStack goal = objective.getGoalAsItem();
final TranslatableComponent tc = new TranslatableComponent(plugin.getLocaleManager() if (goal.getItemMeta() != null && goal.getItemMeta().hasDisplayName()) {
.queryItemStack(goal)); builder.add("" + ChatColor.DARK_AQUA + ChatColor.ITALIC
tc.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA); + goal.getItemMeta().getDisplayName());
builder.add(tc); } else {
} else {
builder.add(ChatColor.AQUA + BukkitItemUtil.getPrettyItemName(goal.getType().name()));
}
}
builder.add(split[1]).newLine();
}
if (objective.getMessage().contains("<mob>") && objective.getGoalAsMob() != null) {
split = objective.getMessage().split("<mob>");
builder.add(split[0]);
if (plugin.getConfigSettings().canTranslateNames()) { if (plugin.getConfigSettings().canTranslateNames()) {
final TranslatableComponent tc = new TranslatableComponent(plugin.getLocaleManager() final TranslatableComponent tc = new TranslatableComponent(plugin.getLocaleManager()
.queryEntityType(objective.getGoalAsMob().getEntityType(), null)); // TODO extra data .queryItemStack(goal));
tc.setColor(net.md_5.bungee.api.ChatColor.DARK_RED); tc.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
builder.add(tc); builder.add(tc);
} else { } else {
builder.add(BukkitMiscUtil.snakeCaseToUpperCamelCase(objective.getGoalAsMob().getEntityType().name())); builder.add(ChatColor.AQUA + BukkitItemUtil.getPrettyItemName(goal.getType().name()));
} }
builder.add(split[1]).newLine();
} }
if (split == null) { builder.add(split[1]).newLine();
builder.add(objective.getMessage()).newLine(); }
if (message.contains("<mob>") && objective.getGoalAsMob() != null) {
split = message.split("<mob>");
builder.add(split[0]);
if (plugin.getConfigSettings().canTranslateNames()) {
final TranslatableComponent tc = new TranslatableComponent(plugin.getLocaleManager()
.queryEntityType(objective.getGoalAsMob().getEntityType(), null)); // TODO extra data
tc.setColor(net.md_5.bungee.api.ChatColor.DARK_RED);
builder.add(tc);
} else {
builder.add(BukkitMiscUtil.snakeCaseToUpperCamelCase(objective.getGoalAsMob().getEntityType().name()));
} }
builder.add(split[1]).newLine();
}
if (split == null) {
builder.add(message).newLine();
} }
} }
pages.add(builder.build()); pages.add(builder.build());

View File

@ -1714,7 +1714,8 @@ public class BukkitQuester implements Quester {
} }
for (final Objective obj : q.getCurrentObjectives(quest, false, false)) { for (final Objective obj : q.getCurrentObjectives(quest, false, false)) {
final BukkitObjective objective = (BukkitObjective) obj; final BukkitObjective objective = (BukkitObjective) obj;
final String message = "- " + objective.getMessage(); final String message = "- " + BukkitLang.BukkitFormatToken.convertString(quester.getPlayer(),
objective.getMessage());
if (objective.getProgressAsItem() != null && objective.getGoalAsItem() != null) { if (objective.getProgressAsItem() != null && objective.getGoalAsItem() != null) {
final ItemStack progress = objective.getProgressAsItem(); final ItemStack progress = objective.getProgressAsItem();
final ItemStack goal = objective.getGoalAsItem(); final ItemStack goal = objective.getGoalAsItem();