Skip to content
This repository has been archived by the owner on Dec 3, 2022. It is now read-only.

Commit

Permalink
Fix config critical bug
Browse files Browse the repository at this point in the history
  • Loading branch information
WetABQ committed Mar 18, 2020
1 parent d2cc344 commit 3294d99
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 44 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress DifferentKotlinMavenVersion -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>top.wetabq.easyapi</groupId>
<artifactId>EasyAPI</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>


<licenses>
Expand Down
69 changes: 44 additions & 25 deletions src/main/java/top/wetabq/easyapi/EasyAPI.kt
Original file line number Diff line number Diff line change
@@ -1,49 +1,68 @@
package top.wetabq.easyapi

import cn.nukkit.Server
import cn.nukkit.plugin.PluginBase
import top.wetabq.easyapi.module.EasyAPIModuleManager
import top.wetabq.easyapi.utils.MerticsLite
import top.wetabq.easyapi.utils.color
import java.util.*


object EasyAPI : PluginBase() {
class EasyAPI : PluginBase() {


var TITLE = "&c[&eEasy&aAPI&c]".color()
var git = getGitInfo()

val VERSION: String = this.description.version
var GIT_VERSION = getVersion()

val moduleManager = EasyAPIModuleManager
override fun onLoad() {
INSTANCE = this
init()
}

override fun onEnable() {
MerticsLite(this)
moduleManager.registerDefault()
logger.info("EasyAPI by WetABQ Enabled...")
logger.info("EasyAPI Verison:$VERSION $GIT_VERSION by WetABQ Enabled...")
}

override fun onDisable() {
moduleManager.disableAll()
}

private fun getGitInfo(): Properties {
val gitFileStream = EasyAPI.javaClass.classLoader.getResourceAsStream("git.properties")
val properties = Properties()
properties.load(gitFileStream)
return properties
}
companion object {

lateinit var git: Properties
lateinit var server: Server

lateinit var INSTANCE: EasyAPI
lateinit var VERSION: String
lateinit var GIT_VERSION: String

var TITLE = "&c[&eEasy&aAPI&c]".color()

val moduleManager = EasyAPIModuleManager

fun init() {
server = INSTANCE.server
git = getGitInfo()
VERSION = INSTANCE.description.version
GIT_VERSION = getVersion()
}

private fun getGitInfo(): Properties {
val gitFileStream = INSTANCE::class.java.classLoader.getResourceAsStream("git.properties")
val properties = Properties()
properties.load(gitFileStream)
return properties
}

private fun getVersion(): String {
val version = StringBuilder()
version.append("git-")
var commitId: String
return if (git.getProperty("git.commit.id.abbrev").also {
commitId = it
} == null) {
version.append("null").toString()
} else version.append(commitId).toString()
}

private fun getVersion(): String {
val version = StringBuilder()
version.append("git-")
var commitId: String
return if (git.getProperty("git.commit.id.abbrev").also {
commitId = it
} == null) {
version.append("null").toString()
} else version.append(commitId).toString()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import top.wetabq.easyapi.config.encoder.CodecEasyConfig

object SimpleConfig : CodecEasyConfig<Any>(
"integrateConfig",
EasyAPI,
"integrateConfig") {
EasyAPI.INSTANCE) {

override fun encode(obj: Any): String = obj.toString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import top.wetabq.easyapi.config.EasyConfig

abstract class CodecEasyConfig<T>(
configName:String,
plugin: Plugin,
private val sectionName: String = "config"
plugin: Plugin
) : EasyConfig(configName, plugin), ConfigCodec<T> {

var simpleConfig = LinkedHashMap<String,T>()
var simpleConfig = linkedMapOf<String,T>()
var sectionName = "config"

@Suppress("UNCHECKED_CAST")
override fun initFromConfigSecion(configSection: ConfigSection) {
Expand All @@ -20,6 +20,8 @@ abstract class CodecEasyConfig<T>(
}

override fun spawnDefault(configSection: ConfigSection) {
simpleConfig = linkedMapOf()
sectionName = "config"
configSection[sectionName] = simpleConfig
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import top.wetabq.easyapi.config.encoder.CodecEasyConfig

abstract class AdvanceCodecEasyConfig<T>(
configName:String,
plugin: Plugin,
private val sectionName: String = "config"
) : CodecEasyConfig<T>(configName, plugin, sectionName),
plugin: Plugin
) : CodecEasyConfig<T>(configName, plugin),
AdvanceConfigCodec<T> {

@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ abstract class SimpleCodecEasyConfig<T>(
configName:String,
val plugin: Plugin,
val clazzT: Class<T>,
sectionName: String = "config",
private val codec: AdvanceConfigCodec<T> = ReflectionConfigCodec(
clazzT
)
) : AdvanceCodecEasyConfig<T>(configName, plugin, sectionName) {
) : AdvanceCodecEasyConfig<T>(configName, plugin) {

override fun encode(obj: T): LinkedHashMap<String, *> = codec.encode(obj)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object EasyAPIModuleManager {
module.register()
modules[module.getModuleInfo()] = module
val info = module.getModuleInfo()
EasyAPI.logger.info("Module ${info.name}_${info.moduleVersion} from ${info.moduleOwner.name} by ${info.author} loaded")
EasyAPI.INSTANCE.logger.info("Module ${info.name}_${info.moduleVersion} from ${info.moduleOwner.name} by ${info.author} loaded")
}

fun registerDefault() {
Expand All @@ -36,7 +36,7 @@ object EasyAPIModuleManager {
fun disableAll() {
modules.forEach { (info, module) ->
disable(module)
EasyAPI.logger.warning("Module ${info.name}_${info.moduleVersion} from ${info.moduleOwner.name} by ${info.author} disabled")
EasyAPI.INSTANCE.logger.warning("Module ${info.name}_${info.moduleVersion} from ${info.moduleOwner.name} by ${info.author} disabled")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object AsyncListenerModule: SimpleEasyAPIModule() {
const val AUTHOR = "WetABQ"

override fun getModuleInfo(): ModuleInfo = ModuleInfo(
EasyAPI,
EasyAPI.INSTANCE,
MODULE_NAME,
AUTHOR,
ModuleVersion(1, 0 ,0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object ChatNameTagFormatModule : SimpleEasyAPIModule() {
const val CHAT_FORMATTER = "chatFormatter"

override fun getModuleInfo(): ModuleInfo = ModuleInfo(
EasyAPI,
EasyAPI.INSTANCE,
MODULE_NAME,
AUTHOR,
ModuleVersion(1, 0, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object EasyBaseModule: SimpleEasyAPIModule() {
const val TITLE_PATH = "title"

override fun getModuleInfo(): ModuleInfo = ModuleInfo(
EasyAPI,
EasyAPI.INSTANCE,
MODULE_NAME,
AUTHOR,
ModuleVersion(1,0,0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ object ScreenShowModule : SimpleEasyAPIModule() {
const val SHOW_TASK = "showTask"

override fun getModuleInfo(): ModuleInfo = ModuleInfo(
EasyAPI,
EasyAPI.INSTANCE,
EasyBaseModule.MODULE_NAME,
EasyBaseModule.AUTHOR,
ModuleVersion(1,0,0)
)

override fun moduleRegister() {
this.registerAPI(SHOW_TASK, PluginTaskAPI<EasyAPI>(EasyAPI))
this.registerAPI(SHOW_TASK, PluginTaskAPI<EasyAPI>(EasyAPI.INSTANCE))
.add(PluginTaskEntry(
object : PluginTask<EasyAPI>(EasyAPI) {
object : PluginTask<EasyAPI>(EasyAPI.INSTANCE) {

override fun onRun(p0: Int) {
sendAll()
Expand Down

0 comments on commit 3294d99

Please sign in to comment.