Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/gradle/cloudVersion-1.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Nlkomaru authored Mar 15, 2024
2 parents 2795cf2 + 7cc6fa1 commit dc8327c
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 129 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"
49 changes: 41 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 }}
Expand Down Expand Up @@ -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
<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'
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
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.

Loading

0 comments on commit dc8327c

Please sign in to comment.