Coder Social home page Coder Social logo

yamlconfiguration's Introduction

Description

You need yaml configuration api with comments and with easy use ?

This API is for you !

Dynamic-Yaml-Configuration works with runtime annotations, it permit to create configuration values with a great ease.

Extremly modulable, and useful, but not optimized (due to comments and lot of reflection uses with annotations)

You should use it only for low-storage configurations

Features

  • default config values
  • modulable comments
  • dynamic values creations
  • automatic replacements & color code translations
  • dynamic configuration keys creation

Implementation

Gradle

repositories {
    mavenCentral()
}

dependencies {
    implementation 'io.github.ibramsou:dynamic-yaml-configuration-api:1.3.1'
    implementation 'io.github.ibramsou:dynamic-yaml-configuration-core:1.3.1'
}

Maven

<dependencies>
    <dependency>
        <groupId>io.github.ibramsou</groupId>
        <artifactId>dynamic-yaml-configuration-api</artifactId>
        <version>1.3.0</version>
    </dependency>
        <dependency>
        <groupId>io.github.ibramsou</groupId>
        <artifactId>dynamic-yaml-configuration-core</artifactId>
        <version>1.3.0</version>
    </dependency>
</dependencies>

How to use

Annotated Configuration Values

public class MyDynamicConfiguration {

    @ConfigurationPath(value = "example-value", comments = "Here is an example value :)")
    public String exampleValue = "Hi !";
    @ConfigurationPath("test.size")
    public int exampleSize = 451;

    public MyDynamicConfiguration() {
        final File configFile = new File("config.yml");
        // file will be automatically created if not exists
        final YamlConfiguration configuration = YamlAPI.INSTANCE.getConfigurationManager()
                .loadConfiguration(this, configFile, ConfigurationType.DYNAMIC);
        // You always need to load & save for dynamic config types
        configuration.load();
        configuration.save();
    }
}

Automatic Config Translation

@ConfigurationPath("replaced-value")
@ConfigurationReplacement(values = "$", replacements = "S")
// If you using bukkit / bungee, color codes will be translated with configuration replacement
public String replacedValue = "&cHi ! $$$"; 

Note: You can create your packet handler interface in relation with your own custom packets

Dynamic Sections

You can also seperate your configuration sections with ConfigurationPart objects

@ConfigurationPath(value = "sub-section", comments = "Here is my sub config section ! :)")
@ConfigurationReplacement
public MyConfigurationSection subSection = new MyConfigurationSection();
    
private static class MyConfigurationSection extends ConfigurationPart {
    @ConfigurationPath("enabled")
    public boolean enabled = true;
    @ConfigurationPath("players")
    public List<String> players = new ArrayList<>(Arrays.asList("Bramsou", "Ibrahim"));
    @ConfigurationPath("message")
    public String message = "&aHi :)";
}

Note: If a section is anotated by @ConfigurationReplacement every values of the section will be replaced

Dynamic Keys

@ConfigurationKeys(defaultKeys = "banana")
@ConfigurationPath(value = "items", comments = "")
public ConfigurationList<ItemSection> items = new ConfigurationList<ItemSection>(Collections.singletonList(new ItemSection())) {
    @Override
    public ConfigurationPart create(String key) {
        return new ItemSection(key);
    }
};

private static class ItemSection extends ConfigurationPart {

    @ConfigurationPath("amount")
    public int amount = 1;
    @ConfigurationPath("price")
    public int price = 5;
    
    private final String itemName;

    public ItemSection(String name) {
        this.itemName = name;
    }
    
    public String getItemName() {
        return this.itemName;
    }
}

yamlconfiguration's People

Contributors

ibramsou avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.