Skip to content

Commit

Permalink
✨ added "none" to hide stage from quest description
Browse files Browse the repository at this point in the history
  • Loading branch information
SkytAsul committed Dec 9, 2023
1 parent 718d193 commit a426872
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> @Nullable T getData(@NotNull PlayerAccount acc, @NotNull String dataKey);

Expand Down
15 changes: 13 additions & 2 deletions core/src/main/java/fr/skytasul/quests/BeautyQuests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit a426872

Please sign in to comment.