/
PaperElementExtensions.java
43 lines (37 loc) · 1.9 KB
/
PaperElementExtensions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.denizenscript.denizen.paper.properties;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.paper.PaperModule;
import com.denizenscript.denizen.utilities.FormattedTextHelper;
import com.denizenscript.denizencore.objects.core.ElementTag;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.chat.ComponentSerializer;
public class PaperElementExtensions {
public static void register() {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_18)) {
// <--[tag]
// @attribute <ElementTag.parse_minimessage>
// @returns ElementTag
// @Plugin Paper
// @description
// Returns the element with all MiniMessage tags parsed, see <@link url https://docs.adventure.kyori.net/minimessage/format.html> for more information.
// -->
ElementTag.tagProcessor.registerTag(ElementTag.class, "parse_minimessage", (attribute, object) -> {
return new ElementTag(PaperModule.stringifyComponent(MiniMessage.miniMessage().deserialize(object.asString())));
});
// <--[tag]
// @attribute <ElementTag.to_minimessage>
// @returns ElementTag
// @Plugin Paper
// @description
// Returns the element with all text formatting parsed into MiniMessage format.
// -->
ElementTag.tagProcessor.registerTag(ElementTag.class, "to_minimessage", (attribute, object) -> {
return new ElementTag(MiniMessage.miniMessage().serialize(
PaperModule.jsonToComponent(ComponentSerializer.toString(FormattedTextHelper.parse(object.asString(), ChatColor.WHITE, false)))
));
});
}
}
}