diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 4d6bd01..bc03f42 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -8,4 +8,4 @@ updates:
- package-ecosystem: "gradle"
directory: "/"
schedule:
- interval: "daily"
+ interval: "weekly"
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 75fa1fe..68f09d3 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -1,14 +1,18 @@
name: Release Drafter
on:
+ # Runs on pushes targeting the default branch
push:
- branches:
- - master
+ branches: ["master"]
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
permissions:
- contents: read
+ contents: write
pages: write
id-token: write
+ pull-requests: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
@@ -17,10 +21,7 @@ concurrency:
cancel-in-progress: false
jobs:
- build:
- permissions:
- contents: write
- pull-requests: write
+ deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
@@ -50,10 +51,42 @@ jobs:
with:
# Upload entire repository
path: 'build/dokka/html'
+ - name: Deploy to GitHub Pages
+ id: deployment
+ uses: actions/deploy-pages@v4
+
+ - name: Test with Gradle
+ run: ./gradlew test
+
+ - name: Publish test results
+ id: publish-test-results
+ uses: mikepenz/action-junit-report@v4
+ if: success() || failure()
+ with:
+ report_paths: '**/build/test-results/test/TEST-*.xml'
- uses: release-drafter/release-drafter@v5
id: release-drafter
with:
publish: false
+ footer: |
+ ## Check summary
+
+
+
+
+ | Tests 💯 |
+ Passed ✅ |
+ Skipped ⏭️ |
+ Failed ❌ |
+
+
+ JUnit Test Report |
+ ${{ steps.publish-test-results.outputs.total }} ran |
+ ${{ steps.publish-test-results.outputs.passed }} passed |
+ ${{ steps.publish-test-results.outputs.skipped }} skipped |
+ ${{ steps.publish-test-results.outputs.failed }} failed |
+
+
env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..0abc3be
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,25 @@
+name: test
+
+on: [ pull_request ]
+
+jobs:
+ check:
+ name: Check
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ - uses: actions/setup-java@v3
+ with:
+ distribution: 'temurin'
+ java-version: '17'
+ cache: 'gradle'
+ - name: Change wrapper permissions
+ run: chmod +x ./gradlew
+ - name: Test with Gradle
+ run: ./gradlew test
+ - name: Publish test results
+ uses: mikepenz/action-junit-report@v4
+ if: success() || failure()
+ with:
+ report_paths: '**/build/test-results/test/TEST-*.xml'
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index 156917e..8a04f11 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -40,8 +40,8 @@ dependencies {
val ifVersion = "0.10.11"
val junitVersion = "5.10.1"
val mockkVersion = "1.13.8"
- val mockBukkitVersion = "3.58.0"
- val sqliteVersion = "3.44.1.0"
+ val mockBukkitVersion = "3.74.0"
+ val sqliteVersion = "3.45.1.0"
val mysqlVersion = "8.0.33"
val vaultVersion = "1.7"
val protocolLibVersion = "5.2.0-SNAPSHOT"
diff --git a/src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt b/src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt
index ed0e921..aca01df 100644
--- a/src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt
+++ b/src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt
@@ -37,12 +37,12 @@ import dev.nikomaru.raceassist.data.database.BetList
import dev.nikomaru.raceassist.data.database.UserAuthData
import dev.nikomaru.raceassist.data.files.RaceUtils
import dev.nikomaru.raceassist.files.Config
+import dev.nikomaru.raceassist.files.ConfigData
import dev.nikomaru.raceassist.horse.commands.HorseDetectCommand
import dev.nikomaru.raceassist.horse.commands.OwnerDeleteCommand
import dev.nikomaru.raceassist.horse.events.HorseBreedEvent
import dev.nikomaru.raceassist.horse.events.HorseKillEvent
import dev.nikomaru.raceassist.horse.events.HorseTamedEvent
-import dev.nikomaru.raceassist.packet.event.HorsePacketSendEvent
import dev.nikomaru.raceassist.race.commands.HelpCommand
import dev.nikomaru.raceassist.race.commands.ReloadCommand
import dev.nikomaru.raceassist.race.commands.audience.AudienceJoinCommand
@@ -64,13 +64,11 @@ import dev.nikomaru.raceassist.utils.TestCommand
import dev.nikomaru.raceassist.utils.Utils
import dev.nikomaru.raceassist.utils.Utils.client
import dev.nikomaru.raceassist.utils.coroutines.async
-import dev.nikomaru.raceassist.utils.coroutines.minecraft
import dev.nikomaru.raceassist.web.WebCommand
import dev.nikomaru.raceassist.web.api.WebAPI
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.withContext
-import kotlinx.serialization.ExperimentalSerializationApi
import org.bukkit.Server
import org.bukkit.command.CommandSender
import org.jetbrains.exposed.sql.Database
@@ -88,23 +86,32 @@ open class RaceAssist : SuspendingJavaPlugin(), RaceAssistAPI, KoinComponent {
val plugin: RaceAssist by inject()
val injectServer: Server by inject()
+ val configData: ConfigData by inject()
+
+ var webServerIsStarted = false
- @OptIn(ExperimentalSerializationApi::class)
override suspend fun onEnableAsync() {
// Plugin startup logic
+ Lang.load()
+ loadResources()
+ settingWebAPI()
+ }
+
+ override fun onEnable() {
api = this
setupKoin()
- Lang.load()
Config.load()
settingDatabase()
setCommand()
- loadResources()
-// registerEvents()
- HorsePacketSendEvent()
- withContext(Dispatchers.minecraft) {
- VaultAPI.setupEconomy()
+ VaultAPI.setupEconomy()
+ }
+
+ override suspend fun onDisableAsync() {
+ // Plugin shutdown logic
+ if (webServerIsStarted) {
+ WebAPI.stopServer()
}
- settingWebAPI()
+ client.close()
}
private fun setupKoin() {
@@ -120,18 +127,24 @@ open class RaceAssist : SuspendingJavaPlugin(), RaceAssistAPI, KoinComponent {
}
fun settingWebAPI() {
- if (Config.config.webAPI != null) {
- if (Config.config.mySQL == null) {
- plugin.logger.warning("MySQLが設定されていないため、WebAPIを起動できません。")
- return
- }
- launch {
- async(Dispatchers.async) {
- WebAPI.settingServer()
- WebAPI.startServer()
- }
+ if (configData.webAPI == null) {
+ plugin.logger.warning("WebAPIが設定されていないため、WebAPIを起動できません。")
+ return
+ }
+
+ if (configData.mySQL == null) {
+ plugin.logger.warning("MySQLが設定されていないため、WebAPIを起動できません。")
+ return
+ }
+
+ webServerIsStarted = true
+ launch {
+ async(Dispatchers.async) {
+ WebAPI.settingServer()
+ WebAPI.startServer()
}
}
+
}
private suspend fun loadResources() {
@@ -148,13 +161,13 @@ open class RaceAssist : SuspendingJavaPlugin(), RaceAssistAPI, KoinComponent {
}
private fun settingDatabase() {
- if (Config.config.mySQL != null) {
+ if (configData.mySQL != null) {
Class.forName("com.mysql.cj.jdbc.Driver")
Database.connect(
- url = "jdbc:mysql://${Config.config.mySQL!!.url}",
+ url = "jdbc:mysql://${configData.mySQL!!.url}",
driver = "com.mysql.cj.jdbc.Driver",
- user = Config.config.mySQL!!.username,
- password = Config.config.mySQL!!.password,
+ user = configData.mySQL!!.username,
+ password = configData.mySQL!!.password,
)
transaction {
@@ -167,18 +180,13 @@ open class RaceAssist : SuspendingJavaPlugin(), RaceAssistAPI, KoinComponent {
)
transaction {
+
SchemaUtils.create(BetList)
}
}
}
- override fun onDisable() {
- // Plugin shutdown logic
- WebAPI.stopServer()
- client.close()
- }
-
private fun setCommand() {
val commandManager: PaperCommandManager = PaperCommandManager(
@@ -251,11 +259,12 @@ open class RaceAssist : SuspendingJavaPlugin(), RaceAssistAPI, KoinComponent {
parse(TestCommand())
}
- if (Config.config.webAPI != null) {
+ if (configData.webAPI != null) {
with(annotationParser) {
parse(WebCommand())
}
}
+ logger.info("command is registered")
}
private fun registerEvents() {
@@ -300,7 +309,7 @@ open class RaceAssist : SuspendingJavaPlugin(), RaceAssistAPI, KoinComponent {
}
override fun getWebManager(): WebManager? {
- if (Config.config.webAPI == null) return null
+ if (configData.webAPI == null) return null
return WebManager()
}
diff --git a/src/main/kotlin/dev/nikomaru/raceassist/api/core/manager/WebManager.kt b/src/main/kotlin/dev/nikomaru/raceassist/api/core/manager/WebManager.kt
index 8763a9f..482b1f3 100644
--- a/src/main/kotlin/dev/nikomaru/raceassist/api/core/manager/WebManager.kt
+++ b/src/main/kotlin/dev/nikomaru/raceassist/api/core/manager/WebManager.kt
@@ -18,15 +18,18 @@
package dev.nikomaru.raceassist.api.core.manager
import dev.nikomaru.raceassist.data.database.UserAuthData
-import dev.nikomaru.raceassist.files.Config
+import dev.nikomaru.raceassist.files.ConfigData
import dev.nikomaru.raceassist.utils.Utils.toUUID
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
+import org.koin.core.component.KoinComponent
+import org.koin.core.component.inject
import java.util.*
-class WebManager {
+class WebManager : KoinComponent {
+ val configData: ConfigData by inject()
fun getAvailable(): Boolean {
- return Config.config.webAPI != null
+ return configData.webAPI != null
}
suspend fun getRegisteredPlayers(): List {
diff --git a/src/main/kotlin/dev/nikomaru/raceassist/data/files/RaceUtils.kt b/src/main/kotlin/dev/nikomaru/raceassist/data/files/RaceUtils.kt
index c807465..fc2b421 100644
--- a/src/main/kotlin/dev/nikomaru/raceassist/data/files/RaceUtils.kt
+++ b/src/main/kotlin/dev/nikomaru/raceassist/data/files/RaceUtils.kt
@@ -37,7 +37,7 @@ import org.koin.core.component.inject
import java.util.*
object RaceUtils : KoinComponent {
- val plugin: RaceAssist by inject()
+ private val plugin: RaceAssist by inject()
fun existsRace(raceId: String): Boolean {
diff --git a/src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt b/src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt
index ba72e53..b695dc1 100644
--- a/src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt
+++ b/src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt
@@ -23,6 +23,8 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
+import org.koin.core.context.loadKoinModules
+import org.koin.dsl.module
import java.io.File
object Config : KoinComponent {
@@ -36,7 +38,10 @@ object Config : KoinComponent {
createConfig(file)
- config = json.decodeFromString(file.readText())
+ val config: ConfigData = json.decodeFromString(file.readText())
+ loadKoinModules(module {
+ single { config }
+ })
}
@OptIn(ExperimentalSerializationApi::class)
diff --git a/src/main/kotlin/dev/nikomaru/raceassist/packet/event/HorsePacketSendEvent.kt b/src/main/kotlin/dev/nikomaru/raceassist/packet/event/HorsePacketSendEvent.kt
deleted file mode 100644
index f51f8a1..0000000
--- a/src/main/kotlin/dev/nikomaru/raceassist/packet/event/HorsePacketSendEvent.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright © 2021-2024 Nikomaru
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package dev.nikomaru.raceassist.packet.event
-
-import com.comphenix.protocol.PacketType
-import com.comphenix.protocol.ProtocolManager
-import com.comphenix.protocol.events.ListenerPriority
-import com.comphenix.protocol.events.PacketAdapter
-import com.comphenix.protocol.events.PacketEvent
-import dev.nikomaru.raceassist.RaceAssist
-import org.koin.core.component.KoinComponent
-import org.koin.core.component.inject
-
-
-class HorsePacketSendEvent : KoinComponent {
- val plugin: RaceAssist by inject()
- val protocolManager: ProtocolManager by inject()
-
- init {
- protocolManager.addPacketListener(object : PacketAdapter(
- plugin,
- ListenerPriority.NORMAL,
- PacketType.Play.Server.REL_ENTITY_MOVE_LOOK
- ) {
- override fun onPacketSending(event: PacketEvent) {
-
- }
- })
-
-
- }
-}
\ No newline at end of file
diff --git a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommand.kt b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommand.kt
index b7da2ec..f101d19 100644
--- a/src/main/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommand.kt
+++ b/src/main/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommand.kt
@@ -20,10 +20,9 @@ package dev.nikomaru.raceassist.race.commands
import cloud.commandframework.annotations.CommandDescription
import cloud.commandframework.annotations.CommandMethod
import cloud.commandframework.annotations.CommandPermission
-import dev.nikomaru.raceassist.utils.Lang.mm
import org.bukkit.command.CommandSender
-@CommandMethod("ra|raceassist")
+@CommandMethod("ra")
class HelpCommand {
@CommandMethod("help")
@CommandPermission("raceassist.commands.help")
@@ -31,20 +30,7 @@ class HelpCommand {
fun help(sender: CommandSender) {
val message =
"コマンドリスト クリックで開く"
- sender.sendMessage(mm.deserialize(message))
+ sender.sendRichMessage(message)
+ return
}
-//
-// @CommandMethod("image ")
-// suspend fun createImage(sender: CommandSender,
-// @Argument(value = "x1") x1: Int,
-// @Argument(value = "x2") x2: Int,
-// @Argument(value = "y1") y1: Int,
-// @Argument(value = "y2") y2: Int) {
-// val base64 = Utils.createImage(x1, x2, y1, y2)
-//
-// File("D:\\download\\racajkghfds.txt").writeText(base64)
-// val serializedObject: ByteArray = Base64.getDecoder().decode(base64)
-// File("D:\\download\\racajkghfds.png").writeBytes(serializedObject)
-// }
-
}
\ No newline at end of file
diff --git a/src/main/kotlin/dev/nikomaru/raceassist/utils/display/LuminescenceShulker.kt b/src/main/kotlin/dev/nikomaru/raceassist/utils/display/LuminescenceShulker.kt
index f8741ae..efa44ed 100644
--- a/src/main/kotlin/dev/nikomaru/raceassist/utils/display/LuminescenceShulker.kt
+++ b/src/main/kotlin/dev/nikomaru/raceassist/utils/display/LuminescenceShulker.kt
@@ -23,7 +23,6 @@ import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.wrappers.WrappedDataValue
import com.comphenix.protocol.wrappers.WrappedDataWatcher
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject
-import dev.nikomaru.raceassist.RaceAssist
import dev.nikomaru.raceassist.utils.coroutines.async
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@@ -37,7 +36,7 @@ import kotlin.random.Random
class LuminescenceShulker : KoinComponent {
- val protocolManager: ProtocolManager by inject()
+ private val protocolManager: ProtocolManager by inject()
private val ids = arrayListOf()
diff --git a/src/test/kotlin/dev/nikomaru/raceassist/RaceAssistTest.kt b/src/test/kotlin/dev/nikomaru/raceassist/RaceAssistTest.kt
index 4b4503e..5453ee7 100644
--- a/src/test/kotlin/dev/nikomaru/raceassist/RaceAssistTest.kt
+++ b/src/test/kotlin/dev/nikomaru/raceassist/RaceAssistTest.kt
@@ -18,22 +18,19 @@
package dev.nikomaru.raceassist
import be.seeseemelk.mockbukkit.MockBukkit
-import com.comphenix.protocol.ProtocolLib
-import com.comphenix.protocol.ProtocolLibrary
-import org.bukkit.Server
+import be.seeseemelk.mockbukkit.ServerMock
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext
import org.koin.core.context.loadKoinModules
import org.koin.dsl.module
-open class RaceAssistTest : BeforeEachCallback, AfterEachCallback {
-
- private lateinit var server: Server
+class RaceAssistTest : BeforeEachCallback, AfterEachCallback {
+ private lateinit var server: ServerMock
private lateinit var plugin: RaceAssist
override fun beforeEach(context: ExtensionContext) {
- println("beforeEach() executed before " + context.displayName + ".");
+ println("beforeEach() executed before " + context.displayName + ".")
server = MockBukkit.mock()
setupKoin()
}
@@ -47,7 +44,7 @@ open class RaceAssistTest : BeforeEachCallback, AfterEachCallback {
plugin = MockBukkit.load(RaceAssist::class.java)
val appModule = module {
single { plugin }
- single { server }
+ single { server }
}
loadKoinModules(appModule)
}
diff --git a/src/test/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommandTest.kt b/src/test/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommandTest.kt
index fd14a8a..0791366 100644
--- a/src/test/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommandTest.kt
+++ b/src/test/kotlin/dev/nikomaru/raceassist/race/commands/HelpCommandTest.kt
@@ -19,6 +19,7 @@ package dev.nikomaru.raceassist.race.commands
import be.seeseemelk.mockbukkit.ServerMock
import dev.nikomaru.raceassist.RaceAssistTest
+import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
@@ -26,14 +27,19 @@ import org.koin.test.KoinTest
import org.koin.test.inject
@ExtendWith(RaceAssistTest::class)
-class HelpCommandTest : KoinTest{
- private val server : ServerMock by inject()
+class HelpCommandTest : KoinTest {
+ private val server: ServerMock by inject()
@Test
- @DisplayName("コマンドテスト: ra help")
- fun sendHelp(){
+ @DisplayName("Testing the help command")
+ fun helpCommandTest() {
val player = server.addPlayer()
- val result = player.performCommand("ra help")
- assert(result)
+ player.isOp = true
+ player.performCommand("ra help")
+ Thread.sleep(100)
+ val res = player.nextMessage()
+ println(res)
+ assertNotNull(res)
}
+
}
\ No newline at end of file