Skip to content

Commit 5bd0236

Browse files
committed
0.2-RC2
1 parent 88f234f commit 5bd0236

20 files changed

Lines changed: 242 additions & 27 deletions

File tree

.idea/dictionaries/project.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Core/src/main/kotlin/io/github/grassproject/framework/config/Config.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import io.github.grassproject.framework.core.GPPlugin
44
import org.bukkit.configuration.file.FileConfiguration
55
import org.bukkit.configuration.file.YamlConfiguration
66
import java.io.File
7+
import kotlin.reflect.KClass
8+
import kotlin.reflect.full.cast
79

810
fun GPPlugin.saveResource(resource: String, file: File) {
911
if (file.exists()) return
@@ -23,7 +25,7 @@ fun GPPlugin.saveResource(resource: String, file: File) {
2325
}
2426
}
2527

26-
fun GPPlugin.init(vararg configs: GPFile) {
28+
fun GPPlugin.init(vararg configs: GPConfig) {
2729
configs.forEach { yaml ->
2830
val file = File(dataFolder, yaml.name)
2931
if (!file.exists()) saveResource(yaml.name, file)
@@ -60,6 +62,10 @@ abstract class Config {
6062
open fun double(path: String, def: Double = 0.0) = config.getDouble(path, def)
6163
open fun doubleList(path: String) = config.getDoubleList(path)
6264

65+
open fun <T: Any> getValue(path: String, clazz: KClass<T>): T {
66+
return clazz.cast(config.get(path))
67+
}
68+
6369
inline fun <reified T : Enum<T>> enum(path: String, def: T): T {
6470
val str = string(path, def.name)
6571
return runCatching { enumValueOf<T>(str.uppercase()) }.getOrDefault(def)
@@ -87,7 +93,7 @@ open class ConfigFile(open val file: File) : Config() {
8793
}
8894
}
8995

90-
open class GPFile(pluginFolder: File, open var name: String) :
96+
open class GPConfig(pluginFolder: File, open var name: String) :
9197
ConfigFile(File(pluginFolder, name)) {
9298

9399
constructor(pluginFolder: File, name: String, autoCreate: Boolean = true) : this(pluginFolder, name) {

Core/src/main/kotlin/io/github/grassproject/framework/config/ConfigExt.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.bukkit.configuration.ConfigurationSection
44
import org.bukkit.configuration.MemoryConfiguration
55
import org.bukkit.configuration.file.FileConfiguration
66
import org.bukkit.configuration.file.YamlConfiguration
7-
import kotlin.collections.iterator
87

98
fun ConfigurationSection.keysForEach(path: String, boolean: Boolean, function: (String) -> Unit) {
109
val section = getConfigurationSection(path) ?: return

Core/src/main/kotlin/io/github/grassproject/framework/core/GPFrameworkEngine.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package io.github.grassproject.framework.core
22

3-
import org.slf4j.LoggerFactory
3+
import io.github.grassproject.framework.util.GPLogger
44

55
object GPFrameworkEngine {
6-
7-
private val logger = LoggerFactory.getLogger("GPFramework")
86
private val plugins = mutableMapOf<String, GPPlugin>()
97

108
fun register(plugin: GPPlugin) {
119
plugins[plugin.name] = plugin
12-
logger.info("Registered plugin ${plugin.name}")
10+
GPLogger.suc("Registered plugin ${plugin.name}")
1311
}
1412

1513
fun unregister(plugin: GPPlugin) {
1614
plugins.remove(plugin.name)
17-
logger.info("Unregistered plugin ${plugin.name}")
15+
GPLogger.bug("Unregistered plugin ${plugin.name}")
1816
}
1917

2018
fun getPlugin(name: String): GPPlugin? = plugins[name]

Core/src/main/kotlin/io/github/grassproject/framework/core/GPPlugin.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
package io.github.grassproject.framework.core
22

3+
import io.github.grassproject.framework.util.GPLogger
34
import io.github.grassproject.framework.util.bukkit.MinecraftVersion
45
import org.bukkit.plugin.java.JavaPlugin
56

67
abstract class GPPlugin : JavaPlugin(), GPFramework {
8+
val version=pluginMeta.version
9+
val authors=pluginMeta.authors
10+
val description=pluginMeta.description
11+
val apiVersion=pluginMeta.apiVersion
712

813
override fun onLoad() {
914
load()
1015
}
1116

1217
override fun onEnable() {
1318
if (!MinecraftVersion.V1_21_1.isAbove()) {
14-
logger.warning("서버 버전이 너무 낮습니다. 1.21.1 이상을 사용하세요.")
19+
GPLogger.warning("서버 버전이 너무 낮습니다. 1.21.1 이상을 사용하세요.")
1520
server.pluginManager.disablePlugin(this)
1621
return
1722
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.github.grassproject.framework.core.command
2+
3+
import com.mojang.brigadier.arguments.ArgumentType
4+
import com.mojang.brigadier.builder.LiteralArgumentBuilder
5+
import com.mojang.brigadier.tree.LiteralCommandNode
6+
import io.papermc.paper.command.brigadier.CommandSourceStack
7+
import org.bukkit.plugin.java.JavaPlugin
8+
9+
@Deprecated("Experimental")
10+
abstract class GPBrigadier {
11+
12+
abstract val plugin: JavaPlugin
13+
abstract val commandName: String
14+
open val permission: String? = null
15+
16+
protected val rootBuilder: LiteralArgumentBuilder<CommandSourceStack> by lazy {
17+
LiteralArgumentBuilder.literal<CommandSourceStack>(commandName)
18+
}
19+
20+
val commandNode: LiteralCommandNode<CommandSourceStack>
21+
get() = rootBuilder.build()
22+
23+
fun literal(name: String, block: LiteralArgumentBuilder<CommandSourceStack>.() -> Unit) {
24+
val builder = LiteralArgumentBuilder.literal<CommandSourceStack>(name)
25+
builder.block()
26+
rootBuilder.then(builder)
27+
}
28+
29+
fun <T> argument(name: String, type: ArgumentType<T>, executes: ((CommandSourceStack, ArgumentType<T>) -> Int)? = null) {
30+
val argBuilder = com.mojang.brigadier.builder.RequiredArgumentBuilder.argument<CommandSourceStack, T>(name, type)
31+
if (executes != null) {
32+
argBuilder.executes { ctx ->
33+
val value = ctx.getArgument(name, type.javaClass)
34+
executes(ctx.source, value)
35+
}
36+
}
37+
rootBuilder.then(argBuilder)
38+
}
39+
40+
open fun executes(exec: (CommandSourceStack, Array<String>) -> Int) {
41+
rootBuilder.executes { ctx ->
42+
val args = ctx.input.split(" ").drop(1).toTypedArray()
43+
exec(ctx.source, args)
44+
}
45+
}
46+
47+
fun register(): LiteralCommandNode<CommandSourceStack> {
48+
// plugin.server.pluginManager.registerEvents(object : org.bukkit.event.Listener {}, plugin)
49+
// plugin.getLifecycleManager().registerEventHandler(io.papermc.paper.command.brigadier.) { commands ->
50+
// commands.registrar().register(commandNode, "GPBrigadier: $commandName")
51+
// }
52+
return this.rootBuilder.build()
53+
}
54+
}

Core/src/main/kotlin/io/github/grassproject/framework/database/DatabaseManager.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ package io.github.grassproject.framework.database
22

33
import com.zaxxer.hikari.HikariConfig
44
import com.zaxxer.hikari.HikariDataSource
5-
import io.github.grassproject.framework.config.GPFile
6-
import io.github.grassproject.framework.core.GPPlugin
5+
import io.github.grassproject.framework.config.GPConfig
76
import org.jetbrains.exposed.v1.core.Table
87
import org.jetbrains.exposed.v1.jdbc.Database
98
import org.jetbrains.exposed.v1.jdbc.SchemaUtils
109
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
1110
import java.io.File
12-
import java.io.IOException
1311

1412
object DatabaseManager {
1513

@@ -19,7 +17,7 @@ object DatabaseManager {
1917
this.driver = driver
2018
}
2119

22-
fun initConfig(config: GPFile) {
20+
fun initConfig(config: GPConfig) {
2321
val type = config.enum("database.type", DataType.SQLITE)
2422

2523
val host = config.string("database.credentials.host", "localhost")

Core/src/main/kotlin/io/github/grassproject/framework/item/ItemBuilder.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import org.bukkit.inventory.meta.ItemMeta
1515
import org.bukkit.inventory.meta.components.CustomModelDataComponent
1616
import org.bukkit.persistence.PersistentDataContainer
1717
import org.bukkit.persistence.PersistentDataType
18-
import kotlin.collections.iterator
1918

2019
class ItemBuilder(private val itemStack: ItemStack) {
2120

Core/src/main/kotlin/io/github/grassproject/framework/item/ItemHandler.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.github.grassproject.framework.item
22

3-
import io.github.grassproject.framework.item.factory.*
3+
import io.github.grassproject.framework.item.factory.CraftEngineFactory
4+
import io.github.grassproject.framework.item.factory.IAFactory
5+
import io.github.grassproject.framework.item.factory.NexoFactory
46
import org.bukkit.Material
57
import org.bukkit.inventory.ItemStack
68

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.github.grassproject.framework.util
2+
3+
import io.github.grassproject.framework.util.component.toMiniMessage
4+
import org.bukkit.Bukkit
5+
6+
object GPLogger {
7+
private val prefix="<#96f19c>GPFramework</#96f19c><#989c99> > </#989c99>"
8+
9+
@JvmStatic
10+
fun info(string: String) {
11+
Bukkit.getConsoleSender().sendMessage { "${prefix}<white>${string}</white>".toMiniMessage() }
12+
}
13+
14+
@JvmStatic
15+
fun warning(string: String) {
16+
Bukkit.getConsoleSender().sendMessage { "${prefix}<yellow>${string}</yellow>".toMiniMessage() }
17+
}
18+
19+
@JvmStatic
20+
fun suc(string: String) {
21+
Bukkit.getConsoleSender().sendMessage { "${prefix}<green>${string}</green>".toMiniMessage() }
22+
}
23+
24+
@JvmStatic
25+
fun bug(string: String) {
26+
Bukkit.getConsoleSender().sendMessage { "${prefix}<red>${string}</red>".toMiniMessage() }
27+
}
28+
}

0 commit comments

Comments
 (0)