Skip to content

BetterYaml setup

Dieter Nuytemans edited this page Jul 1, 2021 · 4 revisions

Setup BetterYaml to work with your project

Add the following to your pom:

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>
<dependencies>
	<dependency>
	    <groupId>com.github.BetterPluginsSpigot</groupId>
	    <artifactId>BetterYaml</artifactId>
	    <version>1.1.0</version>
	</dependency>
</dependencies>

To prevent compatibility issues with other plugins (these may prevent your plugin from enabling!), relocate BetterYAML to a uniquely named part of your JAR-file:

<build>
<!-- Shade BetterYAML into your jar-->
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-shade-plugin</artifactId>
         <version>3.2.1</version>
         <configuration>
            <relocations>
               <relocation>
                  <pattern>be.dezijwegel.betteryaml</pattern>
                  <shadedPattern>YOUR.UNIQUE.PACKAGE.NAME.HERE</shadedPattern>
               </relocation>
            </relocations>
         </configuration>
         <executions>
            <execution>
               <phase>package</phase>
               <goals>
                  <goal>shade</goal>
               </goals>
            </execution>
         </executions>
      </plugin>
   </plugins>
</build>

Preferably, use the latest version to get all features. Check BetterYaml Releases to find which is the latest version. Or check it via JitPack: .

For each config file, we need to create two files in our resources folder. Let's assume we only have one config file; but working with multiple config files is supported. Our config file is called ourConfig.yml.

| - .git/
| - src/
|    | - <redacted>
| - resources
|    | - ourConfig.yml
|    | - templates/
|         | - ourConfig.yml
| - pom.xml

In resources/templates/ourConfig.yml we create our template, this file contains all comments and options with placeholder values. Check the config file below for an explanation. This is the file where you will edit what the server owner's config looks like.

resources/templates/ourConfig.yml
# This option is not using a placeholder, so this setting will be reverted everytime your plugin loads
# That means that if the user changes this, its changes will be undone
version: "3.1.4"

# The {} braces indicate a placeholder. If no default value is specified in resources/ourConfig.yml, the placeholder will not be replaced
max_free_pizzas: {max_free_pizzas}

# This placeholder will not be specified in the next section
free_pizza: {free_pizza}

# For this option, we will define a default option
string_option: {string_option}

We also need to specify the default values in resources/ourConfig.yml:

resources/ourConfig.yml
# Comments in this file do not matter, it only serves as a storage for your default values
max_free_pizzas: 17
string_option: "This is a String!"

If your user now uses your plugin for the first time, the copied config file will look like the one below. In case the user makes any configuration change, it will be maintained and that change will not be overwritten. When a user edits, adds or removes comments, they will revert to the default values.

Plugin config on server: ourConfig.yml
# This option is not using a placeholder, so this setting will be reverted everytime your plugin loads
# That means that if the user changes this, its changes will be undone
version: "3.1.4"

# The {} braces indicate a placeholder. If no default value is specified in resources/ourConfig.yml, the placeholder will not be replaced
max_free_pizzas: 17

# This placeholder will not be specified in the next section
free_pizza: {free_pizza}

# It is good practice to wrap placeholders that will be replaced by a String with ""
string_option: "This is a String!"

Wiki navigation

Wiki home

JavaDocs


BetterYaml (config files)

BetterYaml (deprecated, but supported)

Please use OptionalBetterYaml instead.

Setup

How to use BetterYaml

OptionalBetterYaml

Setup

How to use


BetterLang (language files)

Setup

How to use


Validation

Auto-correct faulty configuration values! You can create your own, custom validators.

How to use validators

EXPERIMENTAL: Optional sections

Clone this wiki locally