Skip to content

Commit

Permalink
refactored; multimodule support
Browse files Browse the repository at this point in the history
  • Loading branch information
makeevrserg committed Nov 27, 2022
1 parent 3d9cc65 commit d76dd80
Show file tree
Hide file tree
Showing 35 changed files with 578 additions and 296 deletions.
119 changes: 3 additions & 116 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,120 +7,7 @@ plugins {
java
`maven-publish`
`java-library`
kotlin("jvm") version Dependencies.Kotlin.version
kotlin("plugin.serialization") version Dependencies.Kotlin.version
id("com.github.johnrengelman.shadow") version Dependencies.Kotlin.shadow
}
java {
withSourcesJar()
withJavadocJar()
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_17
}
repositories {
mavenLocal()
mavenCentral()
maven(Dependencies.Repositories.extendedclip)
maven(Dependencies.Repositories.maven2Apache)
maven(Dependencies.Repositories.essentialsx)
maven(Dependencies.Repositories.enginehub)
maven(Dependencies.Repositories.spigotmc)
maven(Dependencies.Repositories.dmulloy2)
maven(Dependencies.Repositories.papermc)
maven(Dependencies.Repositories.dv8tion)
maven(Dependencies.Repositories.playpro)
maven(Dependencies.Repositories.jitpack)
maven(Dependencies.Repositories.scarsz)
maven(Dependencies.Repositories.maven2)
modelEngige(project)
astraLibs(project)
paperMC(project)
}

dependencies {
// Kotlin
implementation(Dependencies.Libraries.kotlinGradlePlugin)
// Coroutines
implementation(Dependencies.Libraries.kotlinxCoroutinesCoreJVM)
implementation(Dependencies.Libraries.kotlinxCoroutinesCore)
// Serialization
implementation(Dependencies.Libraries.kotlinxSerialization)
implementation(Dependencies.Libraries.kotlinxSerializationJson)
implementation(Dependencies.Libraries.kotlinxSerializationYaml)
// AstraLibs
implementation(Dependencies.Libraries.astraLibsKtxCore)
implementation(Dependencies.Libraries.astraLibsSpigotCore)
// Test
testImplementation(kotlin("test"))
testImplementation(Dependencies.Libraries.orgTeting)
// Spigot dependencies
compileOnly(Dependencies.Libraries.essentialsX)
compileOnly(Dependencies.Libraries.paperMC)
compileOnly(Dependencies.Libraries.spigot)
compileOnly(Dependencies.Libraries.spigotApi)
compileOnly(Dependencies.Libraries.protocolLib)
compileOnly(Dependencies.Libraries.placeholderapi)
compileOnly(Dependencies.Libraries.worldguard)
compileOnly(Dependencies.Libraries.discordsrv)
compileOnly(Dependencies.Libraries.vaultAPI)
compileOnly(Dependencies.Libraries.coreprotect)
compileOnly(Dependencies.Libraries.modelengine)
}

