diff --git a/build.gradle.kts b/build.gradle.kts index 49d8353..81cbb58 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,36 +1,38 @@ +import io.izzel.taboolib.gradle.* + plugins { `java-library` `maven-publish` - id("io.izzel.taboolib") version "1.56" - id("org.jetbrains.kotlin.jvm") version "1.7.21" + id("io.izzel.taboolib") version "2.0.11" + id("org.jetbrains.kotlin.jvm") version "1.8.22" } taboolib { - install("common") - install("common-5") - install("module-configuration") - install("module-database") - install("platform-velocity") - install("expansion-command-helper") - classifier = null - version = "6.0.10-114" + env { + install(UNIVERSAL, VELOCITY) + install( + DATABASE, + CONFIGURATION + ) + + version { + taboolib = "6.1.1-beta17" + } + } } repositories { mavenLocal() - maven { - url = uri("https://papermc.io/repo/repository/maven-public/") - } - maven { - url = uri("https://jitpack.io") - } mavenCentral() + maven("https://papermc.io/repo/repository/maven-public/") + maven("https://jitpack.io") } dependencies { compileOnly("com.velocitypowered:velocity-api:3.1.1") compileOnly("mysql:mysql-connector-java:8.0.30") compileOnly("net.kyori:adventure-text-minimessage:4.12.0") + compileOnly(kotlin("stdlib")) compileOnly(fileTree("libs")) } diff --git a/src/main/java/me/xiaozhangup/picturelogin/PictureUtil.java b/src/main/java/me/xiaozhangup/picturelogin/PictureUtil.java index 0a40508..59b1681 100644 --- a/src/main/java/me/xiaozhangup/picturelogin/PictureUtil.java +++ b/src/main/java/me/xiaozhangup/picturelogin/PictureUtil.java @@ -113,18 +113,18 @@ public ImageMessage getMessage(List messages, BufferedImage image, Playe .replace("%player_name%", player.getUsername()) .replace("%online%", String.valueOf(PictureLoginJava.server.getPlayerCount())); - int note = DatabaseManager.getTableNote().getByTo(player.getUniqueId().toString()); + int note = DatabaseManager.getTableMailbox().byReceiver(player.getUniqueId(), MailType.NOTE); if (note > 0) { - message = message.replace("%note%", "单击阅读'>单击阅读 " + note + " 条留言"); + message = message.replace("%note%", "单击阅读'>单击阅读 " + note + " 件信封"); } else { - message = message.replace("%note%", "没有未读的留言"); + message = message.replace("%note%", "没有未读的信封"); } - int mail = DatabaseManager.getTableMail().getByTo(player.getUniqueId().toString()); + int mail = DatabaseManager.getTableMailbox().byReceiver(player.getUniqueId(), MailType.MAIL); if (mail > 0) { - message = message.replace("%mail%", "单击查收'>单击查收 " + mail + " 条邮件"); + message = message.replace("%mail%", "单击查收'>单击查收 " + mail + " 件包裹"); } else { - message = message.replace("%mail%", "没有未读的邮件"); + message = message.replace("%mail%", "没有未收的包裹"); } msg[count++] = MiniMessage.miniMessage().deserialize(message); diff --git a/src/main/kotlin/me/xiaozhangup/picturelogin/MailType.kt b/src/main/kotlin/me/xiaozhangup/picturelogin/MailType.kt new file mode 100644 index 0000000..7a54b70 --- /dev/null +++ b/src/main/kotlin/me/xiaozhangup/picturelogin/MailType.kt @@ -0,0 +1,9 @@ +package me.xiaozhangup.picturelogin + +enum class MailType( + val display: String +) { + MAIL("包裹"), + NOTE("信封"), + RICH("邮件") +} \ No newline at end of file diff --git a/src/main/kotlin/me/xiaozhangup/picturelogin/data/DatabaseManager.kt b/src/main/kotlin/me/xiaozhangup/picturelogin/data/DatabaseManager.kt index aec44f4..46c8a76 100644 --- a/src/main/kotlin/me/xiaozhangup/picturelogin/data/DatabaseManager.kt +++ b/src/main/kotlin/me/xiaozhangup/picturelogin/data/DatabaseManager.kt @@ -1,8 +1,7 @@ package me.xiaozhangup.picturelogin.data import me.xiaozhangup.picturelogin.PictureLogin -import me.xiaozhangup.picturelogin.data.table.TableMail -import me.xiaozhangup.picturelogin.data.table.TableNote +import me.xiaozhangup.picturelogin.data.table.TableMailbox import taboolib.common.LifeCycle import taboolib.common.platform.Awake import taboolib.common.platform.SkipTo @@ -18,11 +17,7 @@ object DatabaseManager { private set @JvmStatic - lateinit var tableNote: TableNote - private set - - @JvmStatic - lateinit var tableMail: TableMail + lateinit var tableMailbox: TableMailbox private set private val databaseConfig: taboolib.library.configuration.ConfigurationSection by lazy { @@ -36,8 +31,7 @@ object DatabaseManager { host = HostSQL(databaseConfig) dataSource = host.createDataSource() - tableNote = TableNote().apply { createTable() } - tableMail = TableMail().apply { createTable() } + tableMailbox = TableMailbox().apply { createTable() } } } \ No newline at end of file diff --git a/src/main/kotlin/me/xiaozhangup/picturelogin/data/table/TableMail.kt b/src/main/kotlin/me/xiaozhangup/picturelogin/data/table/TableMail.kt deleted file mode 100644 index e285ba4..0000000 --- a/src/main/kotlin/me/xiaozhangup/picturelogin/data/table/TableMail.kt +++ /dev/null @@ -1,54 +0,0 @@ -package me.xiaozhangup.picturelogin.data.table - -import me.xiaozhangup.picturelogin.data.DatabaseManager -import me.xiaozhangup.picturelogin.data.DatabaseManager.dataSource -import me.xiaozhangup.picturelogin.data.table.SQLTable -import taboolib.module.database.* - -class TableMail : SQLTable { - - override val table: Table, SQL> = Table("mail_mail", DatabaseManager.host) { - add("id") { - type(ColumnTypeSQL.VARCHAR, 36) { - options(ColumnOptionSQL.KEY) - } - } - - add("from") { - type(ColumnTypeSQL.VARCHAR, 36) { - options(ColumnOptionSQL.KEY) - } - } - - add("to") { - type(ColumnTypeSQL.VARCHAR, 36) { - options(ColumnOptionSQL.KEY) - } - } - - add("mail") { - type(ColumnTypeSQL.TEXT) - } - } - - fun getByFrom(uuid: String): Int { - var n = 0 - table.select(dataSource) { - where("from" eq uuid) - }.forEach { - n++ - } - return n - } - - fun getByTo(uuid: String): Int { - var n = 0 - table.select(dataSource) { - where("to" eq uuid) - }.forEach { - n++ - } - return n - } - -} \ No newline at end of file diff --git a/src/main/kotlin/me/xiaozhangup/picturelogin/data/table/TableMailbox.kt b/src/main/kotlin/me/xiaozhangup/picturelogin/data/table/TableMailbox.kt new file mode 100644 index 0000000..40e8cce --- /dev/null +++ b/src/main/kotlin/me/xiaozhangup/picturelogin/data/table/TableMailbox.kt @@ -0,0 +1,56 @@ +package me.xiaozhangup.picturelogin.data.table + +import me.xiaozhangup.picturelogin.MailType +import me.xiaozhangup.picturelogin.data.DatabaseManager +import me.xiaozhangup.picturelogin.data.DatabaseManager.dataSource +import taboolib.module.database.* +import java.util.* + +class TableMailbox : SQLTable { + + override val table: Table, SQL> = Table("mailbox", DatabaseManager.host) { + add("uuid") { + type(ColumnTypeSQL.VARCHAR, 36) { + options(ColumnOptionSQL.KEY) + } + } + + add("type") { + type(ColumnTypeSQL.TINYTEXT) + } + + add("title") { + type(ColumnTypeSQL.TINYTEXT) + } + + add("sender") { + type(ColumnTypeSQL.VARCHAR, 36) + } + + add("receiver") { + type(ColumnTypeSQL.VARCHAR, 36) + } + + add("context") { + type(ColumnTypeSQL.TEXT) + } + } + + fun bySender(sender: UUID, type: MailType? = null): Int { + return table.select(dataSource) { + where { + "sender" eq sender.toString() + if (type != null) "type" eq type.name + } + }.map { }.size + } + + fun byReceiver(receiver: UUID, type: MailType? = null): Int { + return table.select(dataSource) { + where { + "receiver" eq receiver.toString() + if (type != null) "type" eq type.name + } + }.map { }.size + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/xiaozhangup/picturelogin/data/table/TableNote.kt b/src/main/kotlin/me/xiaozhangup/picturelogin/data/table/TableNote.kt deleted file mode 100644 index 15075eb..0000000 --- a/src/main/kotlin/me/xiaozhangup/picturelogin/data/table/TableNote.kt +++ /dev/null @@ -1,51 +0,0 @@ -package me.xiaozhangup.picturelogin.data.table - -import me.xiaozhangup.picturelogin.data.DatabaseManager -import me.xiaozhangup.picturelogin.data.DatabaseManager.dataSource -import taboolib.common.util.asList -import taboolib.module.database.* - -class TableNote : SQLTable { - - override val table: Table, SQL> = Table("mail_note", DatabaseManager.host) { - add("id") { - type(ColumnTypeSQL.VARCHAR, 36) { - options(ColumnOptionSQL.KEY) - } - } - - add("from") { - type(ColumnTypeSQL.VARCHAR, 36) - } - - add("to") { - type(ColumnTypeSQL.VARCHAR, 36) - } - - add("note") { - type(ColumnTypeSQL.TEXT) - } - } - - - fun getByFrom(uuid: String): Int { - var n = 0 - table.select(dataSource) { - where("from" eq uuid) - }.forEach { - n++ - } - return n - } - - fun getByTo(uuid: String): Int { - var n = 0 - table.select(dataSource) { - where("to" eq uuid) - }.forEach { - n++ - } - return n - } - -} \ No newline at end of file