1
mirror of https://github.com/CarmJos/MineConfiguration.git synced 2026-06-04 13:55:03 +08:00

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

This commit is contained in:
2023-09-21 00:08:42 +08:00
parent 09537975e4
commit 2959c00795
@@ -208,7 +208,9 @@ public class PreparedItem {
LoreContent content = insertedLore.get(path); LoreContent content = insertedLore.get(path);
if (content == null) continue; if (content == null) continue;
String prefix = matcher.group(1); String prefix = Optional.ofNullable(matcher.group(1))
.map(s -> TextParser.parseText(player, s, placeholders))
.orElse("");
int offset1 = Optional.ofNullable(matcher.group(3)) int offset1 = Optional.ofNullable(matcher.group(3))
.map(Integer::parseInt).orElse(0); .map(Integer::parseInt).orElse(0);
Integer offset2 = Optional.ofNullable(matcher.group(4)) Integer offset2 = Optional.ofNullable(matcher.group(4))
@@ -230,20 +232,19 @@ public class PreparedItem {
public static List<String> parseLoreLine(@Nullable Player player, @NotNull LoreContent content, public static List<String> parseLoreLine(@Nullable Player player, @NotNull LoreContent content,
@NotNull Map<String, Object> placeholders, @NotNull Map<String, Object> placeholders,
@Nullable String prefix, int upOffset, int downOffset) { @NotNull String parsedPrefix, int upOffset, int downOffset) {
if (content.getContent().isEmpty()) return Collections.emptyList(); 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 ? "" : TextParser.parseText(player, prefix, placeholders);
List<String> finalLore = new ArrayList<>(); List<String> finalLore = new ArrayList<>();
for (int i = 0; i < upOffset; i++) finalLore.add(" "); for (int i = 0; i < upOffset; i++) finalLore.add(" ");
if (content.isOriginal()) { if (content.isOriginal()) {
content.getContent().stream().map(s -> finalPrefix + s).forEach(finalLore::add); content.getContent().stream().map(s -> parsedPrefix + s).forEach(finalLore::add);
} else { } else {
content.getContent().stream().map(s -> finalPrefix + TextParser.parseText(player, s, placeholders)) content.getContent().stream().map(s -> parsedPrefix + TextParser.parseText(player, s, placeholders))
.forEach(finalLore::add); .forEach(finalLore::add);
} }
for (int i = 0; i < downOffset; i++) finalLore.add(" "); for (int i = 0; i < downOffset; i++) finalLore.add(" ");