4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
# Use these Java versions
java: [
17 # Latest version
21 # Latest version
]
# and run on both Linux and Windows
os: [ubuntu-20.04]
Expand All @@ -32,7 +32,7 @@ jobs:
- name: build
run: ./gradlew build
- name: capture build artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -38,7 +38,7 @@ jobs:
MODRINTH: ${{ secrets.MODRINTH }}
CHANGELOG: ${{ github.event.release.body }}
- name: Upload GitHub release
uses: AButler/upload-release-assets@v2.0
uses: AButler/upload-release-assets@v3.0
with:
files: 'build/libs/*.jar;!build/libs/*-sources.jar;!build/libs/*-dev.jar'
repo-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4.+'
id 'fabric-loom' version '1.6.+'
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
}
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.0
minecraft_version=1.20.5-rc1
yarn_mappings=1.20.5-rc1+build.1
loader_version=0.15.10

#Fabric api
fabric_version=0.91.1+1.20.4
fabric_version=0.97.3+1.20.5

# Mod Properties
mod_version = 2.4.0-pre.1+1.20.4
mod_version = 2.4.0-pre.2+1.20.5
maven_group = eu.pb4
archives_base_name = placeholder-api

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ public Text toText(ParserContext context, boolean removeBackslashes) {
args[i] = this.args[i] instanceof TextNode textNode ? textNode.toText(context, removeBackslashes) : this.args[i];
}

if (GeneralUtils.IS_LEGACY_TRANSLATION) {
return Text.translatable(this.key, args);
} else {
return Text.translatableWithFallback(this.key(), this.fallback, args);
}

return Text.translatableWithFallback(this.key(), this.fallback, args);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public TextNode[] parseNodes(TextNode input) {
if (input instanceof LiteralNode literalNode) {
var list = new ArrayList<SubNode<?>>();
parseLiteral(literalNode, list::add);
return parseSubNodes(list.listIterator(), null, -1, false);
return parseSubNodes(list.listIterator(), null, -1);
} else if (input instanceof TranslatedNode translatedNode) {
return new TextNode[]{ translatedNode.transform(this) };
} else if (input instanceof ParentTextNode parentTextNode) {
Expand All @@ -87,7 +87,7 @@ public TextNode[] parseNodes(TextNode input) {
list.add(new SubNode<>(SubNodeType.TEXT_NODE, TextNode.asSingle(parseNodes(children))));
}
}
return new TextNode[]{parentTextNode.copyWith(parseSubNodes(list.listIterator(), null, -1, false), this)};
return new TextNode[]{parentTextNode.copyWith(parseSubNodes(list.listIterator(), null, -1), this)};
} else {
return new TextNode[]{input};
}
Expand All @@ -101,9 +101,7 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
var i = reader.read();
if (i == '\\' && reader.canRead()) {
var next = reader.read();
//if (next != '~' && next != '`' && next != '_' && next != '*' && next != '|') {
builder.append(i);
//}
builder.append(next);
continue;
}
Expand All @@ -129,7 +127,14 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
type = switch (i) {
case '`' -> SubNodeType.BACK_TICK;
case '*' -> SubNodeType.STAR;
case '_' -> SubNodeType.FLOOR;
case '_' -> {
if (reader.getCursor() == 1 || !reader.canRead()
|| Character.isWhitespace(reader.peek(-2))
|| Character.isWhitespace(reader.peek())) {
yield SubNodeType.FLOOR;
}
yield null;
}
case '(' -> SubNodeType.BRACKET_OPEN;
case ')' -> SubNodeType.BRACKET_CLOSE;
case '[' -> SubNodeType.SQR_BRACKET_OPEN;
Expand All @@ -155,7 +160,7 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
}
}

