Improve description and examples

This commit is contained in:
Roman Zhuravlev 2025-08-31 19:35:08 +05:00
parent b091ca6b46
commit 372e4f8ac7

View file

@ -1,4 +1,14 @@
### Add as maven dependency
# Various utilities for YAML, JDBC, Bukkit and other things.
Varoutil is a simple API for projects with bulky APIs like YAML, JDBC, Bukkit, Velocity, and others. Its goal is to
simplify development by making code more consistent.
Note: The Varioutil project is currently under development, there is no stable version yet. The API, package names,
artifacts, and the project name itself may change at any time.
## Add as maven dependency
The project has its own Maven repository, so to access the artifact as a dependency you will need to add it to your
`pom.xml`.
```xml
<repositories>
<repository>
@ -7,63 +17,80 @@
</repository>
</repositories>
```
Then add the artifact as a dependency, for example `common`.
```xml
<dependencies>
<dependency>
<groupId>org.zhdev.varioutil</groupId>
<artifactId>all</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
```
### Example for reflection
#### Maven dependency
```xml
<dependencies>
<dependency>
<groupId>org.zhdev.varioutil</groupId>
<groupId>org.zhdev</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
```
#### Code
```java
import java.lang.reflect.Field;
import org.zhdev.varioutil.ReflectionUtils;
import org.bukkit.Bukkit;
## Examples
Note: The project is primarily focused on making it easier to work with Bukkit and YAML, so only
examples for those are available at the moment. Public Javadocs and more examples will be available with the first
release of the Varioutil project.
public class BukkitFields {
public static final Field METHOD__CraftServer__getServer;
### Bukkit Plugin and YAML Parsing
Let's say we have a Bukkit plugin called Bukman, and we want to read the `extra-config.yml` file located in the
`./plugins/Bukman` directory and get the value of the `state` field from it.
static {
METHOD__CraftServer__getServer = ReflectionUtils.methodSearcher()
.of(Bukkit.getServer())
.methodOf("getServer")
.returns(CLASS__DedicatedServer)
.search();
}
}
```
### Example for yaml
#### Maven dependency
Add the required `bukkit` dependency.
```xml
<dependencies>
<dependency>
<groupId>org.zhdev.varioutil</groupId>
<groupId>org.zhdev</groupId>
<artifactId>bukkit</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
```
#### Code
Add the following code.
```java
package org.zhdev;
import org.zhdev.config.BukkitYamlConfig;
import org.zhdev.config.Config;
public class BukmanBukkitPlugin extends BukkitPreparedPlugin {
private final Config extraConfig = new BukkitYamlConfig("extra-config.yml");
private int state;
@Override
protected void onPostLoad() {
// parse `./plugins/Bukman/extra-config.yml`
loadConfig(extraConfig);
// get the value of the `state` field or get 3 if null
state = extraConfig.getInteger("state", 5);
}
public int getState() {
return state;
}
}
```
### More YAML examples
#### Maven dependency
If you only need YAML parsing, just add the `io` maven dependency.
```xml
<dependencies>
<dependency>
<groupId>org.zhdev</groupId>
<artifactId>io</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
```
#### Code
```java
import org.zhdev.varioutil.Config;
import org.zhdev.varioutil.YamlConfig;
import org.zhdev.Config;
import org.zhdev.YamlConfig;
import java.util.List;