2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ org.gradle.jvmargs=-Xmx1G
fabric_version=0.119.1+1.21.5

# Mod Properties
mod_version = 2.6.0+1.21.5
mod_version = 2.6.1+1.21.5
maven_group = eu.pb4
archives_base_name = placeholder-api
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import java.net.URI;

public final class ClickActionNode extends SimpleStylingNode {
private final Action action;
private final ClickEvent.Action action;
private final TextNode value;

public ClickActionNode(TextNode[] children, Action action, TextNode value) {
public ClickActionNode(TextNode[] children, ClickEvent.Action action, TextNode value) {
super(children);
this.action = action;
this.value = value;
}

public Action action() {
public ClickEvent.Action clickEventAction() {
return action;
}

Expand All @@ -28,29 +28,26 @@ public TextNode value() {

@Override
protected Style style(ParserContext context) {
if (this.action == Action.OPEN_URL) {
try {
return Style.EMPTY.withClickEvent(new ClickEvent.OpenUrl(URI.create(this.value.toText(context).getString())));
} catch (Exception ignored) {
return Style.EMPTY;
return switch (this.action) {
case OPEN_URL -> {
try {
yield Style.EMPTY.withClickEvent(new ClickEvent.OpenUrl(URI.create(this.value.toText(context).getString())));
} catch (Exception ignored) {
yield Style.EMPTY;
}
}
} else if (this.action == Action.CHANGE_PAGE) {
try {
return Style.EMPTY.withClickEvent(new ClickEvent.ChangePage(Integer.parseInt(this.value.toText(context).getString())));
} catch (Exception ignored) {
return Style.EMPTY;
case CHANGE_PAGE -> {
try {
yield Style.EMPTY.withClickEvent(new ClickEvent.ChangePage(Integer.parseInt(this.value.toText(context).getString())));
} catch (Exception ignored) {
yield Style.EMPTY;
}
}
} else if (this.action == Action.OPEN_FILE) {
return Style.EMPTY.withClickEvent(new ClickEvent.OpenFile(this.value.toText(context).getString()));
} else if (this.action == Action.RUN_COMMAND) {
return Style.EMPTY.withClickEvent(new ClickEvent.RunCommand(this.value.toText(context).getString()));
} else if (this.action == Action.SUGGEST_COMMAND) {
return Style.EMPTY.withClickEvent(new ClickEvent.SuggestCommand(this.value.toText(context).getString()));
} else if (this.action == Action.COPY_TO_CLIPBOARD) {
return Style.EMPTY.withClickEvent(new ClickEvent.CopyToClipboard(this.value.toText(context).getString()));
} else {
return Style.EMPTY;
}
case OPEN_FILE -> Style.EMPTY.withClickEvent(new ClickEvent.OpenFile(this.value.toText(context).getString()));
case RUN_COMMAND -> Style.EMPTY.withClickEvent(new ClickEvent.RunCommand(this.value.toText(context).getString()));
case SUGGEST_COMMAND -> Style.EMPTY.withClickEvent(new ClickEvent.SuggestCommand(this.value.toText(context).getString()));
case COPY_TO_CLIPBOARD -> Style.EMPTY.withClickEvent(new ClickEvent.CopyToClipboard(this.value.toText(context).getString()));
};
}

@Override
Expand All @@ -71,11 +68,31 @@ public boolean isDynamicNoChildren() {
@Override
public String toString() {
return "ClickActionNode{" +
"action=" + action +
"action=" + action.asString() +
", value=" + value +
'}';
}


@Deprecated(forRemoval = true)
public ClickActionNode(TextNode[] children, Action action, TextNode value) {
super(children);
this.action = action.vanillaType();
this.value = value;
}

@Deprecated(forRemoval = true)
public Action action() {
return switch (this.action) {
case OPEN_URL -> Action.OPEN_URL;
case OPEN_FILE -> Action.OPEN_FILE;
case CHANGE_PAGE -> Action.CHANGE_PAGE;
case RUN_COMMAND -> Action.RUN_COMMAND;
case SUGGEST_COMMAND -> Action.SUGGEST_COMMAND;
case COPY_TO_CLIPBOARD -> Action.COPY_TO_CLIPBOARD;
};
}
@Deprecated(forRemoval = true)
public record Action(ClickEvent.Action vanillaType) {
public static final Action OPEN_URL = new Action(ClickEvent.Action.OPEN_URL);
public static final Action CHANGE_PAGE = new Action(ClickEvent.Action.CHANGE_PAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import eu.pb4.placeholders.api.node.parent.HoverNode;
import eu.pb4.placeholders.api.node.parent.ParentTextNode;
import eu.pb4.placeholders.impl.textparser.TextParserImpl;
import net.minecraft.text.ClickEvent;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -68,7 +69,7 @@ public static TextNode defaultQuoteFormatting(TextNode[] textNodes) {
}

public static TextNode defaultUrlFormatting(TextNode[] textNodes, TextNode url) {
return new ClickActionNode(TextNode.array(new FormattingNode(textNodes, Formatting.BLUE, Formatting.UNDERLINE)), ClickActionNode.Action.OPEN_URL, url);
return new ClickActionNode(TextNode.array(new FormattingNode(textNodes, Formatting.BLUE, Formatting.UNDERLINE)), ClickEvent.Action.OPEN_URL, url);
}

@Override
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/eu/pb4/placeholders/impl/textparser/BuiltinTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,22 @@ public static void register() {
(data) -> new KeybindNode(data.getNext("value", ""))));
}

// Broken
/*
{
TagRegistry.registerDefault(TextTag.enclosing("click", "click_action", false,
(nodes, data, parser) -> {
if (!data.isEmpty()) {
var type = data.getNext("type");
var value = data.getNext("value", "");
for (ClickEvent.Action action : ClickEvent.Action.values()) {
if (action.asString().equals(type)) {

for (var action : ClickEvent.Action.values()) {
if (action.asString().equals(type) && action.isUserDefinable()) {
return new ClickActionNode(nodes, action, parser.parseNode(value));
}
}
}
return new ParentNode(nodes);
}));
}
*/

{
TagRegistry.registerDefault(
Expand All @@ -254,7 +252,7 @@ public static void register() {
false,
(nodes, data, parser) -> {
if (!data.isEmpty()) {
return new ClickActionNode(nodes, ClickActionNode.Action.RUN_COMMAND, parser.parseNode(data.get("value", 0)));
return new ClickActionNode(nodes, ClickEvent.Action.RUN_COMMAND, parser.parseNode(data.get("value", 0)));
}
return new ParentNode(nodes);
}
Expand All @@ -272,7 +270,7 @@ public static void register() {
(nodes, data, parser) -> {

if (!data.isEmpty()) {
return new ClickActionNode(nodes, ClickActionNode.Action.SUGGEST_COMMAND, parser.parseNode(data.getNext("value", "")));
return new ClickActionNode(nodes, ClickEvent.Action.SUGGEST_COMMAND, parser.parseNode(data.getNext("value", "")));
}
return new ParentNode(nodes);
}
Expand All @@ -289,7 +287,7 @@ public static void register() {
false, (nodes, data, parser) -> {

if (!data.isEmpty()) {
return new ClickActionNode(nodes, ClickActionNode.Action.OPEN_URL, parser.parseNode(data.get("value", 0)));
return new ClickActionNode(nodes, ClickEvent.Action.OPEN_URL, parser.parseNode(data.get("value", 0)));
}
return new ParentNode(nodes);
}
Expand All @@ -307,7 +305,7 @@ public static void register() {
(nodes, data, parser) -> {

if (!data.isEmpty()) {
return new ClickActionNode(nodes, ClickActionNode.Action.COPY_TO_CLIPBOARD, parser.parseNode(data.get("value", 0)));
return new ClickActionNode(nodes, ClickEvent.Action.COPY_TO_CLIPBOARD, parser.parseNode(data.get("value", 0)));
}
return new ParentNode(nodes);
}
Expand All @@ -323,7 +321,7 @@ public static void register() {
"click_action",
true, (nodes, data, parser) -> {
if (!data.isEmpty()) {
return new ClickActionNode(nodes, ClickActionNode.Action.CHANGE_PAGE, parser.parseNode(data.get("value", 0)));
return new ClickActionNode(nodes, ClickEvent.Action.CHANGE_PAGE, parser.parseNode(data.get("value", 0)));
}
return new ParentNode(nodes);
}));
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/eu/pb4/placeholders/impl/textparser/TextTagsV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,21 @@ public static void register() {
}));
}

// Broken
/*
{
TextParserV1.registerDefault(TextParserV1.TextTag.of("click", "click_action", false, (tag, data, input, handlers, endAt) -> {
String[] lines = data.split(":", 2);
var out = recursiveParsing(input, handlers, endAt);
if (lines.length > 1) {
for (ClickEvent.Action action : ClickEvent.Action.values()) {
if (action.asString().equals(cleanArgument(lines[0]))) {
for (var action : ClickEvent.Action.values()) {
if (action.asString().equals(cleanArgument(lines[0])) && action.isUserDefinable()) {
return out.value(new ClickActionNode(out.nodes(), action, new LiteralNode(restoreOriginalEscaping(cleanArgument(lines[1])))));
}
}
}
return out.value(new ParentNode(out.nodes()));
}));
}
*/


{
TextParserV1.registerDefault(
Expand All @@ -216,7 +214,7 @@ public static void register() {
(tag, data, input, handlers, endAt) -> {
var out = recursiveParsing(input, handlers, endAt);
if (!data.isEmpty()) {
return out.value(new ClickActionNode(out.nodes(), ClickActionNode.Action.RUN_COMMAND, new LiteralNode(restoreOriginalEscaping(cleanArgument(data)))));
return out.value(new ClickActionNode(out.nodes(), ClickEvent.Action.RUN_COMMAND, new LiteralNode(restoreOriginalEscaping(cleanArgument(data)))));
}
return out.value(new ParentNode(out.nodes()));
}
Expand All @@ -234,7 +232,7 @@ public static void register() {
(tag, data, input, handlers, endAt) -> {
var out = recursiveParsing(input, handlers, endAt);
if (!data.isEmpty()) {
return out.value(new ClickActionNode(out.nodes(), ClickActionNode.Action.SUGGEST_COMMAND, new LiteralNode(restoreOriginalEscaping(cleanArgument(data)))));
return out.value(new ClickActionNode(out.nodes(), ClickEvent.Action.SUGGEST_COMMAND, new LiteralNode(restoreOriginalEscaping(cleanArgument(data)))));
}
return out.value(new ParentNode(out.nodes()));
}
Expand All @@ -251,7 +249,7 @@ public static void register() {
false, (tag, data, input, handlers, endAt) -> {
var out = recursiveParsing(input, handlers, endAt);
if (!data.isEmpty()) {
return out.value(new ClickActionNode(out.nodes(), ClickActionNode.Action.OPEN_URL, new LiteralNode(restoreOriginalEscaping(cleanArgument(data)))));
return out.value(new ClickActionNode(out.nodes(), ClickEvent.Action.OPEN_URL, new LiteralNode(restoreOriginalEscaping(cleanArgument(data)))));
}
return out.value(new ParentNode(out.nodes()));
}
Expand All @@ -269,7 +267,7 @@ public static void register() {
(tag, data, input, handlers, endAt) -> {
var out = recursiveParsing(input, handlers, endAt);
if (!data.isEmpty()) {
return out.value(new ClickActionNode(out.nodes(), ClickActionNode.Action.COPY_TO_CLIPBOARD, new LiteralNode(restoreOriginalEscaping(cleanArgument(data)))));
return out.value(new ClickActionNode(out.nodes(), ClickEvent.Action.COPY_TO_CLIPBOARD, new LiteralNode(restoreOriginalEscaping(cleanArgument(data)))));
}
return out.value(new ParentNode(out.nodes()));
}
Expand All @@ -286,7 +284,7 @@ public static void register() {
true, (tag, data, input, handlers, endAt) -> {
var out = recursiveParsing(input, handlers, endAt);
if (!data.isEmpty()) {
return out.value(new ClickActionNode(out.nodes(), ClickActionNode.Action.CHANGE_PAGE, new LiteralNode(restoreOriginalEscaping(cleanArgument(data)))));
return out.value(new ClickActionNode(out.nodes(), ClickEvent.Action.CHANGE_PAGE, new LiteralNode(restoreOriginalEscaping(cleanArgument(data)))));
}
return out.value(new ParentNode(out.nodes()));
}));
Expand Down