Skip to content

Commit 7453153

Browse files
committed
(breaking) Use MiniMessage instead of legacy section/ampersand character
1 parent 8f807c1 commit 7453153

File tree

21 files changed

+434
-395
lines changed

21 files changed

+434
-395
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = "net.azisaba.spicyazisaban"
11-
version = "1.0.0-${getBranch()}-${getGitHash()}${if (hasUncommittedChanges()) "-debug" else ""}"
11+
version = "2.0.0-${getBranch()}-${getGitHash()}${if (hasUncommittedChanges()) "-debug" else ""}"
1212

1313
java {
1414
toolchain.languageVersion.set(JavaLanguageVersion.of(17))

bungee/src/main/kotlin/net/azisaba/spicyAzisaBan/bungee/SpicyAzisaBanBungee.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import net.azisaba.spicyAzisaBan.common.ServerInfo
1010
import net.azisaba.spicyAzisaBan.common.chat.Component
1111
import net.azisaba.spicyAzisaBan.common.command.Command
1212
import net.azisaba.spicyAzisaBan.common.scheduler.ScheduledTask
13+
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
1314
import net.md_5.bungee.api.ProxyServer
1415
import net.md_5.bungee.api.chat.TextComponent
1516
import java.io.File
@@ -64,4 +65,14 @@ class SpicyAzisaBanBungee: SpicyAzisaBan() {
6465
override fun getConsoleActor(): Actor = BungeeActor(server.console)
6566

6667
override fun getDataFolder(): Path = File("./plugins/SpicyAzisaBan").toPath()
68+
69+
override fun convertComponent(component: net.kyori.adventure.text.Component): Component {
70+
return LegacyComponentSerializer.builder()
71+
.character('§')
72+
.useUnusualXRepeatedCharacterHexFormat()
73+
.build()
74+
.serialize(component)
75+
.let { TextComponent.fromLegacyText(it) }
76+
.let { TextComponent(*it).toCommon() }
77+
}
6778
}

cli/src/main/kotlin/net/azisaba/spicyAzisaBan/cli/SpicyAzisaBanCLI.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import net.azisaba.spicyAzisaBan.common.ServerInfo
1010
import net.azisaba.spicyAzisaBan.common.chat.Component
1111
import net.azisaba.spicyAzisaBan.common.command.Command
1212
import net.azisaba.spicyAzisaBan.common.scheduler.ScheduledTask
13+
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
1314
import java.io.File
1415
import java.io.OutputStream
1516
import java.nio.file.Path
@@ -66,4 +67,12 @@ class SpicyAzisaBanCLI: SpicyAzisaBan() {
6667
override fun executeCommand(actor: Actor, command: String) = throw AssertionError("Cannot execute command on CLI")
6768
override fun getConsoleActor(): Actor = CLIActor
6869
override fun getDataFolder(): Path = File(".").toPath()
69-
}
70+
71+
override fun convertComponent(component: net.kyori.adventure.text.Component): Component {
72+
return LegacyComponentSerializer.builder()
73+
.character('§')
74+
.build()
75+
.serialize(component)
76+
.let { SimpleComponent.fromLegacyText(it) }
77+
}
78+
}

common/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ dependencies {
1818
}
1919
api("org.ow2.asm:asm:9.7.1")
2020
api("org.ow2.asm:asm-commons:9.7.1")
21+
api("net.kyori:adventure-text-minimessage:4.17.0")
22+
api("net.kyori:adventure-text-serializer-legacy:4.17.0")
2123
compileOnlyApi("org.mariadb.jdbc:mariadb-java-client:3.5.0")
2224
}

common/src/main/kotlin/net/azisaba/spicyAzisaBan/SABMessages.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package net.azisaba.spicyAzisaBan
22

