diff --git a/api/src/main/java/fr/skytasul/quests/api/stages/StageController.java b/api/src/main/java/fr/skytasul/quests/api/stages/StageController.java index c38e3738..5ee40504 100644 --- a/api/src/main/java/fr/skytasul/quests/api/stages/StageController.java +++ b/api/src/main/java/fr/skytasul/quests/api/stages/StageController.java @@ -21,7 +21,7 @@ public interface StageController { public void updateObjective(@NotNull Player player, @NotNull String dataKey, @Nullable Object dataValue); - public @NotNull String getDescriptionLine(@NotNull PlayerAccount acc, @NotNull DescriptionSource source); + public @Nullable String getDescriptionLine(@NotNull PlayerAccount acc, @NotNull DescriptionSource source); public @Nullable T getData(@NotNull PlayerAccount acc, @NotNull String dataKey); diff --git a/core/src/main/java/fr/skytasul/quests/BeautyQuests.java b/core/src/main/java/fr/skytasul/quests/BeautyQuests.java index 89b647db..d0685e33 100644 --- a/core/src/main/java/fr/skytasul/quests/BeautyQuests.java +++ b/core/src/main/java/fr/skytasul/quests/BeautyQuests.java @@ -436,10 +436,21 @@ private void loadDefaultIntegrations() { InternalIntegrations.AccountsHook.isEnabled(); // to initialize the class } - private YamlConfiguration loadLang() throws LoadingException { + private void loadLang() throws LoadingException { try { loadedLanguage = config.getConfig().getString("lang", "en_US"); - return Locale.loadLang(this, Lang.values(), loadedLanguage); + Locale.loadLang(this, Lang.values(), loadedLanguage); + + Pattern oldPlaceholders = Pattern.compile("\\{\\d\\}"); + for (Lang l : Lang.values()) { + if (oldPlaceholders.matcher(l.getValue()).find()) { + logger.warning( + "Found old placeholder format in /plugins/BeautyQuests/locales/" + loadedLanguage + ".yml."); + logger.warning( + "This means you probably have not deleted the locales folder after upgrading from a pre-1.0 version." + + " Expect some bugs with message formatting."); + } + } }catch (Exception ex) { throw new LoadingException("Couldn't load language file.", ex); } diff --git a/core/src/main/java/fr/skytasul/quests/structure/QuestBranchImplementation.java b/core/src/main/java/fr/skytasul/quests/structure/QuestBranchImplementation.java index a43e445b..4fe2ed87 100644 --- a/core/src/main/java/fr/skytasul/quests/structure/QuestBranchImplementation.java +++ b/core/src/main/java/fr/skytasul/quests/structure/QuestBranchImplementation.java @@ -1,9 +1,6 @@ package fr.skytasul.quests.structure; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; @@ -125,26 +122,19 @@ public boolean isEndingStage(StageController stage) { throw new IllegalArgumentException("Account does not have this branch launched"); if (asyncReward.contains(acc)) return Lang.SCOREBOARD_ASYNC_END.toString(); if (datas.isInEndingStages()) { - StringBuilder stb = new StringBuilder(); - int i = 0; - for (EndingStage ending : endStages) { - i++; - stb.append(ending.getStage().getDescriptionLine(acc, source)); - if (i != endStages.size()){ - stb.append("{nl}"); - stb.append(Lang.SCOREBOARD_BETWEEN_BRANCHES.toString()); - stb.append("{nl}"); - } - } - return stb.toString(); + return endStages.stream() + .map(stage -> stage.getStage().getDescriptionLine(acc, source)) + .filter(Objects::nonNull) + .collect(Collectors.joining("{nl}" + Lang.SCOREBOARD_BETWEEN_BRANCHES + " {nl}")); } if (datas.getStage() < 0) return "§cerror: no stage set for branch " + getId(); if (datas.getStage() >= regularStages.size()) return "§cerror: datas do not match"; + String descriptionLine = regularStages.get(datas.getStage()).getDescriptionLine(acc, source); return MessageUtils.format(QuestsConfiguration.getConfig().getStageDescriptionConfig().getStageDescriptionFormat(), PlaceholderRegistry.of("stage_index", datas.getStage() + 1, "stage_amount", regularStages.size(), - "stage_description", regularStages.get(datas.getStage()).getDescriptionLine(acc, source))); + "stage_description", descriptionLine == null ? "" : descriptionLine)); } @Override diff --git a/core/src/main/java/fr/skytasul/quests/structure/StageControllerImplementation.java b/core/src/main/java/fr/skytasul/quests/structure/StageControllerImplementation.java index b0a6d36e..03d047c1 100644 --- a/core/src/main/java/fr/skytasul/quests/structure/StageControllerImplementation.java +++ b/core/src/main/java/fr/skytasul/quests/structure/StageControllerImplementation.java @@ -116,11 +116,19 @@ public void updateObjective(@NotNull Player player, @NotNull String dataKey, @Nu } @Override - public @NotNull String getDescriptionLine(@NotNull PlayerAccount acc, @NotNull DescriptionSource source) { + public @Nullable String getDescriptionLine(@NotNull PlayerAccount acc, @NotNull DescriptionSource source) { try { + String description = stage.getCustomText(); + if (description != null) { + if (description.equals("none")) + return null; + description = "§e" + description; + } + StageDescriptionPlaceholdersContext context = StageDescriptionPlaceholdersContext.of(true, acc, source, null); - String description = - stage.getCustomText() == null ? stage.getDefaultDescription(context) : ("§e" + stage.getCustomText()); + if (description == null) + description = stage.getDefaultDescription(context); + return MessageUtils.finalFormat(description, stage.getPlaceholdersRegistry(), context); } catch (Exception ex) { QuestsPlugin.getPlugin().getLoggerExpanded().severe(