All Projects → mkotb → ConfigAPI

mkotb / ConfigAPI

Licence: ISC license
GSON-like ORM for Bukkit YAML API's

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to ConfigAPI

kerrigan
基于Tornado实现的一套配置中心,可基于分项目、环境管理配置,语法高亮、对比历史版本、快速回滚等,并提供Restful风格的API
Stars: ✭ 57 (+147.83%)
Mutual labels:  config, config-api
hb-config
hb-config: easy to configure your python project especially Deep Learning experiments
Stars: ✭ 21 (-8.7%)
Mutual labels:  config
nvim
No description or website provided.
Stars: ✭ 13 (-43.48%)
Mutual labels:  config
CS-CoreLib2
This is an updated (LITE) Version of CS-CoreLib. Instead of being a hard dependency, it should be shaded instead.
Stars: ✭ 20 (-13.04%)
Mutual labels:  bukkit
Webpack5-Max
Webpack 5 Boilerplate for JS/React/TS apps.
Stars: ✭ 103 (+347.83%)
Mutual labels:  config
dotfiles
My collection of dotfiles
Stars: ✭ 77 (+234.78%)
Mutual labels:  config
GuiLib
Yet another bukkit inventory gui library
Stars: ✭ 18 (-21.74%)
Mutual labels:  bukkit
node-config
nodejs的配置中心
Stars: ✭ 53 (+130.43%)
Mutual labels:  config
profig
A straightforward configuration library for Python.
Stars: ✭ 26 (+13.04%)
Mutual labels:  config
RxjavaSamples
This repo is a container for some samples using RXJAVA2 samples
Stars: ✭ 12 (-47.83%)
Mutual labels:  gson
ChatControl-Pro
The ultimate chat solution. Prevent spam, ads, swears and even bots on your server. Replaced by ChatControl Red: https://mineacademy.org/chatcontrol-red
Stars: ✭ 65 (+182.61%)
Mutual labels:  bukkit
juno-agent
juno-agent
Stars: ✭ 46 (+100%)
Mutual labels:  config
nim config
Global project-agnostic config.nims
Stars: ✭ 54 (+134.78%)
Mutual labels:  config
dotfiles
/home/yous
Stars: ✭ 43 (+86.96%)
Mutual labels:  config
Survival-Games
Survival Games plugin for Spigot - UPDATED for 1.13+
Stars: ✭ 24 (+4.35%)
Mutual labels:  bukkit
LevelledMobs
Level-up mobs on your Spigot/Paper server, RPG-style!
Stars: ✭ 143 (+521.74%)
Mutual labels:  bukkit
rimerc
rimerc: rimer's dictionary & config
Stars: ✭ 228 (+891.3%)
Mutual labels:  config
dough
Library containing a lot of useful utility classes for the everyday Java and Spigot/Paper developer.
Stars: ✭ 26 (+13.04%)
Mutual labels:  bukkit
dotfiles
My personal configuration and bootstrap files
Stars: ✭ 14 (-39.13%)
Mutual labels:  config
Debuggery
A small plugin designed to expose API values at runtime.
Stars: ✭ 36 (+56.52%)
Mutual labels:  bukkit

ConfigAPI

This project is a GSON-like project for Bukkit's YML Config API. This project is on maven central! You can add it to your project using the following:

<dependency>
  <groupId>xyz.mkotb</groupId>
  <artifactId>config-api</artifactId>
  <version>1.0.1</version>
</dependency>

If you're not familiar with GSON, let me show you a quick example of what you can do with this API:

public class MyPlugin extends JavaPlugin {
    private MyConfig myConfig;
    private ConfigFactory configFactory = ConfigFactory.newFactory(this);

    @Override
    public void onEnable() {
        myConfig = configFactory.fromFile("config", MyConfig.class);
        getLogger().info(myConfig.getStartMessage());

        if (myConfig.myFavouriteNumbers != null) {
            getLogger().info(myConfig.myFavouriteNumbers.toString());
        }
    }

    @Override
    public void onDisable() {
        // if we changed values in my config while the server is up
        // we should save it
        configFactory.save("config", myConfig);
    }
}

@Comment("This is my header comment")
public class MyConfig {
                    // init values will be saved as part of the "default config"
    private String startMessage = "This awesome bukkit plugin has started!";
    @Comment("Put in your favourite number here!")
    @RequiredField // if this field is not set in the config file due to user error
                   // an exception will be thrown
    private int myFavouriteNumber = 3;
                   // lists, sets, queues, maps, and arrays are supported!
    List<Integer> myFavouriteNumbers;
                   // supports concurrency classes!
    private AtomicInteger myFavouriteAtomicNumber = new AtomicInteger(4);
                   // myWeapon will be set if it's in the config but won't exist
                   // by default
    private ItemStack myWeapon;
                   // additionally objects within the config are allowed
    private PartOfConfig part;

    public String getStartMessage() {
        return startMessage;
    }
}

public class PartOfConfig {
    private String hi = "my name is billy";
}

In the following example, we displayed majority of the features available in the API. The fromFile() method takes care of all the initial processes you may need, such as creating the new file and placing default values. Many additional classes such as color, offline players, and vectors are supported to be saved. In the future, extensibility to the Adapter API will be added to where you can use your own data types which can be converted.

Interaction with the File

As of currently, if you were to setup and run this plugin, it would write the following to config.yml using the default values:

# This is my header comment
start-message: This awesome bukkit plugin has started!
# Put in your favourite number here!
my-favourite-number: 3
my-favourite-atomic-number: 4

As you can see, it only saved the fields which were already set as defaults. If you haven't noticed already, the API changed the naming conventions from Java lower camel case (likeThis) to the conventional YAML namespace (like-this). You can modify which naming convention the API uses. There will be more information you can refer to on this on the wiki.

If we were to add a list of our favourite numbers to the config manually, we will be able to see the API being able to load them up without a problem:

my-favourite-numbers:
- 2
- 6
- 8

And if we start up our server with the new config, we'll see the following printed in console:

[01:09:42 INFO]: [ConfigTestPlugin] Enabling ConfigTestPlugin v1.0
[01:09:42 INFO]: [ConfigTestPlugin] This super cool awesome bukkit plugin has started!
[01:09:42 INFO]: [ConfigTestPlugin] [2, 6, 8]

Well, that was easy.

ConfigAPI is still in early development and will soon be for release for developers to use in their projects. Contributions are more than welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].