Skip to content

Commit d7c9ebe

Browse files
committed
Fix transformation of custom and dialog click actions
1 parent 2e4fd87 commit d7c9ebe

6 files changed

Lines changed: 85 additions & 68 deletions

File tree

.profileconfig.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"jfrConfig": {
3+
"settings": "profile"
4+
},
5+
"asyncProfilerConfig": {
6+
"jfrsync": true,
7+
"alloc": true,
8+
"event": "wall",
9+
"misc": ""
10+
},
11+
"file": "$PROJECT_DIR/profile.jfr",
12+
"conversionConfig": {
13+
"nonProjectPackagePrefixes": [
14+
"java.",
15+
"javax.",
16+
"kotlin.",
17+
"jdk.",
18+
"com.google.",
19+
"org.apache.",
20+
"org.spring.",
21+
"sun.",
22+
"scala."
23+
],
24+
"enableMarkers": true,
25+
"initialVisibleThreads": 10,
26+
"initialSelectedThreads": 10,
27+
"includeGCThreads": false,
28+
"includeInitialSystemProperty": false,
29+
"includeInitialEnvironmentVariables": false,
30+
"includeSystemProcesses": false,
31+
"ignoredEvents": [
32+
"jdk.ActiveSetting",
33+
"jdk.ActiveRecording",
34+
"jdk.BooleanFlag",
35+
"jdk.IntFlag",
36+
"jdk.DoubleFlag",
37+
"jdk.LongFlag",
38+
"jdk.NativeLibrary",
39+
"jdk.StringFlag",
40+
"jdk.UnsignedIntFlag",
41+
"jdk.UnsignedLongFlag",
42+
"jdk.InitialSystemProperty",
43+
"jdk.InitialEnvironmentVariable",
44+
"jdk.SystemProcess",
45+
"jdk.ModuleExport",
46+
"jdk.ModuleRequire"
47+
],
48+
"minRequiredItemsPerThread": 3
49+
},
50+
"additionalGradleTargets": [
51+
{
52+
"targetPrefix": "quarkus",
53+
"optionForVmArgs": "-Djvm.args",
54+
"description": "Example quarkus config, adding profiling arguments via -Djvm.args option to the Gradle task run"
55+
}
56+
],
57+
"additionalMavenTargets": [
58+
{
59+
"targetPrefix": "quarkus:",
60+
"optionForVmArgs": "-Djvm.args",
61+
"description": "Example quarkus config, adding profiling arguments via -Djvm.args option to the Maven goal run"
62+
}
63+
]
64+
}

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
55
# check these on https://fabricmc.net/use
6-
minecraft_version=1.21.6-pre2
7-
yarn_mappings=1.21.6-pre2+build.1
6+
minecraft_version=1.21.6
7+
yarn_mappings=1.21.6+build.1
88
loader_version=0.16.14
99

1010
#Fabric api
11-
fabric_version=0.125.2+1.21.6
11+
fabric_version=0.127.0+1.21.6
1212

1313
# Mod Properties
14-
mod_version = 2.7.0+1.21.6
14+
mod_version = 2.7.1+1.21.6
1515
maven_group = eu.pb4
1616
archives_base_name = placeholder-api

src/main/java/eu/pb4/placeholders/api/Placeholders.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
import java.util.regex.Pattern;
1919

