Showing with 39 additions and 25 deletions.
  1. +3 −0 docs/user/general.md
  2. +15 −0 docs/user/mod-placeholders.md
  3. +1 −1 gradle.properties
  4. +20 −24 src/main/java/eu/pb4/placeholders/api/parsers/MarkdownLiteParserV1.java
3 changes: 3 additions & 0 deletions docs/user/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ and [placeholders from mods here](/user/mod-placeholders).
[Modrinth](https://modrinth.com/mod/discord4fabric),
[Github](https://github.com/Reimnop/Discord4Fabric)

- Fuji -
[Modrinth](https://modrinth.com/mod/fuji),
[Github](https://github.com/sakurawald/fuji-fabric/)
15 changes: 15 additions & 0 deletions docs/user/mod-placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ These placeholders are provided by other mods. Some are build in directly, while
- `%afkplus:invulnerable%` - Returns a basic tag to display the status if a player is marked as "invulnerable" using the "disableDamage"
features. It is also used internally under the default "[AFK]" tag method, with "[AFK:I]", for example.

### [Fuji](https://modrinth.com/mod/fuji)
- `%fuji:player_mined%` - Sum of mining blocks of a player.
- `%fuji:server_mined%` - Sum of mining blocks of a server.
- `%fuji:player_placed%` - Sum of placed blocks of a player.
- `%fuji:server_placed%` - Sum of placed blocks of a server.
- `%fuji:player_killed%` - Sum of killed entities of a player.
- `%fuji:server_killed%` - Sum of killed entities of a server.
- `%fuji:player_moved%` - Sum of moved distance of a player.
- `%fuji:server_moved%` - Sum of moved distance of a server.
- `%fuji:player_playtime%` - Sum of playtime of a player.
- `%fuji:server_playtime%` - Sum of playtime of a server.
- `%fuji:item%` - Create the display of main-hand item.
- `%fuji:inv%` - Create the display of inventory.
- `%fuji:ender%` - Create the display of ender-chest.

### [Get Off My Lawn ReServed](https://pb4.eu/#get-off-my-lawn)

- `%goml:claim_owners%`/`%goml:claim_owners [no owners text]%` - Returns a list of claim owners.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1G
fabric_version=0.100.1+1.21

# Mod Properties
mod_version = 2.4.1+1.21
mod_version = 2.4.2+1.21
maven_group = eu.pb4
archives_base_name = placeholder-api

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