Java Code Examples for cn.nukkit.utils.Config

The following examples show how to use cn.nukkit.utils.Config. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Nukkit   Source File: Item.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static void initCreativeItems() {
    clearCreativeItems();

    Config config = new Config(Config.YAML);
    config.load(Server.class.getClassLoader().getResourceAsStream("creativeitems.json"));
    List<Map> list = config.getMapList("items");

    for (Map map : list) {
        try {
            addCreativeItem(fromJson(map));
        } catch (Exception e) {
            MainLogger.getLogger().logException(e);
        }
    }
}
 
Example 2
Source Project: Nukkit   Source File: CraftingManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
public CraftingManager() {
    InputStream recipesStream = Server.class.getClassLoader().getResourceAsStream("recipes.json");
    if (recipesStream == null) {
        throw new AssertionError("Unable to find recipes.json");
    }

    Config recipesConfig = new Config(Config.JSON);
    recipesConfig.load(recipesStream);
    this.loadRecipes(recipesConfig);

    String path = Server.getInstance().getDataPath() + "custom_recipes.json";
    File filePath = new File(path);

    if (filePath.exists()) {
        Config customRecipes = new Config(filePath, Config.JSON);
        this.loadRecipes(customRecipes);
    }
    this.rebuildPacket();

    MainLogger.getLogger().info("Loaded " + this.recipes.size() + " recipes.");
}
 
Example 3
Source Project: EconomyAPI   Source File: YamlProvider.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "serial" })
public void init(File path){
	file = new Config(new File(path, "Money.yml"), Config.YAML, new LinkedHashMap<String, Object>(){
		{
			put("version" , 2);
			put("money", new LinkedHashMap<String, Double>());
		}
	});
	
	LinkedHashMap<Object, Object> temp = (LinkedHashMap<Object, Object>) file.get("money");
	
	data = new LinkedHashMap<>();
	temp.forEach((key, money) -> {
		String username = key.toString();
		
		if(money instanceof Integer){
			data.put(username, ((Integer) money).doubleValue());
		}else if(money instanceof Double){
			data.put(username, (Double) money);
		}else if(money instanceof String){
			data.put(username, Double.parseDouble(money.toString()));
		}
	});
}
 
Example 4
Source Project: EconomyAPI   Source File: YamlProvider.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "serial" })
public void init(File path){
	file = new Config(new File(path, "Money.yml"), Config.YAML, new LinkedHashMap<String, Object>(){
		{
			put("version" , 2);
			put("money", new LinkedHashMap<String, Double>());
		}
	});
	
	LinkedHashMap<Object, Object> temp = (LinkedHashMap<Object, Object>) file.get("money");
	
	data = new LinkedHashMap<>();
	temp.forEach((key, money) -> {
		String username = key.toString();
		
		if(money instanceof Integer){
			data.put(username, ((Integer) money).doubleValue());
		}else if(money instanceof Double){
			data.put(username, (Double) money);
		}else if(money instanceof String){
			data.put(username, Double.parseDouble(money.toString()));
		}
	});
}
 
Example 5
Source Project: Jupiter   Source File: PluginBase.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public Config getConfig() {
    if (this.config == null) {
        this.reloadConfig();
    }
    return this.config;
}
 
Example 6
Source Project: Jupiter   Source File: PluginBase.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void reloadConfig() {
    this.config = new Config(this.configFile);
    InputStream configStream = this.getResource("config.yml");
    if (configStream != null) {
        DumperOptions dumperOptions = new DumperOptions();
        dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        Yaml yaml = new Yaml(dumperOptions);
        try {
            this.config.setDefault(yaml.loadAs(Utils.readFile(this.configFile), LinkedHashMap.class));
        } catch (IOException e) {
            Server.getInstance().getLogger().logException(e);
        }
    }
}
 
Example 7
Source Project: Nukkit   Source File: PluginBase.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public Config getConfig() {
    if (this.config == null) {
        this.reloadConfig();
    }
    return this.config;
}
 
Example 8
Source Project: Nukkit   Source File: PluginBase.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void reloadConfig() {
    this.config = new Config(this.configFile);
    InputStream configStream = this.getResource("config.yml");
    if (configStream != null) {
        DumperOptions dumperOptions = new DumperOptions();
        dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        Yaml yaml = new Yaml(dumperOptions);
        try {
            this.config.setDefault(yaml.loadAs(Utils.readFile(this.configFile), LinkedHashMap.class));
        } catch (IOException e) {
            Server.getInstance().getLogger().logException(e);
        }
    }
}
 
