Skip to content

Commit

Permalink
updated AstraLibs to 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
makeevrserg committed Jan 14, 2023
1 parent 72bd7e3 commit 8c90e7e
Show file tree
Hide file tree
Showing 25 changed files with 97 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}
withType<Jar> {
archiveClassifier.set("min")
}
compileJava {
options.encoding = "UTF-8"
}
test {
useJUnit()
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
this.showStandardStreams = true
Expand Down
1 change: 1 addition & 0 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation(libs.kotlin.serializationKaml)
// AstraLibs
implementation(libs.astralibs.ktxCore)
implementation(libs.astralibs.orm)
// Test
testImplementation(kotlin("test"))
testImplementation(libs.orgTesting)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.astrainteractive.astratemplate.domain

import com.astrainteractive.astratemplate.domain.local.dto.RatingDTO
import com.astrainteractive.astratemplate.domain.local.dto.UserDTO
import com.astrainteractive.astratemplate.domain.local.dto.mapping.UserMapper
import com.astrainteractive.astratemplate.domain.local.entities.RatingRelationTable
import com.astrainteractive.astratemplate.domain.local.entities.User
import com.astrainteractive.astratemplate.domain.local.entities.UserRating
import com.astrainteractive.astratemplate.domain.local.entities.UserTable
import com.astrainteractive.astratemplate.domain.remote.RestApi
import ru.astrainteractive.astralibs.database_v2.Database
import ru.astrainteractive.astralibs.orm.Database
import java.util.*
import kotlin.random.Random

Expand Down Expand Up @@ -39,13 +38,13 @@ class Repository(
}

suspend fun selectRating(user: UserDTO): List<UserRating>? {
return RatingRelationTable.find(databaseDataSource, ::UserRating) {
return RatingRelationTable.find(databaseDataSource, UserRating) {
RatingRelationTable.userID.eq(user.id)
}
}

suspend fun updateUser(user: UserDTO) {
UserTable.find(constructor = ::User) {
UserTable.find(constructor = User) {
UserTable.id.eq(user.id)
}.firstOrNull()?.apply {
this.minecraftUuid = user.minecraftUUID
Expand All @@ -64,7 +63,7 @@ class Repository(
* Same as [createUserTable]
*/
suspend fun getAllUsers(): List<UserDTO>? {
return UserTable.all(databaseDataSource, ::User).map(UserMapper::toDTO)
return UserTable.all(databaseDataSource, User).map(UserMapper::toDTO)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ru.astrainteractive.astralibs.domain.mapping.IMapper
interface IRatingMapper : IMapper<UserRating, RatingDTO>
object RatingMapper : IRatingMapper {
override fun fromDTO(it: RatingDTO): UserRating {
return RatingRelationTable.find(constructor = ::UserRating) {
return RatingRelationTable.find(constructor = UserRating) {
RatingRelationTable.id.eq(it.id)
}.firstOrNull()!!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IUserMapper : IMapper<User, UserDTO>

object UserMapper : IUserMapper {
override fun fromDTO(it: UserDTO): User {
return UserTable.find(constructor = ::User) {
return UserTable.find(constructor = User) {
UserTable.id.eq(it.id)
}.firstOrNull()!!
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.astrainteractive.astratemplate.domain.local.entities

import ru.astrainteractive.astralibs.database.ColumnInfo
import ru.astrainteractive.astralibs.database.Entity
import ru.astrainteractive.astralibs.database.PrimaryKey
import ru.astrainteractive.astralibs.database_v2.Column
import ru.astrainteractive.astralibs.database_v2.Table
import ru.astrainteractive.astralibs.orm.database.Column
import ru.astrainteractive.astralibs.orm.database.Constructable
import ru.astrainteractive.astralibs.orm.database.Entity
import ru.astrainteractive.astralibs.orm.database.Table

object RatingRelationTable : Table<Int>("rating") {
override val id: Column<Int> = integer("id").primaryKey().autoIncrement()
val userID = integer("user_id")
val reason = text("reason")
}
class UserRating : ru.astrainteractive.astralibs.database_v2.Entity<Int>(RatingRelationTable){
class UserRating : Entity<Int>(RatingRelationTable){
val id by RatingRelationTable.id
val userID by RatingRelationTable.userID
val reason by RatingRelationTable.reason
companion object: Constructable<UserRating>(::UserRating)
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.astrainteractive.astratemplate.domain.local.entities

import ru.astrainteractive.astralibs.database.ColumnInfo
import ru.astrainteractive.astralibs.database.Entity
import ru.astrainteractive.astralibs.database.PrimaryKey
import ru.astrainteractive.astralibs.database_v2.Column
import ru.astrainteractive.astralibs.database_v2.Table
import ru.astrainteractive.astralibs.orm.database.Column
import ru.astrainteractive.astralibs.orm.database.Constructable
import ru.astrainteractive.astralibs.orm.database.Entity
import ru.astrainteractive.astralibs.orm.database.Table


object UserTable : Table<Int>("users") {
override val id: Column<Int> = integer("id").primaryKey().autoIncrement()
val discordId = text("discord_id")
val minecraftUuid = text("minecraft_uuid")
}

class User : ru.astrainteractive.astralibs.database_v2.Entity<Int>(UserTable) {
class User : Entity<Int>(UserTable) {
val id by UserTable.id
var discordId by UserTable.discordId
var minecraftUuid by UserTable.minecraftUuid
companion object: Constructable<User>(::User)
}
1 change: 1 addition & 0 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
modImplementation(libs.fabric.api.get())
// AstraLibs
implementation(libs.astralibs.ktxCore)
implementation(libs.astralibs.orm)
implementation(libs.xerialSqliteJdbcLib)
implementation(project(":domain"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import com.astrainteractive.astratemplate.domain.local.entities.UserTable
import com.astrainteractive.astratemplate.domain.remote.RestApi
import com.google.gson.Gson
import kotlinx.coroutines.runBlocking
import ru.astrainteractive.astralibs.database_v2.Database
import ru.astrainteractive.astralibs.di.module
import ru.astrainteractive.astralibs.orm.DBConnection
import ru.astrainteractive.astralibs.orm.Database
import ru.astrainteractive.astralibs.rest.RestRequester
import java.io.File

val sqlModule = module {
runBlocking {
val database = Database()
database.openConnection("jdbc:sqlite:data.db", "org.sqlite.JDBC")
database.openConnection("data.db", DBConnection.SQLite)
UserTable.create(database)
RatingRelationTable.create(database)
database
Expand Down
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
# Plugin/Mod core
plugin = "4.1.0"
plugin = "4.2.0"
name = "AstraTemplate"
group = "com.astrainteractive"
description = "Template plugin for EmpireProjekt"
Expand All @@ -14,7 +14,7 @@ json = "1.3.3"
kaml = "0.46.0"
exposed = "0.38.1"
jdbc = "3.36.0.3"
astraLibs = "2.0.17"
astraLibs = "2.1.1"
mysqlDriver = "8.0.20"
xerialSqliteJdbcVersion = "3.34.0"
# Build
Expand Down Expand Up @@ -60,6 +60,8 @@ kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", v
kotlin-serializationJson = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "json" }
kotlin-serializationKaml = { module = "com.charleskorn.kaml:kaml", version.ref = "kaml" }
astralibs-ktxCore = { module = "ru.astrainteractive.astralibs:ktx-core", version.ref = "astraLibs" }
astralibs-orm = { module = "ru.astrainteractive.astralibs:orm", version.ref = "astraLibs" }
astralibs-spigotGui = { module = "ru.astrainteractive.astralibs:spigot-gui", version.ref = "astraLibs" }
astralibs-spigotCore = { module = "ru.astrainteractive.astralibs:spigot-core", version.ref = "astraLibs" }
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit-bom" }
xerial-sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version.ref = "jdbc" }
Expand Down
2 changes: 2 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies {
implementation(libs.kotlin.serializationKaml)
// AstraLibs
implementation(libs.astralibs.ktxCore)
implementation(libs.astralibs.orm)
implementation(libs.astralibs.spigotGui)
implementation(libs.astralibs.spigotCore)
implementation(libs.bstats.bukkit)
// Spigot dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ import org.bukkit.plugin.java.JavaPlugin
import ru.astrainteractive.astralibs.AstraLibs
import ru.astrainteractive.astralibs.Logger
import ru.astrainteractive.astralibs.async.PluginScope
import ru.astrainteractive.astralibs.di.getValue
import ru.astrainteractive.astralibs.events.GlobalEventManager
import ru.astrainteractive.astralibs.menu.SharedInventoryClickEvent
import ru.astrainteractive.astratemplate.events.EventHandler
import ru.astrainteractive.astratemplate.modules.PluginConfigModule
import ru.astrainteractive.astratemplate.modules.eventHandlerModule
import ru.astrainteractive.astratemplate.utils.Files
import ru.astrainteractive.astratemplate.utils.Singleton

/**
* Initial class for your plugin
*/
class AstraTemplate : JavaPlugin() {
companion object {
lateinit var instance: AstraTemplate
}
companion object : Singleton<AstraTemplate>()

init {
instance = this
Expand All @@ -30,7 +32,8 @@ class AstraTemplate : JavaPlugin() {
/**
* Class for handling all of your events
*/
private var eventHandler: EventHandler? = null
private val eventHandler: EventHandler by eventHandlerModule



/**
Expand All @@ -39,8 +42,9 @@ class AstraTemplate : JavaPlugin() {
override fun onEnable() {
AstraLibs.rememberPlugin(this)
Logger.prefix = "AstraTemplate"
eventHandler = EventHandler()
eventHandler.onEnable()
CommandManager()
SharedInventoryClickEvent.onEnable(GlobalEventManager)
Logger.log("Logger enabled", "AstraTemplate")
Logger.warn("Warn message from logger", "AstraTemplate")
Logger.error("Error message", "AstraTemplate")
Expand All @@ -50,7 +54,7 @@ class AstraTemplate : JavaPlugin() {
* This method called when server is shutting down or when PlugMan disable plugin.
*/
override fun onDisable() {
eventHandler?.onDisable()
eventHandler.onDisable()
runBlocking { SQLDatabaseModule.value.closeConnection() }
HandlerList.unregisterAll(this)
GlobalEventManager.onDisable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import ru.astrainteractive.astralibs.AstraLibs
import ru.astrainteractive.astralibs.utils.registerCommand
import ru.astrainteractive.astralibs.utils.registerTabCompleter
import ru.astrainteractive.astralibs.commands.registerCommand
import ru.astrainteractive.astralibs.commands.registerTabCompleter
import ru.astrainteractive.astralibs.utils.withEntry
import ru.astrainteractive.astratemplate.AstraTemplate


fun CommandManager.addCommandCompleter() = AstraLibs.registerTabCompleter("add") { sender, args ->
if (args.size == 0)

fun CommandManager.addCommandCompleter() = AstraTemplate.instance.registerTabCompleter("add") {
if (args.isEmpty())
return@registerTabCompleter Bukkit.getOnlinePlayers().map { it.name }.withEntry(args.last())

if (args.size == 1)
Expand All @@ -27,7 +29,7 @@ fun CommandManager.addCommandCompleter() = AstraLibs.registerTabCompleter("add")
/**
* Add {PLAYER} {ITEM} [AMOUNT]
*/
fun CommandManager.addCommand() = AstraLibs.registerCommand("add") { sender, args ->
fun CommandManager.addCommand() = AstraTemplate.instance.registerCommand("add") {
if (sender !is Player) {
sender.sendMessage("Sender should be player")
return@registerCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ru.astrainteractive.astralibs.AstraLibs
import ru.astrainteractive.astralibs.commands.registerCommand
import ru.astrainteractive.astralibs.di.getValue
import ru.astrainteractive.astralibs.utils.registerCommand
import ru.astrainteractive.astratemplate.AstraTemplate
import ru.astrainteractive.astratemplate.commands.*
import ru.astrainteractive.astratemplate.modules.TranslationModule

Expand Down Expand Up @@ -31,7 +32,7 @@ class CommandManager {
RandomRickAndMortyCharacter()

// It shows that [val XXX by IReloadable] is actually affected by reloading
AstraLibs.registerCommand("translation") { sender, _ ->
AstraTemplate.instance.registerCommand("translation") {
sender.sendMessage(translation.getByByCheck)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import CommandManager
import ru.astrainteractive.astratemplate.commands.Arguments.Companion.getArgumentString
import org.bukkit.Bukkit
import ru.astrainteractive.astralibs.AstraLibs
import ru.astrainteractive.astralibs.utils.registerCommand
import ru.astrainteractive.astralibs.utils.registerTabCompleter
import ru.astrainteractive.astralibs.commands.registerCommand
import ru.astrainteractive.astralibs.commands.registerTabCompleter
import ru.astrainteractive.astratemplate.AstraTemplate
import ru.astrainteractive.astratemplate.utils.AstraPermission

/**
Expand All @@ -25,7 +26,7 @@ private class Arguments {
}


fun CommandManager.damageCompleter() = AstraLibs.registerTabCompleter("adamage") { sender, args ->
fun CommandManager.damageCompleter() = AstraTemplate.instance.registerTabCompleter("adamage") {
return@registerTabCompleter when (args.size) {
0 -> listOf("adamage")
1 -> Bukkit.getOnlinePlayers().map { it.name }
Expand All @@ -35,7 +36,7 @@ fun CommandManager.damageCompleter() = AstraLibs.registerTabCompleter("adamage")

}

fun CommandManager.damageCommand() = AstraLibs.registerCommand("adamage") { sender, args ->
fun CommandManager.damageCommand() = AstraTemplate.instance.registerCommand("adamage") {
if (!AstraPermission.Damage.hasPermission(sender)) {
sender.sendMessage(translation.noPermission)
return@registerCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package ru.astrainteractive.astratemplate.commands

import CommandManager
import ru.astrainteractive.astralibs.AstraLibs
import ru.astrainteractive.astralibs.utils.registerTabCompleter
import ru.astrainteractive.astralibs.commands.registerTabCompleter
import ru.astrainteractive.astralibs.utils.withEntry
import ru.astrainteractive.astratemplate.AstraTemplate

/**
* Tab completer for your plugin which is called when player typing commands
*/
fun CommandManager.tabCompleter() = AstraLibs.registerTabCompleter("atemp") { sender, args ->
fun CommandManager.tabCompleter() = AstraTemplate.instance.registerTabCompleter("atemp") {
if (args.isEmpty())
return@registerTabCompleter listOf("atemp", "atempreload")
if (args.size == 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import kotlinx.coroutines.launch
import org.bukkit.entity.Player
import ru.astrainteractive.astralibs.AstraLibs
import ru.astrainteractive.astralibs.async.PluginScope
import ru.astrainteractive.astralibs.utils.registerCommand
import ru.astrainteractive.astralibs.commands.registerCommand
import ru.astrainteractive.astratemplate.AstraTemplate

fun CommandManager.tempGUI() = AstraLibs.registerCommand("atempgui") { sender, args ->
fun CommandManager.tempGUI() = AstraTemplate.instance.registerCommand("atempgui") {
if (sender is Player)
PluginScope.launch(Dispatchers.IO) { SampleGUI(sender).open() }
PluginScope.launch(Dispatchers.IO) { SampleGUI(sender as Player).open() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import ru.astrainteractive.astralibs.AstraLibs
import ru.astrainteractive.astralibs.async.PluginScope
import ru.astrainteractive.astralibs.utils.registerCommand
import ru.astrainteractive.astralibs.commands.registerCommand
import ru.astrainteractive.astratemplate.AstraTemplate

fun CommandManager.RandomRickAndMortyCharacter() = AstraLibs.registerCommand("rickandmorty") { sender, args ->
fun CommandManager.RandomRickAndMortyCharacter() = AstraTemplate.instance.registerCommand("rickandmorty") {
sender.sendMessage("Working on that...")
val repository = RepositoryModule.value
PluginScope.launch(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CommandManager
import ru.astrainteractive.astratemplate.AstraTemplate
import ru.astrainteractive.astratemplate.modules.TranslationModule
import ru.astrainteractive.astralibs.AstraLibs
import ru.astrainteractive.astralibs.utils.registerCommand
import ru.astrainteractive.astralibs.commands.registerCommand
import ru.astrainteractive.astratemplate.utils.AstraPermission

/**
Expand All @@ -16,7 +16,7 @@ import ru.astrainteractive.astratemplate.utils.AstraPermission
*
* Here you should also check for permission
*/
fun CommandManager.reload() = AstraLibs.registerCommand("atempreload") { sender, args ->
fun CommandManager.reload() = AstraTemplate.instance.registerCommand("atempreload") {
val translation = TranslationModule.value
if (!AstraPermission.Reload.hasPermission(sender)) {
sender.sendMessage(translation.noPermission)
Expand Down
Loading

0 comments on commit 8c90e7e

Please sign in to comment.