Skip to content

Commit

Permalink
feature: version to 2.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Gk0Wk committed Jul 4, 2023
1 parent 5ec114e commit 03e4679
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 147 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Useful toolkits java library for Bukkit Server Plugin.

- [x] ConfigManager (JSON, YAML, TOML, HOCON, Properties)
- [x] [ConfigManager](./docs/config.md) (JSON, YAML, TOML, HOCON, Properties, XML, CSV)
- [x] MessageManager (i18n Supported)
- [x] LanguageManager
- [x] CommandManager (Deprecated, and recommend to use [aikar's commands](https://github.com/aikar/commands))
Expand Down
4 changes: 1 addition & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ dependencies {
api("org.ktorm:ktorm-core:3.6.0")
// Network
api("com.squareup.okhttp3:okhttp:5.0.0-alpha.11")
// JSON
api("com.lectra:koson:1.2.5")
api("com.google.code.gson:gson:2.10.1")
// JDK
api("org.jetbrains.kotlin:kotlin-stdlib:1.8.21")
// ConfigureFile
Expand All @@ -56,6 +53,7 @@ dependencies {
api("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.15.2")
api("com.fasterxml.jackson.dataformat:jackson-dataformat-properties:2.15.2")
api("com.jasonclawson:jackson-dataformat-hocon:1.1.0")
api("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2")
// Test
testImplementation(kotlin("test"))
}
Expand Down
101 changes: 101 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# ConfigManager

> ConfigManager2 is based on jackson.
Support:

* JSON, YAML, TOML, HOCON, Properties, XML, CSV.
* Tree-mode & Class-mapping-mode.
* Bukkit's ConfigurationSerializable like ItemStack, ItemMeta, Location, etc..

Setup:

```kotlin
// In plugin onLoad
val configManager = ConfigManager2(this)
```

Read config:

```kotlin
// Check if config exists
configManager.touch("config.yml")
// Get config
val config = configManager["config.yml"]
// Visit config
config.root {
// it == ObjectNode of jackson
val enableMultiHome = it["multi-home", "enable"].asBoolean()
val homeLimit = it["multi-home", "limit"].asInt(1) // can set default value
val inventory = it["inventory"].asBase64Inventory()
val location = it["location"].asConfigurationSerializable<Location>()
}
```

Write:

```kotlin
// Write and save
configManager["store.json"].save {
it.set("last-update", System.currentTimeMillis())
it.set("last-player", Bukkit.getOfflinePlayers()[0])
it.set("example-item", ItemStack(Material.APPLE, 64))
it.setBase64("example-inventory", Bukkit.getOfflinePlayers()[0].player!!.inventory)
it.remove("foo")
}
```

Multi-type support:

```kotlin
// Convert type
configManager["1.json"].saveAs("1.xml")
```

## About ObjectNode

Further reading:

- [Jackson Document](https://github.com/FasterXML/jackson-docs)
- [Databind annotations for class](https://stackabuse.com/definitive-guide-to-jackson-objectmapper-serialize-and-deserialize-java-objects/)

locate a noe:

```kotlin
node["123", "456", 12, "a"].asText()
node get "123".asInt()
```

read value:

```kotlin
node.asInt() / asText() / asBoolean() / ...
node.asList() // ArrayList<Any>
node.asMap() // LinkedHashMap<String, Any>
node.asUUID() // to UUID
node.asMaterial() // to Bukkit Material
node.asType<YourClass>() // to your class
node.asConfigurationSerializable<ItemStack>() // to Bukkit ConfigurationSerializable
node.asBase64Inventory() / asBase64ItemStacks() / asBase64ItemStack()
```

write value:

```kotlin
node.put("key", 1 / "123" / true / ...)
node.put("key", listOf(1, 2, 3))
node.put("key", mapOf("a" to 1, "b" to 2))
node.put("key", YourClass())
node.put("key", ItemStack(Material.APPLE, 1))
node.putBase64("key", Inventory / ItemStack / Array<ItemStack>)
```

## Reference

- [Jackson Core](https://github.com/FasterXML/jackson-core)
- [Jackson Databind](https://github.com/FasterXML/jackson-databind)
- [Jackson YAML](https://github.com/FasterXML/jackson-dataformats-text/tree/master/yaml)
- [Jackson XML](https://github.com/FasterXML/jackson-dataformat-xml)
- [Jackson CSV](https://github.com/FasterXML/jackson-dataformats-text/tree/master/csv)
- [Jackson Properties](https://github.com/FasterXML/jackson-dataformats-text/tree/master/properties)
- [Jackson TOML](https://github.com/FasterXML/jackson-dataformats-text/tree/2.13/toml)
4 changes: 1 addition & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@

rootProject.name = "Violet"

rootProject.name = "Violet"
Loading

0 comments on commit 03e4679

Please sign in to comment.