diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-08 03:42:07 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-08 03:42:07 +0100 |
commit | ef11dd51a61d25bc8722cc844358869b00a5369c (patch) | |
tree | 8545e3e1724bb08dba316dd26b0d5edd9918a6e8 /src/main/kotlin/moe/nea/ledger/NumberUtil.kt | |
parent | fa72dd4ce107190cda7bc56234fed650f20e3aa9 (diff) | |
download | LocalTransactionLedger-ef11dd51a61d25bc8722cc844358869b00a5369c.tar.gz LocalTransactionLedger-ef11dd51a61d25bc8722cc844358869b00a5369c.tar.bz2 LocalTransactionLedger-ef11dd51a61d25bc8722cc844358869b00a5369c.zip |
feat: Add query command
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/NumberUtil.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/NumberUtil.kt | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/NumberUtil.kt b/src/main/kotlin/moe/nea/ledger/NumberUtil.kt index b0e47db..008cfbf 100644 --- a/src/main/kotlin/moe/nea/ledger/NumberUtil.kt +++ b/src/main/kotlin/moe/nea/ledger/NumberUtil.kt @@ -1,5 +1,17 @@ package moe.nea.ledger +import net.minecraft.event.ClickEvent +import net.minecraft.event.HoverEvent +import net.minecraft.util.ChatComponentText +import net.minecraft.util.ChatStyle +import net.minecraft.util.EnumChatFormatting +import net.minecraft.util.IChatComponent +import java.time.Instant +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.format.DateTimeFormatter +import java.time.format.DateTimeFormatterBuilder +import java.time.temporal.ChronoField import java.util.regex.Matcher import java.util.regex.Pattern @@ -66,4 +78,32 @@ fun parseShortNumber(string: String): Double { inline fun <T> Pattern.useMatcher(string: String, block: Matcher.() -> T): T? = matcher(string).takeIf { it.matches() }?.let(block) -fun String.unformattedString(): String = replace("§.".toRegex(), "")
\ No newline at end of file +fun String.unformattedString(): String = replace("§.".toRegex(), "") + +val timeFormat: DateTimeFormatter = DateTimeFormatterBuilder() + .appendValue(ChronoField.DAY_OF_MONTH, 2) + .appendLiteral(".") + .appendValue(ChronoField.MONTH_OF_YEAR, 2) + .appendLiteral(".") + .appendValue(ChronoField.YEAR, 4) + .appendLiteral(" ") + .appendValue(ChronoField.HOUR_OF_DAY, 2) + .appendLiteral(":") + .appendValue(ChronoField.MINUTE_OF_HOUR, 2) + .appendLiteral(":") + .appendValue(ChronoField.SECOND_OF_MINUTE, 2) + .toFormatter() + +fun Instant.formatChat(): IChatComponent { + val text = ChatComponentText( + LocalDateTime.ofInstant(this, ZoneId.systemDefault()).format(timeFormat) + ) + text.setChatStyle( + ChatStyle() + .setChatClickEvent( + ClickEvent(ClickEvent.Action.OPEN_URL, "https://time.is/${this.epochSecond}")) + .setChatHoverEvent( + HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("Click to show on time.is"))) + .setColor(EnumChatFormatting.AQUA)) + return text +} |