# 介绍 XLIB!
XLIB 简化了 Kotlin 语言为初学者开发的 Minecraft 插件开发。该库的设计使得开发人员无需担心某些函数,可以创建和实现他们的想法。
# 安装
### 选择你需要的模块
(你需要将 XLIB 插件安装到你的服务器上,或者将其实现到你的插件中。)
| 模块 | 描述 |
xlib-all |
包含以下模块中的所有函数。 |
xlib-adventure |
包含用于处理 Kyori Adventure 组件的函数。 |
xlib-config |
(即将推出)包含用于处理配置的函数。 |
xlib-plugin |
包含与 JavaPlugin 交互的函数。 |
### 添加到
build.gradle.kts
```kotlin
repositories {
maven("https://jitpack.io")
}
// 如果你已经在服务器上安装了 XLIB 插件,请使用 'compileOnly'。
dependencies {
implementation("com.github.alexthegoood.xlib:{module}:{version}")
}
```
注意:如果想了解更多关于模块的函数和内容,请查看源代码。
# 示例
registerListeners
```kotlin
class ExamplePlugin : JavaPlugin() {
override fun onEnable() {
registerListeners(
MyListener1(),
MyListener2()
)
}
}
class MyListener1 : Listener { /* EventHandlers here */ }
class MyListener2 : Listener { /* EventHandlers here */ }
```
isFolia
```kotlin
class ExamplePlugin : JavaPlugin() {
override fun onEnable() {
val foliaServer = isFolia() // 如果服务器在 Folia 上运行,则为 True,否则为 false
}
}
```
replacePattern
```kotlin
fun myFunction() {
var mycomponent = Component.text("This is #000000")
mycomponent = mycomponent.replacePattern("#([0-9a-fA-F]{6})", "hex color") // Component.text("This is hex color")
}
```
replaceLiteral
```kotlin
fun myFunction() {
var mycomponent = Component.text("Hello world")
mycomponent = mycomponent.replacePattern("world", "minecraft") // Component.text("Hello minecraft")
}
```
序列化和反序列化
```kotlin
/*
你可以使用 Serializers 枚举 (Serializers.{PLAIN, LEGACY, MINI, GSON, JSON})。
示例:serialize(Serializers.MINI); deserialize(Serializers.JSON)。
默认:Serializers.PLAIN
*/
fun mySerialization() {
val mycomponent = Component.text("Hello world")
val mystring = mycomponent.serialize() // "Hello world"
}
fun myDeserialization() {
val mystring = "Hello world"
val mycomponent = mystring.deserialize() // Component.text("Hello world")
}
```