64 changes: 64 additions & 0 deletions .profileconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"jfrConfig": {
"settings": "profile"
},
"asyncProfilerConfig": {
"jfrsync": true,
"alloc": true,
"event": "wall",
"misc": ""
},
"file": "$PROJECT_DIR/profile.jfr",
"conversionConfig": {
"nonProjectPackagePrefixes": [
"java.",
"javax.",
"kotlin.",
"jdk.",
"com.google.",
"org.apache.",
"org.spring.",
"sun.",
"scala."
],
"enableMarkers": true,
"initialVisibleThreads": 10,
"initialSelectedThreads": 10,
"includeGCThreads": false,
"includeInitialSystemProperty": false,
"includeInitialEnvironmentVariables": false,
"includeSystemProcesses": false,
"ignoredEvents": [
"jdk.ActiveSetting",
"jdk.ActiveRecording",
"jdk.BooleanFlag",
"jdk.IntFlag",
"jdk.DoubleFlag",
"jdk.LongFlag",
"jdk.NativeLibrary",
"jdk.StringFlag",
"jdk.UnsignedIntFlag",
"jdk.UnsignedLongFlag",
"jdk.InitialSystemProperty",
"jdk.InitialEnvironmentVariable",
"jdk.SystemProcess",
"jdk.ModuleExport",
"jdk.ModuleRequire"
],
"minRequiredItemsPerThread": 3
},
"additionalGradleTargets": [
{
"targetPrefix": "quarkus",
"optionForVmArgs": "-Djvm.args",
"description": "Example quarkus config, adding profiling arguments via -Djvm.args option to the Gradle task run"
}
],
"additionalMavenTargets": [
{
"targetPrefix": "quarkus:",
"optionForVmArgs": "-Djvm.args",
"description": "Example quarkus config, adding profiling arguments via -Djvm.args option to the Maven goal run"
}
]
}
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

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

#Fabric api
fabric_version=0.125.2+1.21.6
fabric_version=0.127.0+1.21.6

# Mod Properties
mod_version = 2.7.0+1.21.6
mod_version = 2.7.1+1.21.6
maven_group = eu.pb4
archives_base_name = placeholder-api
10 changes: 5 additions & 5 deletions src/main/java/eu/pb4/placeholders/api/Placeholders.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
import java.util.regex.Pattern;

