Skip to content

Repository files navigation

DNConfigManagerAPI


Configuration File's Type:

  • Non-Encoded
  • Encoded (In Base64)

Configuration File's class Managers:

  • ConfigManager
  • EncodedConfigManager

Configuration File's class Managers' Methods:

  • loadContent() - Load the Config File content
  • getName() - Return the Config File Name
  • read() - Return the Config File content (Non-Encoded)
  • save() - Save the File (After changing values)
  • writeDefault() - Write "{}" in the file and erase all others data
  • set(String key, Object value) - Write a value in the File (it doesn't save)
  • remove(String key) - Remove a values from the File (it doesn't save)
  • getHashMap(String key) - Return an HashMap<Object,Object> from a key
  • getString(String key) - Return a String from a key
  • getList(String key) - Return a List<Object> from a key
  • getInt(String key) - Return an Integer from a key
  • getFloat(String key) - Return a Float from a key
  • getBoolean(String key) - Return a Boolean from a key


1 - Initializing

To Initialize the API, you just have to create a new instance of the Config Class (fr.benjimania74.configmanager.Config)

newConfig(StringaddonName); // Initialize the API

2 - Create a Config File

You can create Encoded Config's Files and non Encoded Config's Files by getting the Config() instance

Non-Encoded Config File Creation

Config.getInstance().createConfig(Stringname); // name = Config File's Name// THAT RETURN a ConfigManager Instance

Encoded Config File Creation

Config.getInstance().createEncodedConfig(Stringname); // name = Config File's Name// THAT RETURN an EncodedConfigManager Instance

If the Config File is already existing, you will get an instance of it.


3 - Get a Config File

You can get Encoded and Non-Encoded Config File by getting the Config() instance. You can use the name of the file or the File to get it (use the name is recommended)

Get a Non-Encoded Config File

Config.getInstance().getConfig(Stringname);
Config.getInstance().getConfig(Filefile);

Get an Encoded Config File

Config.getInstance().getEncodedConfig(Stringname);
Config.getInstance().getEncodedConfig(Filefile);

4 - Example

importbe.alexandre01.dreamnetwork.api.DNClientAPI;
importbe.alexandre01.dreamnetwork.api.addons.Addon;
importbe.alexandre01.dreamnetwork.api.addons.DreamExtension;
importfr.benjimania74.configmanager.Config;
importfr.benjimania74.configmanager.ConfigManager;
importfr.benjimania74.configmanager.EncodedConfigManager;
publicclassExampleClassextendsDreamExtension {
publicstaticDNClientAPIclientAPI;
@OverridepublicvoidonLoad() {
super.onLoad();
newConfig(getAddon().getDreamyName()); // Initialize the API
}
@Overridepublicvoidstart() {
super.start();
clientAPI = getDnClientAPI();
// Non-Encoded ConfigConfigManagercm = Config.getInstance().createConfig("hello"); // Create "hello" Config Filecm.writeDefault(); // Write "{}"cm.save(); // Save "{}"// Encoded ConfigEncodedConfigManagerecm = Config.getInstance().getEncodedConfig("encoded"); // Get "encoded" Encoded Config Fileecm.set("isEncoded", true); // Set a boolean value in the fileSystem.out.println(ecm.getString("hello")); // Print a String valueecm.save(); // Save the content
}
@Overridepublicvoidstop() {
super.stop();
}
publicExampleClass(Addonaddon) {
super(addon);
}
}

About

DreamNetwork Configuration's Files Manager

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages