Sueta

ConfigDTO - Access Yaml via object!

0.0.3

An API to easier access your Yaml via an object (ORM)

·Plugin


Config DTO

Wiki | Document | Use As Dependency | Source Code

What is DTO ?

In the field of programming a data transfer object (DTO) is an object that carries data between processes. The motivation for its use is that communication between processes is usually done resorting to remote interfaces (e.g., web services), where each call is an expensive operation.

from wikipedia

This Library let you to access configuration via object related mapping mechanism.

This plugin is fully compatible with kotlin. (caz its written by kotlin :D

Use as Dependency (Maven, Groovy etc)

you can check from here

Features

With this API, you can access the following data in your Yaml:

- primitive type
- collections
- data class
- enumeration
- ConfigurationSerializable Object (ConfigurationSerializable is an interface of bukkit)

How to use

here's the Yaml

name   :   "John Steven"   
family   : 
  -  "Eric"  
  -  "Tomas"  
  -  "Mary"   
age   :  19  
weight   :  44.3

then create a config class

/* 
    find the locate inside the resource 
    if your destination is not same as locate, 
    you can add copyTo = "your/destination" 
*/  
@Resource  (  locate  =   "config.yml"   )  
 public   class  Config  extends  ConfigFile  {  

     public    String   name  ;   //represent the string with path "name"  
     public  List  <  String  >  family  ;   //represent the string list with path "family"  
     public   int  age  ;   //represent the integer with path "age"  
     public   double  weight  ;   //represent the double with path "weight"  

    @Override 
     public    String   toString  (   )   {  
         return   "Config{"   +  
                 "name='"   +  name  +   '  \'  '   +  
                 ", family="   +  family  +  
                 ", age="   +  age  +  
                 ", weight="   +  weight  +  
                 '}'   ;  
     }  
 }

your onEnable():

@Override 
    public void onEnable() { 
        ConfigFactory factory = ConfigDTO.Api.getFactory(this); // get config factory with this plugin instance 
        ConfigManager manager = factory.register(Config.class).dump(); // register the config object 
        Config cf = manager.getConfig(Config.class); // get the instance of config class 
        getLogger().info("Config.class -> " + cf.toString()); //verbose 
    }

the final output:

you can find more on wiki

Similar projects

Plugin →