Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ElementTag.parse/to_minimessage
tags (#2391)
* WIP MiniMessage tags * No need for a dedicated method * MiniMessage was only added to Paper on 1.18 * Link MiniMessage docs
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperElementExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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))) | ||
)); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters