Yamler 0.0.2

Port of famous bukkit/bungee YAML-library

  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice
We welcome you on our site. This site is devoted to the Nukkit project and all that is connected with him. Here you can communicate, download plugins, also many other things get acquainted! Register the account right now :3
Как использовать Yamler API

  1. Создайте класс расширяющий ru.nukkit.yamler.Config
  2. Укажите поля, который будут либо public либо private (недопустимы: final или transient или static)
  3. Опишите конструктор и настройте в нём параметры CONFIG_FILE и CONFIG_HEADER (CONFIG_HEADER необязателен)
  4. Чтобы конфигурация загрузилась воспользуйтесь методом Config.init()
В итоге, у Вас получится класс подобный этому:

Code:
public class Database extends Config {
public Database(Plugin plugin) {
CONFIG_HEADER = new String[]{"Configuration of the Database"};
CONFIG_FILE = new File(plugin.getDataFolder(), "db.yml");
}

@Comments({
"This is the URL of the Database",
"Must be jdbc:<database engine>:<connection parameter>",
"For H2 (which is the default file based DB): jdbc:h2:{DIR}thesuit.db",
"For MySQL: jdbc:mysql://<host>:<port>/<database>"
})
private String Url = "jdbc:h2:{DIR}thesuit.db";

@Comment("The Username which should be used to auth against the Database")
private String Username = "test";

@Comment("The Password for the User")
private String Password = "test";

public String getUrl(){

return this.Url;

}

public String getUsername(){

return this.Username;

}

public String getPassword(){

return this.Password;

}

public void setUrl(String url){

this.Url=url;

}

public void setUsername(String username){

this.Username=username;

}

public void setPassword(String password){

this.Password=password;

}

}
Его можно использовать так:

Code:
Database dbConfig = new Database(this);
if (dbConfig.initConfig()) dbConfig().setUsername ("fromgate");

else this.getLogger().info("Failed to init config!");
И сохранить в файл так:

Code:
  dbConfig.saveConfig();

How to use

If you downloaded a plugin that requires Yamler, you just need to download Yamler too and install it. No permissions, no comands, etc.

Information for plugin developers

  1. Create a Class which extends ru.nukkit.yamler.Config
  2. Create Fields which are either public or private (not final or transient or static)
  3. Create a Constructor and set the CONFIG_FILE and CONFIG_HEADER (CONFIG_HEADER is optional)
  4. To tell the Config to load invoke Config.init()
So you end up having a Config Class like this:

Code:
public class Database extends Config {
public Database(Plugin plugin) {
CONFIG_HEADER = new String[]{"Configuration of the Database"};
CONFIG_FILE = new File(plugin.getDataFolder(), "db.yml");
}

@Comments({
"This is the URL of the Database",
"Must be jdbc:<database engine>:<connection parameter>",
"For H2 (which is the default file based DB): jdbc:h2:{DIR}thesuit.db",
"For MySQL: jdbc:mysql://<host>:<port>/<database>"
})
private String Url = "jdbc:h2:{DIR}thesuit.db";

@Comment("The Username which should be used to auth against the Database")
private String Username = "test";

@Comment("The Password for the User")
private String Password = "test";

public String getUrl(){

return this.Url;

}

public String getUsername(){

return this.Username;

}

public String getPassword(){

return this.Password;

}

public void setUrl(String url){

this.Url=url;

}

public void setUsername(String username){

this.Username=username;

}

public void setPassword(String password){

this.Password=password;

}

}
You can use it with this:

Code:
Database dbConfig = new Database(this);
if (dbConfig.initConfig()) dbConfig().setUsername ("fromgate");

else this.getLogger().info("Failed to init config!");
To save a Config file:

Code:
  dbConfig.saveConfig();