private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNodeType endAt, int count, boolean requireEmpty) {
private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNodeType endAt, int count) {
var out = new ArrayList<TextNode>();
int startIndex = nodes.nextIndex();
var builder = new StringBuilder();
Expand All @@ -165,16 +170,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
if (next.type == endAt) {
int foundCount = 1;

boolean endingOrSpace;
if (requireEmpty && nodes.hasNext()) {
var prev = nodes.next();
endingOrSpace = prev.type != SubNodeType.STRING || ((String) prev.value).startsWith(" ");
nodes.previous();
} else {
endingOrSpace = true;
}

if (foundCount == count && endingOrSpace) {
if (foundCount == count) {
if (!builder.isEmpty()) {
out.add(new LiteralNode(builder.toString()));
}
Expand All @@ -186,7 +182,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
while (nodes.hasNext()) {
if (nodes.next().type == endAt) {
if ((++foundCount) == count) {
if (requireEmpty && nodes.hasNext()) {
if (nodes.hasNext()) {
var prev = nodes.next();
nodes.previous();
if (prev.type == SubNodeType.STRING && !((String) prev.value).startsWith(" ")) {
Expand Down Expand Up @@ -220,7 +216,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
builder.append((String) next.value);
continue;
} else if (next.type == SubNodeType.BACK_TICK && this.allowedFormatting.contains(MarkdownFormat.QUOTE)) {
var value = parseSubNodes(nodes, next.type, 1, false);
var value = parseSubNodes(nodes, next.type, 1);

if (value != null) {
if (!builder.isEmpty()) {
Expand All @@ -231,7 +227,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
continue;
}
} else if (next.type == SubNodeType.SPOILER_LINE && this.allowedFormatting.contains(MarkdownFormat.SPOILER)) {
var value = parseSubNodes(nodes, next.type, 1, false);
var value = parseSubNodes(nodes, next.type, 1);

if (value != null) {
if (!builder.isEmpty()) {
Expand All @@ -242,7 +238,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
continue;
}
} else if (next.type == SubNodeType.DOUBLE_WAVY_LINE && this.allowedFormatting.contains(MarkdownFormat.STRIKETHROUGH)) {
var value = parseSubNodes(nodes, next.type, 1, false);
var value = parseSubNodes(nodes, next.type, 1);

if (value != null) {
if (!builder.isEmpty()) {
Expand All @@ -262,7 +258,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
if (nexter.type == next.type) {
two = true;
var i = nodes.nextIndex();
var value = parseSubNodes(nodes, next.type, 2, false);
var value = parseSubNodes(nodes, next.type, 2);

if (value != null) {
if (!builder.isEmpty()) {
Expand All @@ -288,7 +284,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
}

if (startingOrSpace) {
var value = parseSubNodes(nodes, next.type, 1, next.type == SubNodeType.FLOOR);
var value = parseSubNodes(nodes, next.type, 1);

if (value != null) {
if (!builder.isEmpty()) {
Expand All @@ -302,14 +298,14 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
}
} else if (next.type == SubNodeType.SQR_BRACKET_OPEN && this.allowedFormatting.contains(MarkdownFormat.URL) && nodes.hasNext()) {
var start = nodes.nextIndex();
var value = parseSubNodes(nodes, SubNodeType.SQR_BRACKET_CLOSE, 1, false);
var value = parseSubNodes(nodes, SubNodeType.SQR_BRACKET_CLOSE, 1);

if (value != null) {
if (nodes.hasNext()) {
var check = nodes.next().type == SubNodeType.BRACKET_OPEN;

if (check) {
var url = parseSubNodes(nodes, SubNodeType.BRACKET_CLOSE, 1, false);
var url = parseSubNodes(nodes, SubNodeType.BRACKET_CLOSE, 1);
if (url != null) {
if (!builder.isEmpty()) {
out.add(new LiteralNode(builder.toString()));
Expand Down
26 changes: 6 additions & 20 deletions src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.VersionParsingException;
import net.minecraft.component.DataComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.text.*;
import net.minecraft.util.Formatting;
Expand All @@ -23,19 +25,6 @@ public class GeneralUtils {
public static final boolean IS_DEV = FabricLoader.getInstance().isDevelopmentEnvironment();
public static final TextNode[] CASTER = new TextNode[0];

public static final boolean IS_LEGACY_TRANSLATION;

static {
boolean IS_LEGACY1;
try {
IS_LEGACY1 = FabricLoader.getInstance().getModContainer("minecraft").get().getMetadata().getVersion().compareTo(Version.parse("1.19.4")) < 0;
} catch (VersionParsingException e) {
IS_LEGACY1 = false;
e.printStackTrace();
}
IS_LEGACY_TRANSLATION = IS_LEGACY1;
}

public static String durationToString(long x) {
long seconds = x % 60;
long minutes = (x / 60) % 60;
Expand Down Expand Up @@ -203,12 +192,12 @@ public static MutableText cloneTransformText(Text input, Function<MutableText, M
public static Text getItemText(ItemStack stack, boolean rarity) {
if (!stack.isEmpty()) {
MutableText mutableText = Text.empty().append(stack.getName());
if (stack.hasCustomName()) {
if (stack.contains(DataComponentTypes.CUSTOM_NAME)) {
mutableText.formatted(Formatting.ITALIC);
}

if (rarity) {
mutableText.formatted(stack.getRarity().formatting);
mutableText.formatted(stack.getRarity().getFormatting());
}
mutableText.styled((style) -> {
return style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackContent(stack)));
Expand Down Expand Up @@ -237,11 +226,8 @@ public static ParentNode convertToNodes(Text input) {
}
}

if (IS_LEGACY_TRANSLATION) {
list.add(TranslatedNode.of(content.getKey(), args.toArray()));
} else {
list.add(TranslatedNode.ofFallback(content.getKey(), content.getFallback(), args.toArray()));
}

list.add(TranslatedNode.ofFallback(content.getKey(), content.getFallback(), args.toArray()));
} else if (input.getContent() instanceof ScoreTextContent content) {
list.add(new ScoreNode(content.getName(), content.getObjective()));
} else if (input.getContent() instanceof KeybindTextContent content) {
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/eu/pb4/placeholders/impl/textparser/BuiltinTags.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.pb4.placeholders.impl.textparser;


import com.mojang.datafixers.util.Either;
import eu.pb4.placeholders.api.arguments.StringArgs;
import eu.pb4.placeholders.api.arguments.SimpleArguments;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.entity.EntityType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.StringNbtReader;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registries;
import net.minecraft.text.*;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -112,8 +114,7 @@ public static void register() {
true,
(nodes, data, parser) -> {
return new ColorNode(nodes, TextColor.parse(data.get("value", 0, "white")).result().orElse(DEFAULT_COLOR));
}
)
})
);
}
{
Expand Down Expand Up @@ -316,7 +317,7 @@ public static void register() {
try {
return new HoverNode<>(nodes,
HoverNode.Action.ITEM_STACK,
new HoverEvent.ItemStackContent(ItemStack.fromNbt(StringNbtReader.parse(value)))
new HoverEvent.ItemStackContent(ItemStack.fromNbtOrEmpty(DynamicRegistryManager.EMPTY, StringNbtReader.parse(value)))
);
} catch (Throwable e) {
var stack = Registries.ITEM.get(Identifier.tryParse(data.get("item", value))).getDefaultStack();
Expand All @@ -326,11 +327,6 @@ public static void register() {
stack.setCount(Integer.parseInt(count));
}

var nbt = data.getNext("nbt");
if (nbt != null) {
stack.setNbt(StringNbtReader.parse(nbt));
}

return new HoverNode<>(nodes,
HoverNode.Action.ITEM_STACK,
new HoverEvent.ItemStackContent(stack)
Expand Down Expand Up @@ -421,7 +417,7 @@ public static void register() {
break;
}

TextColor.parse(part).get().ifLeft(textColors::add);
TextColor.parse(part).result().ifPresent(textColors::add);
}
return new GradientNode(nodes, switch (type) {
case "oklab" -> GradientNode.GradientProvider.colorsOkLab(textColors);
Expand Down Expand Up @@ -452,7 +448,7 @@ public static void register() {
break;
}

TextColor.parse(part).get().ifLeft(textColors::add);
TextColor.parse(part).result().ifPresent(textColors::add);
}
// We cannot have an empty list!
if (textColors.isEmpty()) {
Expand Down
Loading