Skip to content

Commit

Permalink
Forcibly backport placeholder parsing behavior from 1.19.3
Browse files Browse the repository at this point in the history
Signed-off-by: unilock <[email protected]>
  • Loading branch information
unilock committed Jun 4, 2024
1 parent 52d5ecc commit 5c20065
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.19.2+build.28
loader_version=0.15.11

# Mod Properties
mod_version=2.3.1
mod_version=2.3.2
maven_group=cc.unilock.nilcord
archives_base_name=nilcord

Expand Down
38 changes: 38 additions & 0 deletions src/main/java/cc/unilock/nilcord/mixin/PlaceholdersMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cc.unilock.nilcord.mixin;

import eu.pb4.placeholders.api.PlaceholderHandler;
import eu.pb4.placeholders.api.PlaceholderResult;
import eu.pb4.placeholders.api.Placeholders;
import eu.pb4.placeholders.api.node.TextNode;
import eu.pb4.placeholders.api.node.parent.ParentNode;
import eu.pb4.placeholders.api.parsers.NodeParser;
import eu.pb4.placeholders.impl.placeholder.NodePlaceholderParserImpl;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

import java.util.Map;
import java.util.regex.Pattern;

@Mixin(value = Placeholders.class, remap = false)
public class PlaceholdersMixin {
/**
* @author unilock
* @reason backport from 1.19.3
*/
@Overwrite
public static ParentNode parseNodes(TextNode node, Pattern pattern, Map<String, Text> placeholders) {
return new ParentNode(NodePlaceholderParserImpl.recursivePlaceholderParsing(node, pattern, new Placeholders.PlaceholderGetter() {
@Override
public PlaceholderHandler getPlaceholder(String placeholder) {
var x = placeholders.get(placeholder);
return x != null ? (ctx, arg) -> PlaceholderResult.value(x) : null;
}

@Override
public boolean isContextOptional() {
return true;
}
}, NodeParser.NOOP));
}
}
1 change: 1 addition & 0 deletions src/main/resources/nilcord.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"package": "cc.unilock.nilcord.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"PlaceholdersMixin",
"PlayerAdvancementTrackerMixin",
"PlayerManagerMixin"
],
Expand Down

0 comments on commit 5c20065

Please sign in to comment.