Various utilities for Yaml, SQL, Bukkit and other things.
Find a file
2023-08-11 19:35:24 +05:00
all Fix pom.xml 2023-07-18 02:21:13 +05:00
bukkit Package refactoring 2023-08-11 19:34:05 +05:00
common Moving string return methods to StringUtils 2023-08-11 19:35:24 +05:00
db Package refactoring 2023-08-11 19:33:20 +05:00
io Package refactoring 2023-08-11 19:34:05 +05:00
misc Package refactoring 2023-08-11 19:33:20 +05:00
.gitignore Initial 2023-07-16 20:06:05 +05:00
LICENSE.md Initial 2023-07-16 20:06:05 +05:00
pom.xml Remove profiles; move javadoc and source plugins in main build section 2023-07-24 02:18:50 +05:00
README.md Change URL of repository 2023-07-24 18:28:19 +05:00

Add as maven dependency

<repositories>
    <repository>
        <id>zhdev-repo</id>
        <url>https://maven.zhdev.org/repository/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>org.zhdev.varioutil</groupId>
        <artifactId>all</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

Example for reflection

Maven dependency

<dependencies>
    <dependency>
        <groupId>org.zhdev.varioutil</groupId>
        <artifactId>common</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

Code

import java.lang.reflect.Field;

import org.zhdev.util.ReflectionUtils;
import org.bukkit.Bukkit;

public class BukkitFields {
    public static final Field METHOD__CraftServer__getServer;

    static {
        METHOD__CraftServer__getServer = ReflectionUtils.methodSearcher()
                .of(Bukkit.getServer())
                .methodOf("getServer")
                .returns(CLASS__DedicatedServer)
                .search();
    }
}

Example for yaml

Maven dependency

<dependencies>
    <dependency>
        <groupId>org.zhdev.varioutil</groupId>
        <artifactId>io</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

Code

import org.zhdev.config.Config;
import org.zhdev.config.YamlConfig;

import java.util.List;

public class Main {
    public static void main(String[] args) {
        Config config = new YamlConfig();

        config.load(); // load from ./config.yml file by default
        config.load("test.yml"); // load from ./test.yml by 1st argument

        // set value to "Hello world!" of 'test' key and set block comment from 3rd argument
        config.set("test", "Hello world!", "It's hello world comment!");

        config.save(); // save as ./config.yml by default
        config.save("test.yml"); // save as ./test.yml by 1st argument

        Config anotherConfig = new YamlConfig("another.yml"); // create with default name "another.yml"
        config.load(); // load from ./another.yml by default

        // get value "test" as integer or "5" if it is null
        Integer value = config.getInteger("test", 5);

        // get value "foo->bar->testlist" as list
        List<?> list = config.getSection("foo", "bar").getList("testlist");
    }
}