diff --git a/README.md b/README.md index f884141..ef2b700 100644 --- a/README.md +++ b/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 @@ -7,63 +17,80 @@ ``` +Then add the artifact as a dependency, for example `common`. ```xml - org.zhdev.varioutil - all - 1.0-SNAPSHOT - - -``` - -### Example for reflection -#### Maven dependency -```xml - - - org.zhdev.varioutil + org.zhdev common 1.0-SNAPSHOT ``` -#### 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 - org.zhdev.varioutil + org.zhdev + bukkit + 1.0-SNAPSHOT + + +``` +#### 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 + + + org.zhdev io 1.0-SNAPSHOT ``` #### Code - ```java -import org.zhdev.varioutil.Config; -import org.zhdev.varioutil.YamlConfig; +import org.zhdev.Config; +import org.zhdev.YamlConfig; import java.util.List;