|
8 | 8 | <h5 align="center">
|
9 | 9 | <a href="#basics">Basic Info</a>
|
10 | 10 | <a href="#maven">Maven Import</a>
|
11 |
| -<a href="#development">Development</a> |
| 11 | +<a href="#usage">Usage</a> |
12 | 12 | <a href="#license">License</a>
|
13 | 13 | </h5>
|
14 | 14 | <br>
|
@@ -55,3 +55,63 @@ Then you can add this library as dependency:
|
55 | 55 | ```
|
56 | 56 |
|
57 | 57 | Make sure you reimport if you're using IntelliJ IDEA!
|
| 58 | + |
| 59 | +<br> |
| 60 | + |
| 61 | +<a name="usage"></a> |
| 62 | +Usage: |
| 63 | +-------- |
| 64 | + |
| 65 | +#### 1. Create a HyConfig Object: |
| 66 | + |
| 67 | +```java |
| 68 | +// Pass in only the java.io.File object that stores the config file path. |
| 69 | +// This will load automatically after the object is initialized. |
| 70 | +// Read only will be enabled by default, use config.setEnableWrite(true); to enable write. |
| 71 | +HyConfig config = new HyConfig(new File("./config.yml")); |
| 72 | +``` |
| 73 | + |
| 74 | +#### 2. Use it: |
| 75 | + |
| 76 | +```yml |
| 77 | +# Example YML: |
| 78 | +Test: |
| 79 | + TestString: StringValue1 |
| 80 | + TestInt: 2 |
| 81 | + TestDouble: 3.5 |
| 82 | + TestStringList: |
| 83 | + - hi |
| 84 | + - there |
| 85 | +``` |
| 86 | +
|
| 87 | +```java |
| 88 | +// Code to read Example YML |
| 89 | + |
| 90 | +// Read Config |
| 91 | +// Comment before each variable represents their value. |
| 92 | + |
| 93 | +// "StringValue1" |
| 94 | +String testString = config.getString("Test.TestString"); |
| 95 | + |
| 96 | +// 2 |
| 97 | +int testInt = config.getInt("Test.TestInt"); |
| 98 | + |
| 99 | +// ["hi", "there"] |
| 100 | +List<String> testList = config.getStringList("Test.TestStringList"); |
| 101 | + |
| 102 | +// ["TestString", "TestInt", "TestDouble", "TestStringList"] |
| 103 | +ArrayList<String> keysUnderTest = config.getKeys("Test"); |
| 104 | + |
| 105 | + |
| 106 | +// Write Config |
| 107 | +// Set value requires enableWrite to be true, if not, calling save() won't do anything. |
| 108 | +// All comments will be removed when saving. |
| 109 | +config.setEnableWrite(true); |
| 110 | +config.set("Test.TestSetString", "TestValue"); |
| 111 | +config.save(); |
| 112 | + |
| 113 | + |
| 114 | +// Enable Auto Backup |
| 115 | +// This will take up a lot of space because it creates a new backup every time save() is called. |
| 116 | +config.setBackupDir(new File("./backups/")); |
| 117 | +``` |
0 commit comments