3-
import net.azisaba.spicyAzisaBan.common.ChatColor
43
import net.azisaba.spicyAzisaBan.util.Util
4+
import net.azisaba.spicyAzisaBan.util.Util.toLegacySectionText
55
import net.azisaba.spicyAzisaBan.util.Util.translate
66
import util.yaml.YamlConfiguration
77
import util.yaml.YamlObject
@@ -35,14 +35,14 @@ object SABMessages {
3535
fun YamlObject.getMessage(key: String, def: String = "<key: $key>"): String {
3636
val raw = this.rawData[key] ?: def
3737
if (raw is String) return raw
38-
return this.getArray(key)?.mapNotNull { o -> o?.toString() }?.joinToString("${ChatColor.RESET}\n") ?: def
38+
return this.getArray(key)?.mapNotNull { o -> o?.toString() }?.joinToString("<reset>\n") ?: def
3939
}
4040

4141
/**
4242
* Replaces the variables (%KEY_IN_UPPERCASE%) in string with value.
4343
*/
4444
fun String.replaceVariables(variables: Map<String, String> = mapOf()): String {
45-
var s = replace("%PREFIX%", SpicyAzisaBan.PREFIX)
45+
var s = replace("%PREFIX%", General.prefix)
4646
.replace("%CMD_PREFIX%", SABConfig.prefix)
4747
variables.forEach { (key, value) -> s = s.replace("%${key.uppercase()}%", value) }
4848
return s
@@ -79,6 +79,7 @@ object SABMessages {
7979
"millis" to Util.zero(3, c[Calendar.MILLISECOND]),
8080
)
8181
.translate()
82+
.toLegacySectionText()
8283
}
8384

8485
object General {

common/src/main/kotlin/net/azisaba/spicyAzisaBan/SpicyAzisaBan.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import net.azisaba.spicyAzisaBan.sql.migrations.DatabaseMigration
5151
import net.azisaba.spicyAzisaBan.struct.EventType
5252
import net.azisaba.spicyAzisaBan.util.TimerTasks
5353
import net.azisaba.spicyAzisaBan.util.Util
54+
import net.azisaba.spicyAzisaBan.util.Util.toLegacySectionText
5455
import net.azisaba.spicyAzisaBan.util.Util.translate
5556
import util.promise.rewrite.Promise
5657
import xyz.acrylicstyle.sql.options.FindOptions
@@ -105,7 +106,7 @@ abstract class SpicyAzisaBan {
105106
if (wasInitialized) error("Cannot construct SpicyAzisaBan more than once")
106107
wasInitialized = true
107108
instance = this
108-
PREFIX = SABMessages.General.prefix.translate()
109+
PREFIX = SABMessages.General.prefix.translate().toLegacySectionText()
109110
}
110111

111112
private fun initDatabase() {
@@ -220,6 +221,7 @@ abstract class SpicyAzisaBan {
220221
abstract fun executeCommand(actor: Actor, command: String)
221222
abstract fun getConsoleActor(): Actor
222223
abstract fun getDataFolder(): Path
224+
abstract fun convertComponent(component: net.kyori.adventure.text.Component): Component
223225

224226
class Settings {
225227

common/src/main/kotlin/net/azisaba/spicyAzisaBan/commands/BanListCommand.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import net.azisaba.spicyAzisaBan.common.command.Command
1313
import net.azisaba.spicyAzisaBan.punishment.Punishment
1414
import net.azisaba.spicyAzisaBan.punishment.PunishmentType
1515
import net.azisaba.spicyAzisaBan.util.Util.async
16+
import net.azisaba.spicyAzisaBan.util.Util.convert
1617
import net.azisaba.spicyAzisaBan.util.Util.filterArgKeys
1718
import net.azisaba.spicyAzisaBan.util.Util.filtr
1819
import net.azisaba.spicyAzisaBan.util.Util.send
@@ -103,13 +104,13 @@ object BanListCommand: Command() {
103104
val backText = Component.text("${if (newPage > 1) newPage - 1 else "-"} << ", ChatColor.GRAY)
104105
if (newPage > 1) {
105106
backText.setColor(ChatColor.YELLOW)
106-
backText.setHoverEvent(HoverEvent.Action.SHOW_TEXT, Component.fromLegacyText(SABMessages.General.previousPage.translate()))
107+
backText.setHoverEvent(HoverEvent.Action.SHOW_TEXT, arrayOf(SABMessages.General.previousPage.translate().convert()))
107108
backText.setClickEvent(ClickEvent.Action.RUN_COMMAND, "/${SABConfig.prefix}banlist page=${newPage - 1} ${if (active) "--active" else ""} ${if (all) "--all" else ""} ${if (server != null) "server=\"$server\"" else ""} ${if (punishmentType != null) "type=${punishmentType.name}" else ""}")
108109
}
109110
val nextText = Component.text(" >> ${if (newPage < maxPage) newPage + 1 else "-"}", ChatColor.GRAY)
110111
if (newPage < maxPage) {
111112
nextText.setColor(ChatColor.YELLOW)
112-
nextText.setHoverEvent(HoverEvent.Action.SHOW_TEXT, Component.fromLegacyText(SABMessages.General.nextPage.translate()))
113+
nextText.setHoverEvent(HoverEvent.Action.SHOW_TEXT, arrayOf(SABMessages.General.nextPage.translate().convert()))
113114
nextText.setClickEvent(ClickEvent.Action.RUN_COMMAND, "/${SABConfig.prefix}banlist page=${newPage + 1} ${if (active) "--active" else ""} ${if (all) "--all" else ""} ${if (server != null) "server=\"$server\"" else ""} ${if (punishmentType != null) "type=${punishmentType.name}" else ""}")
114115
}
115116
text.addChildren(backText)

common/src/main/kotlin/net/azisaba/spicyAzisaBan/commands/CheckCommand.kt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import net.azisaba.spicyAzisaBan.SABMessages
55
import net.azisaba.spicyAzisaBan.SABMessages.replaceVariables
66
import net.azisaba.spicyAzisaBan.SpicyAzisaBan
77
import net.azisaba.spicyAzisaBan.common.Actor
8-
import net.azisaba.spicyAzisaBan.common.ChatColor
98
import net.azisaba.spicyAzisaBan.common.command.Command
109
import net.azisaba.spicyAzisaBan.punishment.Punishment
1110
import net.azisaba.spicyAzisaBan.punishment.PunishmentType
@@ -15,9 +14,9 @@ import net.azisaba.spicyAzisaBan.util.Util.async
1514
import net.azisaba.spicyAzisaBan.util.Util.filterArgKeys
1615
import net.azisaba.spicyAzisaBan.util.Util.filtr
1716
import net.azisaba.spicyAzisaBan.util.Util.isValidIPAddress
18-
import net.azisaba.spicyAzisaBan.util.Util.plus
1917
import net.azisaba.spicyAzisaBan.util.Util.send
2018
import net.azisaba.spicyAzisaBan.util.Util.sendErrorMessage
19+
import net.azisaba.spicyAzisaBan.util.Util.toMiniMessage
2120
import net.azisaba.spicyAzisaBan.util.Util.translate
2221
import net.azisaba.spicyAzisaBan.util.contexts.Contexts
2322
import net.azisaba.spicyAzisaBan.util.contexts.IPAddressContext
@@ -51,7 +50,7 @@ object CheckCommand: Command() {
5150
if (pid != null) {
5251
Punishment.fetchPunishmentById(pid).thenDo { p ->
5352
if (p == null) {
54-
return@thenDo actor.send(SABMessages.Commands.General.punishmentNotFound.replaceVariables().translate().format(pid))
53+
return@thenDo actor.send(SABMessages.Commands.General.punishmentNotFound.replaceVariables().format(pid).translate())
5554
}
5655
actor.send(p.getHistoryMessage().complete())
5756
}
@@ -141,14 +140,14 @@ object CheckCommand: Command() {
141140
.replaceVariables(
142141
"ip" to ip,
143142
"hostname" to InetAddress.getByName(ip).hostName,
144-
"mute_count" to (if (muteCount == 0) ChatColor.GREEN else ChatColor.RED) + muteCount.toString(),
145-
"ban_count" to (if (banCount == 0) ChatColor.GREEN else ChatColor.RED) + banCount.toString(),
146-
"warning_count" to (if (warningCount == 0) ChatColor.GREEN else ChatColor.RED) + warningCount.toString(),
147-
"caution_count" to (if (cautionCount == 0) ChatColor.GREEN else ChatColor.RED) + cautionCount.toString(),
143+
"mute_count" to (if (muteCount == 0) "<green>" else "<red>") + muteCount.toString(),
144+
"ban_count" to (if (banCount == 0) "<green>" else "<red>") + banCount.toString(),
145+
"warning_count" to (if (warningCount == 0) "<green>" else "<red>") + warningCount.toString(),
146+
"caution_count" to (if (cautionCount == 0) "<green>" else "<red>") + cautionCount.toString(),
148147
"kick_count" to kickCount.toString(),
149148
"note_count" to noteCount.toString(),
150-
"ban_info" to banInfo,
151-
"mute_info" to muteInfo,
149+
"ban_info" to banInfo.toMiniMessage(),
150+
"mute_info" to muteInfo.toMiniMessage(),
152151
)
153152
.translate()
154153
)
@@ -211,14 +210,14 @@ object CheckCommand: Command() {
211210
"uuid" to pd.uniqueId.toString(),
212211
"ip" to pd.ip.toString(),
213212
"hostname" to pd.ip?.let { InetAddress.getByName(it).hostName }.toString(),
214-
"mute_count" to (if (muteCount == 0) ChatColor.GREEN else ChatColor.RED) + muteCount.toString(),
215-
"ban_count" to (if (banCount == 0) ChatColor.GREEN else ChatColor.RED) + banCount.toString(),
216-
"warning_count" to (if (warningCount == 0) ChatColor.GREEN else ChatColor.RED) + warningCount.toString(),
217-
"caution_count" to (if (cautionCount == 0) ChatColor.GREEN else ChatColor.RED) + cautionCount.toString(),
213+
"mute_count" to (if (muteCount == 0) "<green>" else "<red>") + muteCount.toString(),
214+
"ban_count" to (if (banCount == 0) "<green>" else "<red>") + banCount.toString(),
215+
"warning_count" to (if (warningCount == 0) "<green>" else "<red>") + warningCount.toString(),
216+
"caution_count" to (if (cautionCount == 0) "<green>" else "<red>") + cautionCount.toString(),
218217
"kick_count" to kickCount.toString(),
219218
"note_count" to noteCount.toString(),
220-
"ban_info" to banInfo,
221-
"mute_info" to muteInfo,
219+
"ban_info" to banInfo.toMiniMessage(),
220+
"mute_info" to muteInfo.toMiniMessage(),
222221
)
223222
.translate()
224223
)

common/src/main/kotlin/net/azisaba/spicyAzisaBan/commands/HistoryCommand.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import net.azisaba.spicyAzisaBan.punishment.Punishment
1414
import net.azisaba.spicyAzisaBan.sql.SQLConnection
1515
import net.azisaba.spicyAzisaBan.struct.PlayerData
1616
import net.azisaba.spicyAzisaBan.util.Util.async
17+
import net.azisaba.spicyAzisaBan.util.Util.convert
1718
import net.azisaba.spicyAzisaBan.util.Util.filterArgKeys
1819
import net.azisaba.spicyAzisaBan.util.Util.filtr
1920
import net.azisaba.spicyAzisaBan.util.Util.isValidIPAddress
@@ -177,15 +178,15 @@ object HistoryCommand: Command() {
177178
val backText = Component.text("${if (page > 1) page - 1 else "-"} << ")
178179
if (page > 1) {
179180
backText.setColor(ChatColor.YELLOW)
180-
backText.setHoverEvent(HoverEvent.Action.SHOW_TEXT, Component.fromLegacyText(SABMessages.General.previousPage.translate()))
181+
backText.setHoverEvent(HoverEvent.Action.SHOW_TEXT, arrayOf(SABMessages.General.previousPage.translate().convert()))
181182
backText.setClickEvent(ClickEvent.Action.RUN_COMMAND, "/${SABConfig.prefix}history target=$target page=${page - 1} ${if (active) "--active" else ""} ${if (all) "--all" else ""} ${if (ipOpt) "-i" else ""} ${if (only) "-o" else ""}")
182183
} else {
183184
backText.setColor(ChatColor.GRAY)
184185
}
185186
val nextText = Component.text(" >> ${if (page < maxPage) page + 1 else "-"}")
186187
if (page < maxPage) {
187188
nextText.setColor(ChatColor.YELLOW)
188-
nextText.setHoverEvent(HoverEvent.Action.SHOW_TEXT, Component.fromLegacyText(SABMessages.General.nextPage.translate()))
189+
nextText.setHoverEvent(HoverEvent.Action.SHOW_TEXT, arrayOf(SABMessages.General.nextPage.translate().convert()))
189190
nextText.setClickEvent(ClickEvent.Action.RUN_COMMAND, "/${SABConfig.prefix}history target=$target page=${page + 1} ${if (active) "--active" else ""} ${if (all) "--all" else ""} ${if (ipOpt) "-i" else ""} ${if (only) "-o" else ""}")
190191
} else {
191192
nextText.setColor(ChatColor.GRAY)

common/src/main/kotlin/net/azisaba/spicyAzisaBan/commands/SABCommand.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object SABCommand: Command() {
5454
private val groupRemoveConfirmation = mutableMapOf<UUID, String>()
5555

5656
private fun Actor.sendHelp() {
57-
send("$PREFIX${ChatColor.GREEN}SpicyAzisaBan commands")
57+
send("$PREFIX<green>SpicyAzisaBan commands".translate())
5858
if (hasPermission("sab.command.spicyazisaban.group")) send("${ChatColor.RED}> ${ChatColor.AQUA}/sab group <group>")
5959
if (hasPermission("sab.command.spicyazisaban.info")) send("${ChatColor.RED}> ${ChatColor.AQUA}/sab info")
6060
if (hasPermission("sab.command.spicyazisaban.creategroup")) send("${ChatColor.RED}> ${ChatColor.AQUA}/sab creategroup <group>")
@@ -166,7 +166,7 @@ object SABCommand: Command() {
166166
SpicyAzisaBan.instance.connection.punishmentHistory
167167
.delete(FindOptions.Builder().addWhere("id", id).build())
168168
.then { list ->
169-
if (list.isEmpty()) return@then actor.send(SABMessages.Commands.General.punishmentNotFound.replaceVariables().translate().format(id))
169+
if (list.isEmpty()) return@then actor.send(SABMessages.Commands.General.punishmentNotFound.replaceVariables().format(id).translate())
170170
val v = Punishment.fromTableData(list[0]).getVariables().complete()
171171
actor.send(SABMessages.Commands.Sab.removedFromPunishmentHistory.replaceVariables(v).translate())
172172
}
@@ -181,7 +181,7 @@ object SABCommand: Command() {
181181
SpicyAzisaBan.instance.connection.punishments
182182
.delete(FindOptions.Builder().addWhere("id", id).build())
183183
.then { list ->
184-
if (list.isEmpty()) return@then actor.send(SABMessages.Commands.General.punishmentNotFound.replaceVariables().translate().format(id))
184+
if (list.isEmpty()) return@then actor.send(SABMessages.Commands.General.punishmentNotFound.replaceVariables().format(id).translate())
185185
val v = Punishment.fromTableData(list[0]).getVariables().complete()
186186
actor.send(SABMessages.Commands.Sab.removedFromPunishment.replaceVariables(v).translate())
187187
}

0 commit comments

Comments
 (0)