cn.nukkit.utils.Config Java Examples

The following examples show how to use cn.nukkit.utils.Config. 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 File: YamlProvider.java    From EconomyAPI with 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 #2
Source File: YamlProvider.java    From EconomyAPI with 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 #3
Source File: CraftingManager.java    From Nukkit with 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 #4
Source File: Item.java    From Nukkit with 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 #5
Source File: PluginBase.java    From Nukkit with 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 #6
Source File: PluginBase.java    From Nukkit with 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 File: PluginBase.java    From Nukkit with 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 File: EssentialsAPI.java    From EssentialsNK with 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 #9
Source File: PluginBase.java    From Nukkit with 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 #10
Source File: PluginBase.java    From Jupiter with 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 #11
Source File: PluginBase.java    From Jupiter with 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 #12
Source File: NukkitConfigAdapter.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public void reload() {
    this.configuration = new Config(this.file, Config.YAML);
}
 
Example #13
Source File: Server.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public Config getConfig() {
    return this.config;
}
 
Example #14
Source File: Plugin.java    From Nukkit with 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 #15
Source File: Plugin.java    From Jupiter with 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 #16
Source File: Server.java    From Jupiter with GNU General Public License v3.0 2 votes vote down vote up
/**
 * OPをコンフィグから取得します。
 * @return Config サーバーのOPメンバー
 */
public Config getOps() {
    return operators;
}
 
Example #17
Source File: Server.java    From Jupiter with GNU General Public License v3.0 2 votes vote down vote up
/**
 * ホワイトリストをコンフィグから取得します。
 * @return Config サーバーのホワイトリストのメンバー
 */
public Config getWhitelist() {
    return whitelist;
}
 
Example #18
Source File: Server.java    From Jupiter with 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 #19
Source File: Server.java    From Jupiter with GNU General Public License v3.0 2 votes vote down vote up
/**
 * server.propertiesのオブジェクト(Config)を取得します。
 * @return Config プロパティーのオブジェクト
 */
public Config getProperties() {
    return this.properties;
}
 
Example #20
Source File: Plugin.java    From Nukkit with 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();