Skip to content

Commit

Permalink
safety for text interaction stripping
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Oct 16, 2024
1 parent 142390e commit 2d81b0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ authors=Sisby folk
contributors=Ampflower, falkreon, jaskarth, Garden System
license=LGPL-3.0-or-later
# Mod Version
baseVersion=0.6.24
baseVersion=0.6.25
# Branch Metadata
branch=1.20
tagBranch=1.20
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/folk/sisby/surveyor/util/TextUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

public class TextUtil {
public static Text stripInteraction(Text text) {
NbtCompound nbt = (NbtCompound) Codecs.TEXT.encodeStart(NbtOps.INSTANCE, text).getOrThrow(false, null);
NbtUtil.removeRecursive(nbt, List.of("hoverEvent", "clickEvent", "insertion"));
return Codecs.TEXT.decode(NbtOps.INSTANCE, nbt).getOrThrow(false, null).getFirst();
try {
NbtCompound nbt = (NbtCompound) Codecs.TEXT.encodeStart(NbtOps.INSTANCE, text).getOrThrow(true, null);
NbtUtil.removeRecursive(nbt, List.of("hoverEvent", "clickEvent", "insertion"));
return Codecs.TEXT.decode(NbtOps.INSTANCE, nbt).getOrThrow(true, null).getFirst();
} catch (Exception e) {
return Text.literal(text.getString());
}
}

public static MutableText highlightStrings(Collection<String> list, Function<String, Formatting> highlighter) {
Expand Down

0 comments on commit 2d81b0a

Please sign in to comment.