Example 9
Source Project: EssentialsNK   Source File: EssentialsAPI.java    License: GNU General Public License v3.0 5 votes vote down vote up
public EssentialsAPI(EssentialsNK plugin) {
    instance = this;
    this.plugin = plugin;
    this.homeConfig = new Config(new File(plugin.getDataFolder(), "home.yml"), Config.YAML);
    this.warpConfig = new Config(new File(plugin.getDataFolder(), "warp.yml"), Config.YAML);
    this.muteConfig = new Config(new File(plugin.getDataFolder(), "mute.yml"), Config.YAML);
}
 
Example 10
Source Project: Nukkit   Source File: PluginBase.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public Config getConfig() {
    if (this.config == null) {
        this.reloadConfig();
    }
    return this.config;
}
 
Example 11
Source Project: Nukkit   Source File: PluginBase.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void reloadConfig() {
    this.config = new Config(this.configFile);
    InputStream configStream = this.getResource("config.yml");
    if (configStream != null) {
        DumperOptions dumperOptions = new DumperOptions();
        dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        Yaml yaml = new Yaml(dumperOptions);
        try {
            this.config.setDefault(yaml.loadAs(Utils.readFile(this.configFile), LinkedHashMap.class));
        } catch (IOException e) {
            Server.getInstance().getLogger().logException(e);
        }
    }
}
 
Example 12
Source Project: Jupiter   Source File: Server.java    License: GNU General Public License v3.0 4 votes vote down vote up
public Config getConfig() {
    return this.config;
}
 
Example 13
Source Project: LuckPerms   Source File: NukkitConfigAdapter.java    License: MIT License 4 votes vote down vote up
@Override
public void reload() {
    this.configuration = new Config(this.file, Config.YAML);
}
 
Example 14
Source Project: Jupiter   Source File: Plugin.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * 返回这个Nukkit插件配置文件的{@link cn.nukkit.utils.Config}对象。<br>
 * The config file this Nukkit plugin as a {@link cn.nukkit.utils.Config} object.
 * <p>
 * <p>一般地,插件的配置保存在数据文件夹下的config.yml文件。<br>
 * Normally, the plugin config is saved in the 'config.yml' file in its data folder.</p>
 *
 * @return 插件的配置文件。<br>The configuration of this plugin.
 * @see cn.nukkit.plugin.Plugin#getDataFolder
 * @since Nukkit 1.0 | Nukkit API 1.0.0
 */
Config getConfig();
 
Example 15
Source Project: Jupiter   Source File: Server.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * server.propertiesのオブジェクト(Config)を取得します。
 * @return Config プロパティーのオブジェクト
 */
public Config getProperties() {
    return this.properties;
}
 
Example 16
Source Project: Jupiter   Source File: Server.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * jupiter.ymlのオブジェクト(Config)を取得します。
 * @return Config jupiter.ymlのオブジェクト
 */
public Config getJupiterConfig(){
    return new Config(this.getDataPath() + "jupiter.yml");
}
 
Example 17
Source Project: Jupiter   Source File: Server.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * ホワイトリストをコンフィグから取得します。
 * @return Config サーバーのホワイトリストのメンバー
 */
public Config getWhitelist() {
    return whitelist;
}
 
Example 18
Source Project: Jupiter   Source File: Server.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * OPをコンフィグから取得します。
 * @return Config サーバーのOPメンバー
 */
public Config getOps() {
    return operators;
}
 
Example 19
Source Project: Nukkit   Source File: Plugin.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * 返回这个Nukkit插件配置文件的{@link cn.nukkit.utils.Config}对象。<br>
 * The config file this Nukkit plugin as a {@link cn.nukkit.utils.Config} object.
 *
 * <p>一般地,插件的配置保存在数据文件夹下的config.yml文件。<br>
 * Normally, the plugin config is saved in the 'config.yml' file in its data folder.</p>
 *
 * @return 插件的配置文件。<br>The configuration of this plugin.
 * @see cn.nukkit.plugin.Plugin#getDataFolder
 * @since Nukkit 1.0 | Nukkit API 1.0.0
 */
Config getConfig();
 
Example 20
Source Project: Nukkit   Source File: Plugin.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * 返回这个Nukkit插件配置文件的{@link cn.nukkit.utils.Config}对象。<br>
 * The config file this Nukkit plugin as a {@link cn.nukkit.utils.Config} object.
 * <p>
 * <p>一般地,插件的配置保存在数据文件夹下的config.yml文件。<br>
 * Normally, the plugin config is saved in the 'config.yml' file in its data folder.</p>
 *
 * @return 插件的配置文件。<br>The configuration of this plugin.
 * @see cn.nukkit.plugin.Plugin#getDataFolder
 * @since Nukkit 1.0 | Nukkit API 1.0.0
 */
Config getConfig();