Skip to content

Commit

Permalink
Merge pull request #52 from RaceAssist/web-support
Browse files Browse the repository at this point in the history
Add test method.
  • Loading branch information
Nlkomaru authored Jan 13, 2024
2 parents cceb149 + 85c6e9e commit 9cd0d0e
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ updates:
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
31 changes: 30 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,38 @@ jobs:
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
<table>
<tr>
<th>
<th>Tests 💯</th>
<th>Passed ✅</th>
<th>Skipped ⏭️</th>
<th>Failed ❌</th>
</tr>
<tr>
<td>JUnit Test Report</td>
<td>${{ steps.publish-test-results.outputs.total }} ran</td>
<td>${{ steps.publish-test-results.outputs.passed }} passed</td>
<td>${{ steps.publish-test-results.outputs.skipped }} skipped</td>
<td>${{ steps.publish-test-results.outputs.failed }} failed</td>
</tr>
</table>
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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'
75 changes: 42 additions & 33 deletions src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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 {
Expand All @@ -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<CommandSender> = PaperCommandManager(
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,17 @@ 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")
@CommandDescription("help command")
fun help(sender: CommandSender) {
val message =
"<click:open_url:'https://github.com/Nlkomaru/RaceAssist-core/wiki/Command'><green>コマンドリスト クリックで開く</green></click>"
sender.sendMessage(mm.deserialize(message))
sender.sendRichMessage(message)
return
}
//
// @CommandMethod("image <x1> <x2> <y1> <y2>")
// 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)
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Int>()

Expand Down
Loading

0 comments on commit 9cd0d0e

Please sign in to comment.