Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Files

Latest commit

 

History

History
125 lines (96 loc) · 2.79 KB

README.en-us.md

File metadata and controls

125 lines (96 loc) · 2.79 KB



HyConfigLib

A simple YAML configuration library.




Basic Information:

  • A port of the config lib in Minecraft Bukkit (Spigot).
  • There's no difference except that this config lib can run witout a Minecraft server.
  • For people who is used to write config on Minecraft plugins but now want to write some independent programs.

All credit belongs to @md_5.
Tutorial on creating a Minecraft config: https://www.spigotmc.org/wiki/creating-a-config-file/


Maven Import:

Add the JitPack repo into your pom.xml first:

<repositories>
    <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
    </repository>
</repositories>

Then you can add this library as dependency:

<dependency>
    <groupId>com.github.hydevelop</groupId>
    <artifactId>HyConfigLib</artifactId>
    <version>3.1.52</version>
</dependency>

Make sure you reimport if you're using IntelliJ IDEA!


Usage:

1. Create a HyConfig Object:

// Pass in only the java.io.File object that stores the config file path.
// This will load automatically after the object is initialized.
// Read only will be enabled by default, use config.setEnableWrite(true); to enable write.
HyConfig config = new HyConfig(new File("./config.yml"));

2. Use it:

# Example YML:
Test:
  TestString: StringValue1
  TestInt: 2
  TestDouble: 3.5
  TestStringList:
  - hi
  - there
// Code to read Example YML

// Read Config
// Comment before each variable represents their value.

// "StringValue1"
String testString = config.getString("Test.TestString");

// 2
int testInt = config.getInt("Test.TestInt");

// ["hi", "there"]
List<String> testList = config.getStringList("Test.TestStringList");

// ["TestString", "TestInt", "TestDouble", "TestStringList"]
ArrayList<String> keysUnderTest = config.getKeys("Test");


// Write Config
// Set value requires enableWrite to be true, if not, calling save() won't do anything.
// All comments will be removed when saving.
config.setEnableWrite(true);
config.set("Test.TestSetString", "TestValue");
config.save();


// Enable Auto Backup
// This will take up a lot of space because it creates a new backup every time save() is called.
config.setBackupDir(new File("./backups/"));

Virtual Config:

This is a way to load config from a string without a file.

HyVirtualConfig virtualConfig = new HyVirtualConfig(configInString);