Coder Social home page Coder Social logo

customfileconfig's Introduction

CustomFileConfig

API that bridges the gap between other data representation formats and Spigot's Configuration API

Goals

The solution for supporting alternate configuration formats must be

  • extensible
  • fast
  • connect directly with the Bukkit Configuration File
  • serve as an alternative to the YamlConfiguration class

Problems Seeking to solve

  • Uprooting entire code base to support an alternative configuration format
  • End user complaints of configuration breaking due to misalignment of indent
  • Allow switch to configuration formats that are both "human readable" and "human modifiable".

How it works

Each of the implementations work by acting as a translator between the configuration format and Bukkit's configuration api. These translation needs to happen in both way's which brings us to the Constructor and Representer classes. The Representer builds a configuration format representation of objects passed to it and the Constructor constructs Java objects from the configuration representation.

How to use

Simply replace YamlConfiguration with any of the provided solutions to seamlessly began saving and loading data in a completely different format.

  YamlConfiguration config = new YamlConfiguration();
  File file = new File(plugin.getDataFolder(),"data.yml");

  
  try {
    config.load(file);
  } catch (InvalidConfigurationException e) {
    e.printStackTrace();
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  }
  
  

In that code block, the first line can easily be replaced with something like

  GsonConfiguration config = new GsonConfiguration();

and use Google's Gson library.

If you are really ambitious, this api will meet you there and even handle the Xml format.

  XmlConfiguration config = new XmlConfiguration();

Since these alternative configuration formats are not included in spigot by default, you will need to shade them in to your final build.

        <dependency>
            <groupId>[library group id]</groupId>
            <artifactId>[library artifact id]</artifactId>
            <version>[library version]</version>
            <scope>compile</scope>
        </dependency>
		
	<build>
        <plugins>
      
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <relocations>
                        <relocation>
                            <pattern>[library package]</pattern>
                            <shadedPattern>[your package].[library name]</shadedPattern>
                        </relocation>
                    </relocations>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
	```
  
  Then you just copy the neccessary files to your project. (Shading this enourmous project may not be the best idea)
  
  Happy coding!

customfileconfig's People

Contributors

xdman500 avatar

Watchers

 avatar  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.