1
mirror of https://github.com/CarmJos/MineConfiguration.git synced 2026-06-04 21:58:16 +08:00

feat(item): 重构物品相关代码,支持更多功能

This commit is contained in:
2023-09-20 23:46:59 +08:00
parent 02625b5c0c
commit 09537975e4
@@ -21,7 +21,6 @@ import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class PreparedItem { public class PreparedItem {
@@ -215,8 +214,8 @@ public class PreparedItem {
Integer offset2 = Optional.ofNullable(matcher.group(4)) Integer offset2 = Optional.ofNullable(matcher.group(4))
.map(Integer::parseInt).orElse(null); .map(Integer::parseInt).orElse(null);
List<String> inserted = generateLore( List<String> inserted = parseLoreLine(
content.getContent(), prefix, player, content, placeholders, prefix,
offset2 == null ? 0 : offset1, offset2 == null ? offset1 : offset2 offset2 == null ? 0 : offset1, offset2 == null ? offset1 : offset2
); );
@@ -229,17 +228,25 @@ public class PreparedItem {
return parsedLore; return parsedLore;
} }
public static List<String> generateLore(List<String> lore, String prefix, int upOffset, int downOffset) { public static List<String> parseLoreLine(@Nullable Player player, @NotNull LoreContent content,
if (lore == null || lore.isEmpty()) return Collections.emptyList(); @NotNull Map<String, Object> placeholders,
@Nullable String prefix, int upOffset, int downOffset) {
if (content.getContent().isEmpty()) return Collections.emptyList();
upOffset = Math.max(0, upOffset); upOffset = Math.max(0, upOffset);
downOffset = Math.max(0, downOffset); downOffset = Math.max(0, downOffset);
String finalPrefix = prefix == null ? "" : prefix; String finalPrefix = prefix == null ? "" : TextParser.parseText(player, prefix, placeholders);
List<String> finalLore = new ArrayList<>();
ArrayList<String> finalLore = lore.stream().map(s -> finalPrefix + s) for (int i = 0; i < upOffset; i++) finalLore.add(" ");
.collect(Collectors.toCollection(ArrayList::new)); if (content.isOriginal()) {
for (int i = 0; i < upOffset; i++) finalLore.add(0, " "); content.getContent().stream().map(s -> finalPrefix + s).forEach(finalLore::add);
for (int i = 0; i < downOffset; i++) finalLore.add(finalLore.size(), " "); } else {
content.getContent().stream().map(s -> finalPrefix + TextParser.parseText(player, s, placeholders))
.forEach(finalLore::add);
}
for (int i = 0; i < downOffset; i++) finalLore.add(" ");
return finalLore; return finalLore;
} }