2020
public final class Placeholders {
21-
@Deprecated
21+
@Deprecated(forRemoval = true)
2222
public static final Pattern PLACEHOLDER_PATTERN = PatternPlaceholderParser.PLACEHOLDER_PATTERN;
23-
@Deprecated
23+
@Deprecated(forRemoval = true)
2424
public static final Pattern ALT_PLACEHOLDER_PATTERN = PatternPlaceholderParser.ALT_PLACEHOLDER_PATTERN;
25-
@Deprecated
25+
@Deprecated(forRemoval = true)
2626
public static final Pattern PLACEHOLDER_PATTERN_CUSTOM = PatternPlaceholderParser.PLACEHOLDER_PATTERN_CUSTOM;
27-
@Deprecated
27+
@Deprecated(forRemoval = true)
2828
public static final Pattern ALT_PLACEHOLDER_PATTERN_CUSTOM = PatternPlaceholderParser.ALT_PLACEHOLDER_PATTERN_CUSTOM;
29-
@Deprecated
29+
@Deprecated(forRemoval = true)
3030
public static final Pattern PREDEFINED_PLACEHOLDER_PATTERN = PatternPlaceholderParser.PREDEFINED_PLACEHOLDER_PATTERN;
3131

3232
private static final HashMap<Identifier, PlaceholderHandler> PLACEHOLDERS = new HashMap<>();

src/main/java/eu/pb4/placeholders/api/node/parent/StyledNode.java

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -65,55 +65,6 @@ public Style style(ParserContext context) {
6565
case RUN_COMMAND -> style = style.withClickEvent(new ClickEvent.RunCommand(node));
6666
case SUGGEST_COMMAND -> style = style.withClickEvent(new ClickEvent.SuggestCommand(node));
6767
case COPY_TO_CLIPBOARD -> style = style.withClickEvent(new ClickEvent.CopyToClipboard(node));
68-
case CUSTOM -> {
69-
try {
70-
RegistryWrapper.WrapperLookup wrapper;
71-
if (context.contains(ParserContext.Key.WRAPPER_LOOKUP)) {
72-
wrapper = context.getOrThrow(ParserContext.Key.WRAPPER_LOOKUP);
73-
} else if (context.contains(PlaceholderContext.KEY)) {
74-
wrapper = context.getOrThrow(PlaceholderContext.KEY).server().getRegistryManager();
75-
} else {
76-
wrapper = GeneralUtils.DEFAULT_WRAPPER;
77-
}
78-
79-
style = style.withClickEvent(new ClickEvent.Custom(
80-
Identifier.of(node),
81-
/*this.data == null ?*/ Optional.empty() //: Optional.of(StringNbtReader.fromOps(wrapper.getOps(NbtOps.INSTANCE)).read(this.data.toText(context).getString()))
82-
));
83-
} catch (Throwable e) {
84-
// ignore
85-
}
86-
87-
}
88-
case SHOW_DIALOG -> {
89-
RegistryWrapper.WrapperLookup wrapper;
90-
if (context.contains(ParserContext.Key.WRAPPER_LOOKUP)) {
91-
wrapper = context.getOrThrow(ParserContext.Key.WRAPPER_LOOKUP);
92-
} else if (context.contains(PlaceholderContext.KEY)) {
93-
wrapper = context.getOrThrow(PlaceholderContext.KEY).server().getRegistryManager();
94-
} else {
95-
wrapper = GeneralUtils.DEFAULT_WRAPPER;
96-
}
97-
RegistryEntry<Dialog> dialogRegistryEntry = null;
98-
99-
var id = Identifier.tryParse(node);
100-
101-
if (id != null) {
102-
dialogRegistryEntry = wrapper.getOptionalEntry(RegistryKey.of(RegistryKeys.DIALOG, id)).orElse(null);
103-
}
104-
105-
if (dialogRegistryEntry == null) {
106-
try {
107-
dialogRegistryEntry = Dialog.ENTRY_CODEC.decode(
108-
wrapper.getOps(JsonOps.INSTANCE), JsonParser.parseString(node)).getOrThrow().getFirst();
109-
} catch (Throwable e) {
110-
// ignored
111-
}
112-
}
113-
if (dialogRegistryEntry != null) {
114-
style = style.withClickEvent(new ClickEvent.ShowDialog(dialogRegistryEntry));
115-
}
116-
}
11768
}
11869
}
11970

src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minecraft.text.*;
1212
import net.minecraft.util.Formatting;
1313
import org.jetbrains.annotations.ApiStatus;
14+
import org.jetbrains.annotations.Nullable;
1415
import org.slf4j.Logger;
1516
import org.slf4j.LoggerFactory;
1617

@@ -253,7 +254,6 @@ public static ParentNode convertToNodes(Text input) {
253254
}
254255
}
255256

256-
257257
list.add(TranslatedNode.ofFallback(content.getKey(), content.getFallback(), args.toArray()));
258258
} else if (input.getContent() instanceof ScoreTextContent content) {
259259
list.add(new ScoreNode(content.name(), content.objective()));
@@ -297,17 +297,18 @@ private static StyledNode.HoverData<?> getHoverValue(Style style) {
297297
return null;
298298
}
299299

300+
@Nullable
300301
private static TextNode getClickValue(Style style) {
301302
if (style.getClickEvent() != null) {
302-
return TextNode.of(switch (style.getClickEvent()) {
303-
case ClickEvent.ChangePage event -> String.valueOf(event.page());
304-
case ClickEvent.CopyToClipboard event -> event.value();
305-
case ClickEvent.OpenFile openFile -> openFile.file().getPath();
306-
case ClickEvent.OpenUrl openUrl -> openUrl.uri().toString();
307-
case ClickEvent.RunCommand runCommand -> runCommand.command();
308-
case ClickEvent.SuggestCommand suggestCommand -> suggestCommand.command();
309-
default -> "";
310-
});
303+
return switch (style.getClickEvent()) {
304+
case ClickEvent.ChangePage event -> TextNode.of(String.valueOf(event.page()));
305+
case ClickEvent.CopyToClipboard event -> TextNode.of(event.value());
306+
case ClickEvent.OpenFile openFile -> TextNode.of(openFile.file().getPath());
307+
case ClickEvent.OpenUrl openUrl -> TextNode.of(openUrl.uri().toString());
308+
case ClickEvent.RunCommand runCommand -> TextNode.of(runCommand.command());
309+
case ClickEvent.SuggestCommand suggestCommand -> TextNode.of(suggestCommand.command());
310+
default -> null;
311+
};
311312
}
312313

313314
return null;

src/testmod/java/eu/pb4/placeholderstest/TestMod.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private static int test(CommandContext<ServerCommandSource> context) {
110110
ServerPlayerEntity player = context.getSource().getPlayer();
111111
player.sendMessage(Placeholders.parseText(context.getArgument("text", Text.class), PlaceholderContext.of(player)), false);
112112
player.sendMessage(Text.literal(TextNode.convert(context.getArgument("text", Text.class)).toString()), false);
113+
player.sendMessage(Text.literal(Placeholders.parseNodes(TextNode.convert(context.getArgument("text", Text.class))).toString()), false);
113114
} catch (Exception e) {
114115
e.printStackTrace();
115116
}

0 commit comments

Comments
 (0)