Improve description and examples
This commit is contained in:
parent
b091ca6b46
commit
372e4f8ac7
1 changed files with 63 additions and 36 deletions
99
README.md
99
README.md
|
|
@ -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
|
```xml
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
|
@ -7,63 +17,80 @@
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
```
|
```
|
||||||
|
Then add the artifact as a dependency, for example `common`.
|
||||||
```xml
|
```xml
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.zhdev.varioutil</groupId>
|
<groupId>org.zhdev</groupId>
|
||||||
<artifactId>all</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Example for reflection
|
|
||||||
#### Maven dependency
|
|
||||||
```xml
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.zhdev.varioutil</groupId>
|
|
||||||
<artifactId>common</artifactId>
|
<artifactId>common</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
```
|
```
|
||||||
#### Code
|
|
||||||
```java
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import org.zhdev.varioutil.ReflectionUtils;
|
## Examples
|
||||||
import org.bukkit.Bukkit;
|
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 {
|
### Bukkit Plugin and YAML Parsing
|
||||||
public static final Field METHOD__CraftServer__getServer;
|
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
|
#### Maven dependency
|
||||||
|
Add the required `bukkit` dependency.
|
||||||
```xml
|
```xml
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<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>
|
<artifactId>io</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
```
|
```
|
||||||
#### Code
|
#### Code
|
||||||
|
|
||||||
```java
|
```java
|
||||||
import org.zhdev.varioutil.Config;
|
import org.zhdev.Config;
|
||||||
import org.zhdev.varioutil.YamlConfig;
|
import org.zhdev.YamlConfig;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue