Various utilities for Yaml, SQL, Bukkit and other things.
Find a file
2024-07-15 20:18:50 +05:00
all Adding velocity module 2023-08-11 19:38:38 +05:00
bukkit Add 'exists' path check 2024-04-26 23:33:22 +05:00
common Add 'exists' path check 2024-04-26 23:33:22 +05:00
db Add 'exists' path check 2024-04-26 23:33:22 +05:00
io Fix memory leak 2023-12-02 19:48:10 +05:00
misc Remove unnecessary classes 2024-07-15 20:18:50 +05:00
velocity Add 'exists' path check 2024-04-26 23:33:22 +05:00
.gitignore Add *.iml 2023-12-02 19:48:33 +05:00
LICENSE.md Initial 2023-07-16 20:06:05 +05:00
pom.xml Add colors 2023-10-21 15:55:08 +05:00
README.md Correcting README 2023-08-11 19:41:46 +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.varioutil.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.varioutil.Config;
import org.zhdev.varioutil.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");
    }
}