tasks {
withType<JavaCompile>() {
options.encoding = "UTF-8"
}
withType<Test>().configureEach {
useJUnitPlatform()
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}
withType<Jar> {
archiveClassifier.set("min")
}
compileJava {
options.encoding = "UTF-8"
}
test {
useJUnit()
testLogging {
events("passed", "skipped", "failed")
this.showStandardStreams = true
}
}
processResources {
from(sourceSets.main.get().resources.srcDirs) {
filesMatching("plugin.yml") {
expand(
"name" to project.name,
"version" to project.version,
"description" to project.description
)
}
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
}
}
tasks.shadowJar {
dependencies {
// Kotlin
include(dependency(Dependencies.Libraries.kotlinGradlePlugin))
// Coroutines
include(dependency(Dependencies.Libraries.kotlinxCoroutinesCoreJVM))
include(dependency(Dependencies.Libraries.kotlinxCoroutinesCore))
// Serialization
include(dependency(Dependencies.Libraries.kotlinxSerialization))
include(dependency(Dependencies.Libraries.kotlinxSerializationJson))
include(dependency(Dependencies.Libraries.kotlinxSerializationYaml))
}
isReproducibleFileOrder = true
mergeServiceFiles()
dependsOn(configurations)
archiveClassifier.set(null as String?)
from(sourceSets.main.get().output)
from(project.configurations.runtimeClasspath)
minimize()
destinationDirectory.set(File(Dependencies.destinationDirectoryPath))
kotlin("jvm") version Dependencies.Kotlin.version apply false
kotlin("plugin.serialization") version Dependencies.Kotlin.version apply false
id("com.github.johnrengelman.shadow") version Dependencies.Kotlin.shadow apply false
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object Dependencies {
const val kaml = "0.46.0"
const val exposed = "0.38.1"
const val jdbc = "3.36.0.3"
const val astraLibs = "2.0.0"
const val astraLibs = "2.0.12"
const val shadow = "7.1.2"
const val mysqlDriver = "8.0.20"
const val orgTesting = "7.1.0"
Expand Down
129 changes: 129 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
val name = "AstraNPCS"
group = Dependencies.group
version = Dependencies.version
description = "AstraNPCS"

plugins {
java
`maven-publish`
`java-library`
kotlin("jvm")
kotlin("plugin.serialization")
id("com.github.johnrengelman.shadow")
}
java {
withSourcesJar()
withJavadocJar()
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_17
}
repositories {
mavenLocal()
mavenCentral()
maven(Dependencies.Repositories.extendedclip)
maven(Dependencies.Repositories.maven2Apache)
maven(Dependencies.Repositories.essentialsx)
maven(Dependencies.Repositories.enginehub)
maven(Dependencies.Repositories.spigotmc)
maven(Dependencies.Repositories.dmulloy2)
maven(Dependencies.Repositories.papermc)
maven(Dependencies.Repositories.dv8tion)
maven(Dependencies.Repositories.playpro)
maven(Dependencies.Repositories.jitpack)
maven(Dependencies.Repositories.scarsz)
maven(Dependencies.Repositories.maven2)
modelEngige(project)
astraLibs(project)
paperMC(project)
}

dependencies {
// Kotlin
implementation(Dependencies.Libraries.kotlinGradlePlugin)
// Coroutines
implementation(Dependencies.Libraries.kotlinxCoroutinesCoreJVM)
implementation(Dependencies.Libraries.kotlinxCoroutinesCore)
// Serialization
implementation(Dependencies.Libraries.kotlinxSerialization)
implementation(Dependencies.Libraries.kotlinxSerializationJson)
implementation(Dependencies.Libraries.kotlinxSerializationYaml)
// AstraLibs
implementation(Dependencies.Libraries.astraLibsKtxCore)
implementation(Dependencies.Libraries.astraLibsSpigotCore)
// Test
testImplementation(kotlin("test"))
testImplementation(Dependencies.Libraries.orgTeting)
// Spigot dependencies
compileOnly(Dependencies.Libraries.essentialsX)
compileOnly(Dependencies.Libraries.paperMC)
compileOnly(Dependencies.Libraries.spigot)
compileOnly(Dependencies.Libraries.spigotApi)
compileOnly(Dependencies.Libraries.protocolLib)
compileOnly(Dependencies.Libraries.placeholderapi)
compileOnly(Dependencies.Libraries.worldguard)
compileOnly(Dependencies.Libraries.discordsrv)
compileOnly(Dependencies.Libraries.vaultAPI)
compileOnly(Dependencies.Libraries.coreprotect)
compileOnly(Dependencies.Libraries.modelengine)

implementation(project(":remote-api"))
implementation(project(":versioned:core"))
}

tasks {
withType<JavaCompile>() {
options.encoding = "UTF-8"
}
withType<Test>().configureEach {
useJUnitPlatform()
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}
withType<Jar> {
archiveClassifier.set("min")
}
compileJava {
options.encoding = "UTF-8"
}
test {
useJUnit()
testLogging {
events("passed", "skipped", "failed")
this.showStandardStreams = true
}
}
processResources {
from(sourceSets.main.get().resources.srcDirs) {
filesMatching("plugin.yml") {
expand(
"name" to project.name,
"version" to project.version,
"description" to project.description
)
}
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
}
}
tasks.shadowJar {
dependencies {
// Kotlin
include(dependency(Dependencies.Libraries.kotlinGradlePlugin))
// Coroutines
include(dependency(Dependencies.Libraries.kotlinxCoroutinesCoreJVM))
include(dependency(Dependencies.Libraries.kotlinxCoroutinesCore))
// Serialization
include(dependency(Dependencies.Libraries.kotlinxSerialization))
include(dependency(Dependencies.Libraries.kotlinxSerializationJson))
include(dependency(Dependencies.Libraries.kotlinxSerializationYaml))
}
isReproducibleFileOrder = true
mergeServiceFiles()
dependsOn(configurations)
archiveClassifier.set(null as String?)
from(sourceSets.main.get().output)
from(project.configurations.runtimeClasspath)
minimize()
destinationDirectory.set(File(Dependencies.destinationDirectoryPath))
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.astrainteractive.astranpcs

import com.astrainteractive.astranpcs.api.NPCManager
import com.astrainteractive.astranpcs.api.PacketReader
import com.astrainteractive.astranpcs.commands.CommandManager
import com.astrainteractive.astranpcs.events.ClickNpcEvent
import com.astrainteractive.astranpcs.utils.ConfigProvider
import com.astrainteractive.astranpcs.utils.EmpireNPCSProvider
import com.astrainteractive.astranpcs.modules.*
import com.astrainteractive.astranpcs.utils.AstraTaskTimer
import com.astrainteractive.astranpcs.utils.Files
import kotlinx.coroutines.runBlocking
import org.bukkit.event.HandlerList
Expand All @@ -30,30 +28,34 @@ class AstraNPCS : JavaPlugin() {
AstraLibs.rememberPlugin(this)
Logger.prefix = "AstraNPCS"
CommandManager()
reload()
NPCManager.onEnable()
ClickNpcEvent()
PacketReader.onEnable()

reload()
}

override fun onDisable() {
runBlocking { AstraTaskTimer.cancelJobs() }
HandlerList.unregisterAll(this)
GlobalEventManager.onDisable()
NPCManager.onDisable()
PacketReader.onDisable()
npcManagerModule.value.onDisable()
packetReaderModule.value.onDisable()
runBlocking { AstraTaskTimer.cancelJobs() }
}

fun reload() {
Files.configFile.reload()
ConfigProvider.reload()
EmpireNPCSProvider.reload()
// NPCManager
NPCManager.onDisable()
NPCManager.onEnable()
// PacketReader
PacketReader.onDisable()
PacketReader.onEnable()
configModule.reload()
mojangApiModule.value
npcsModule.reload()

npcManagerModule.value.onDisable()
npcManagerModule.reload()
npcManagerModule.value.onEnable()

packetReaderModule.value.onDisable()
packetReaderModule.reload()
packetReaderModule.value.onEnable()

runBlocking { AstraTaskTimer.cancelJobs() }

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.astrainteractive.astranpcs.commands

import com.astrainteractive.astranpcs.AstraNPCS
import com.astrainteractive.astranpcs.api.NPCManager
import com.astrainteractive.astranpcs.modules.npcManagerModule
import com.astrainteractive.astranpcs.utils.Permissions
import org.bukkit.ChatColor
import org.bukkit.entity.Player
import ru.astrainteractive.astralibs.AstraLibs
import ru.astrainteractive.astralibs.Logger
import ru.astrainteractive.astralibs.di.getValue
import ru.astrainteractive.astralibs.utils.registerCommand
import ru.astrainteractive.astralibs.utils.registerTabCompleter
import ru.astrainteractive.astralibs.utils.withEntry

class Anpc {
val npcManager by npcManagerModule
var anpc = AstraLibs.registerCommand("anpc") { sender, args ->
if (args.firstOrNull().equals("reload", ignoreCase = true)) {
AstraNPCS.instance.reload()
Expand All @@ -38,22 +39,22 @@ class Anpc {
private fun setNpcSkin(sender: Player, args: Array<out String>) {
if (args.size != 3)
return
val npc = NPCManager.npcByEmpireId(args[1]) ?: return
val npc = npcManager.npcByEmpireId(args[1]) ?: return
npc.loadSkinByName(args[2])
}

private fun moveNpcToPlayer(sender: Player, args: Array<out String>) {
if (args.size != 2)
return
val npc = NPCManager.npcByEmpireId(args[1])
val npc = npcManager.npcByEmpireId(args[1])
// npc?.setLocation(sender.location)
}

private fun teleportToNpc(sender: Player, args: Array<out String>) {

if (args.size != 2)
return
val npc = NPCManager.npcByEmpireId(args[1])
val npc = npcManager.npcByEmpireId(args[1])
sender.teleport(npc?.empireNPC?.location ?: return)
}

Expand Down Expand Up @@ -86,7 +87,7 @@ class Anpc {
"name"
).contains(args[0])
)
return@registerTabCompleter NPCManager.registeredNPCs.map { it.empireNPC.id }.withEntry(args[1])
return@registerTabCompleter npcManager.registeredNPCs.map { it.empireNPC.id }.withEntry(args[1])

return@registerTabCompleter listOf()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.astrainteractive.astranpcs.events

import com.astrainteractive.astranpcs.api.NPCInteractionEvent
import com.astrainteractive.astranpcs.api.events.NPCInteractionEvent
import org.bukkit.Bukkit
import ru.astrainteractive.astralibs.events.DSLEvent
import kotlin.random.Random
Expand All @@ -11,8 +11,8 @@ class ClickNpcEvent {
val enpc = e.clicked.empireNPC
if (enpc.phrases?.isNotEmpty() == true) {
val phrases = enpc.phrases
val phrase = phrases[Random.nextInt(phrases.size)]
e.player.sendMessage(phrase)
val phrase = phrases?.get(Random.nextInt(phrases.size))
phrase?.let(e.player::sendMessage)
}
for (command in enpc.commands ?: listOf()) {
if (command.asConsole)
Expand Down
Loading

0 comments on commit d76dd80

Please sign in to comment.