public final class Placeholders {
@Deprecated
@Deprecated(forRemoval = true)
public static final Pattern PLACEHOLDER_PATTERN = PatternPlaceholderParser.PLACEHOLDER_PATTERN;
@Deprecated
@Deprecated(forRemoval = true)
public static final Pattern ALT_PLACEHOLDER_PATTERN = PatternPlaceholderParser.ALT_PLACEHOLDER_PATTERN;
@Deprecated
@Deprecated(forRemoval = true)
public static final Pattern PLACEHOLDER_PATTERN_CUSTOM = PatternPlaceholderParser.PLACEHOLDER_PATTERN_CUSTOM;
@Deprecated
@Deprecated(forRemoval = true)
public static final Pattern ALT_PLACEHOLDER_PATTERN_CUSTOM = PatternPlaceholderParser.ALT_PLACEHOLDER_PATTERN_CUSTOM;
@Deprecated
@Deprecated(forRemoval = true)
public static final Pattern PREDEFINED_PLACEHOLDER_PATTERN = PatternPlaceholderParser.PREDEFINED_PLACEHOLDER_PATTERN;

private static final HashMap<Identifier, PlaceholderHandler> PLACEHOLDERS = new HashMap<>();
Expand Down
49 changes: 0 additions & 49 deletions src/main/java/eu/pb4/placeholders/api/node/parent/StyledNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,55 +65,6 @@ public Style style(ParserContext context) {
case RUN_COMMAND -> style = style.withClickEvent(new ClickEvent.RunCommand(node));
case SUGGEST_COMMAND -> style = style.withClickEvent(new ClickEvent.SuggestCommand(node));
case COPY_TO_CLIPBOARD -> style = style.withClickEvent(new ClickEvent.CopyToClipboard(node));
case CUSTOM -> {
try {
RegistryWrapper.WrapperLookup wrapper;
if (context.contains(ParserContext.Key.WRAPPER_LOOKUP)) {
wrapper = context.getOrThrow(ParserContext.Key.WRAPPER_LOOKUP);
} else if (context.contains(PlaceholderContext.KEY)) {
wrapper = context.getOrThrow(PlaceholderContext.KEY).server().getRegistryManager();
} else {
wrapper = GeneralUtils.DEFAULT_WRAPPER;
}

style = style.withClickEvent(new ClickEvent.Custom(
Identifier.of(node),
/*this.data == null ?*/ Optional.empty() //: Optional.of(StringNbtReader.fromOps(wrapper.getOps(NbtOps.INSTANCE)).read(this.data.toText(context).getString()))
));
} catch (Throwable e) {
// ignore
}

}
case SHOW_DIALOG -> {
RegistryWrapper.WrapperLookup wrapper;
if (context.contains(ParserContext.Key.WRAPPER_LOOKUP)) {
wrapper = context.getOrThrow(ParserContext.Key.WRAPPER_LOOKUP);
} else if (context.contains(PlaceholderContext.KEY)) {
wrapper = context.getOrThrow(PlaceholderContext.KEY).server().getRegistryManager();
} else {
wrapper = GeneralUtils.DEFAULT_WRAPPER;
}
RegistryEntry<Dialog> dialogRegistryEntry = null;

var id = Identifier.tryParse(node);

if (id != null) {
dialogRegistryEntry = wrapper.getOptionalEntry(RegistryKey.of(RegistryKeys.DIALOG, id)).orElse(null);
}

if (dialogRegistryEntry == null) {
try {
dialogRegistryEntry = Dialog.ENTRY_CODEC.decode(
wrapper.getOps(JsonOps.INSTANCE), JsonParser.parseString(node)).getOrThrow().getFirst();
} catch (Throwable e) {
// ignored
}
}
if (dialogRegistryEntry != null) {
style = style.withClickEvent(new ClickEvent.ShowDialog(dialogRegistryEntry));
}
}
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.text.*;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -253,7 +254,6 @@ public static ParentNode convertToNodes(Text input) {
}
}


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

@Nullable
private static TextNode getClickValue(Style style) {
if (style.getClickEvent() != null) {
return TextNode.of(switch (style.getClickEvent()) {
case ClickEvent.ChangePage event -> String.valueOf(event.page());
case ClickEvent.CopyToClipboard event -> event.value();
case ClickEvent.OpenFile openFile -> openFile.file().getPath();
case ClickEvent.OpenUrl openUrl -> openUrl.uri().toString();
case ClickEvent.RunCommand runCommand -> runCommand.command();
case ClickEvent.SuggestCommand suggestCommand -> suggestCommand.command();
default -> "";
});
return switch (style.getClickEvent()) {
case ClickEvent.ChangePage event -> TextNode.of(String.valueOf(event.page()));
case ClickEvent.CopyToClipboard event -> TextNode.of(event.value());
case ClickEvent.OpenFile openFile -> TextNode.of(openFile.file().getPath());
case ClickEvent.OpenUrl openUrl -> TextNode.of(openUrl.uri().toString());
case ClickEvent.RunCommand runCommand -> TextNode.of(runCommand.command());
case ClickEvent.SuggestCommand suggestCommand -> TextNode.of(suggestCommand.command());
default -> null;
};
}

return null;
Expand Down
1 change: 1 addition & 0 deletions src/testmod/java/eu/pb4/placeholderstest/TestMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private static int test(CommandContext<ServerCommandSource> context) {
ServerPlayerEntity player = context.getSource().getPlayer();
player.sendMessage(Placeholders.parseText(context.getArgument("text", Text.class), PlaceholderContext.of(player)), false);
player.sendMessage(Text.literal(TextNode.convert(context.getArgument("text", Text.class)).toString()), false);
player.sendMessage(Text.literal(Placeholders.parseNodes(TextNode.convert(context.getArgument("text", Text.class))).toString()), false);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down