Помогите Конфиг

Левый

Старожил
Пользователь
Баллы
173
Имя в Minecraft
Lefty
Мне нужно открыть конфиг, чтобы вписывать id предметов, которые будут даваться из сундука-сюрприза.
Правильный ли код:
Код:
public static void save(){
try {
YamlConfiguration cfg = new YamlConfiguration();
File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
if (f.exists()) f.delete();
f.createNewFile();
for (String key : vars.keySet())
cfg.set(key, vars.get(key));
cfg.save(f);
} catch (Exception e){
}
}

public static void load(){
vars.clear();
try {
YamlConfiguration cfg = new YamlConfiguration();
File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
if (!f.exists()) return;
cfg.load(f);
for (String key : cfg.getKeys(true)){
if (!key.contains(".")) continue;
vars.put(key,cfg.getString(key));
}
} catch (Exception e){
}
}
protected void saveCfg(){
getConfig().set("general.language",language);
getConfig().set("general.check-updates",checkUpdates);
getConfig().set("reactions.show-messages-for-actions",actionMsg);
getConfig().set("reactions.center-player-teleport",centerTpCoords);
getConfig().set("reactions.region-recheck-delay",worlduardRecheck);
getConfig().set("reactions.item-hold-recheck-delay",itemHoldRecheck);
getConfig().getInt("reactions.item-wear-recheck-delay",itemWearRecheck);
getConfig().set("reactions.horizontal-pushback-action",horizontalPushback );
getConfig().set("reactions.need-file-update", needUpdate);
getConfig().set("actions.shoot.break-block",Shoot.actionShootBreak);
getConfig().set("actions.shoot.penetrable",Shoot.actionShootThrough);
saveConfig();
}

protected void loadCfg(){
language= getConfig().getString("general.language","english");
checkUpdates = getConfig().getBoolean("general.check-updates",true);
languageSave = getConfig().getBoolean("general.language-save",false);
centerTpCoords = getConfig().getBoolean("reactions.center-player-teleport",true);
actionMsg= getConfig().getString("reactions.show-messages-for-actions","tp,grpadd,grprmv,townset,townkick,itemrmv,itemgive,moneypay,moneygive");
worlduardRecheck = getConfig().getInt("reactions.region-recheck-delay",2);
itemHoldRecheck = getConfig().getInt("reactions.item-hold-recheck-delay",2);
itemWearRecheck = getConfig().getInt("reactions.item-wear-recheck-delay",2);;
horizontalPushback = getConfig().getBoolean("reactions.horizontal-pushback-action", false);
needUpdate= getConfig().getBoolean("reactions.need-file-update", true);
Shoot.actionShootBreak = getConfig().getString("actions.shoot.break-block",Shoot.actionShootBreak);
Shoot.actionShootThrough = getConfig().getString("actions.shoot.penetrable",Shoot.actionShootThrough);
}

public static void save(){
try {
YamlConfiguration cfg = new YamlConfiguration();
File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
if (f.exists()) f.delete();
f.createNewFile();
for (String key : vars.keySet())
cfg.set(key, vars.get(key));
cfg.save(f);
} catch (Exception e){
}
}

public static void load(){
vars.clear();
try {
YamlConfiguration cfg = new YamlConfiguration();
File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
if (!f.exists()) return;
cfg.load(f);
for (String key : cfg.getKeys(true)){
if (!key.contains(".")) continue;
vars.put(key,cfg.getString(key));
}
} catch (Exception e){
}
}
Или что-то не то?
 
выдрал кусок кода из чужого плагина и не понимаешь как он работает?
 
Вот отформатированный текст:
Код:
public static void save(){
    try {
        YamlConfiguration cfg = new YamlConfiguration();
        File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
        if (f.exists()) f.delete();
        f.createNewFile();
        for (String key : vars.keySet())
        cfg.set(key, vars.get(key));
        cfg.save(f);
        } catch (Exception e){
    }
}

public static void load(){
    vars.clear();
    try {
        YamlConfiguration cfg = new YamlConfiguration();
        File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
        if (!f.exists()) return;
        cfg.load(f);
        for (String key : cfg.getKeys(true)){
            if (!key.contains(".")) continue;
            vars.put(key,cfg.getString(key));
        }
        } catch (Exception e){
    }
}
protected void saveCfg(){
    getConfig().set("general.language",language);
    getConfig().set("general.check-updates",checkUpdates);
    getConfig().set("reactions.show-messages-for-actions",actionMsg);
    getConfig().set("reactions.center-player-teleport",centerTpCoords);
    getConfig().set("reactions.region-recheck-delay",worlduardRecheck);
    getConfig().set("reactions.item-hold-recheck-delay",itemHoldRecheck);
    getConfig().getInt("reactions.item-wear-recheck-delay",itemWearRecheck);
    getConfig().set("reactions.horizontal-pushback-action",horizontalPushback );
    getConfig().set("reactions.need-file-update", needUpdate);
    getConfig().set("actions.shoot.break-block",Shoot.actionShootBreak);
    getConfig().set("actions.shoot.penetrable",Shoot.actionShootThrough);
    saveConfig();
}

protected void loadCfg(){
    language= getConfig().getString("general.language","english");
    checkUpdates = getConfig().getBoolean("general.check-updates",true);
    languageSave = getConfig().getBoolean("general.language-save",false);
    centerTpCoords = getConfig().getBoolean("reactions.center-player-teleport",true);
    actionMsg= getConfig().getString("reactions.show-messages-for-actions","tp,grpadd,grprmv,townset,townkick,itemrmv,itemgive,moneypay,moneygive");
    worlduardRecheck = getConfig().getInt("reactions.region-recheck-delay",2);
    itemHoldRecheck = getConfig().getInt("reactions.item-hold-recheck-delay",2);
    itemWearRecheck = getConfig().getInt("reactions.item-wear-recheck-delay",2);;
    horizontalPushback = getConfig().getBoolean("reactions.horizontal-pushback-action", false);
    needUpdate= getConfig().getBoolean("reactions.need-file-update", true);
    Shoot.actionShootBreak = getConfig().getString("actions.shoot.break-block",Shoot.actionShootBreak);
    Shoot.actionShootThrough = getConfig().getString("actions.shoot.penetrable",Shoot.actionShootThrough);
}

public static void save(){
    try {
        YamlConfiguration cfg = new YamlConfiguration();
        File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
        if (f.exists()) f.delete();
        f.createNewFile();
        for (String key : vars.keySet())
        cfg.set(key, vars.get(key));
        cfg.save(f);
        } catch (Exception e){
    }
}

public static void load(){
    vars.clear();
    try {
        YamlConfiguration cfg = new YamlConfiguration();
        File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
        if (!f.exists()) return;
        cfg.load(f);
        for (String key : cfg.getKeys(true)){
            if (!key.contains(".")) continue;
            vars.put(key,cfg.getString(key));
        }
        } catch (Exception e){
    }
}
 
Вот отформатированный текст:
Код:
public static void save(){
    try {
        YamlConfiguration cfg = new YamlConfiguration();
        File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
        if (f.exists()) f.delete();
        f.createNewFile();
        for (String key : vars.keySet())
        cfg.set(key, vars.get(key));
        cfg.save(f);
        } catch (Exception e){
    }
}

public static void load(){
    vars.clear();
    try {
        YamlConfiguration cfg = new YamlConfiguration();
        File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
        if (!f.exists()) return;
        cfg.load(f);
        for (String key : cfg.getKeys(true)){
            if (!key.contains(".")) continue;
            vars.put(key,cfg.getString(key));
        }
        } catch (Exception e){
    }
}
protected void saveCfg(){
    getConfig().set("general.language",language);
    getConfig().set("general.check-updates",checkUpdates);
    getConfig().set("reactions.show-messages-for-actions",actionMsg);
    getConfig().set("reactions.center-player-teleport",centerTpCoords);
    getConfig().set("reactions.region-recheck-delay",worlduardRecheck);
    getConfig().set("reactions.item-hold-recheck-delay",itemHoldRecheck);
    getConfig().getInt("reactions.item-wear-recheck-delay",itemWearRecheck);
    getConfig().set("reactions.horizontal-pushback-action",horizontalPushback );
    getConfig().set("reactions.need-file-update", needUpdate);
    getConfig().set("actions.shoot.break-block",Shoot.actionShootBreak);
    getConfig().set("actions.shoot.penetrable",Shoot.actionShootThrough);
    saveConfig();
}

protected void loadCfg(){
    language= getConfig().getString("general.language","english");
    checkUpdates = getConfig().getBoolean("general.check-updates",true);
    languageSave = getConfig().getBoolean("general.language-save",false);
    centerTpCoords = getConfig().getBoolean("reactions.center-player-teleport",true);
    actionMsg= getConfig().getString("reactions.show-messages-for-actions","tp,grpadd,grprmv,townset,townkick,itemrmv,itemgive,moneypay,moneygive");
    worlduardRecheck = getConfig().getInt("reactions.region-recheck-delay",2);
    itemHoldRecheck = getConfig().getInt("reactions.item-hold-recheck-delay",2);
    itemWearRecheck = getConfig().getInt("reactions.item-wear-recheck-delay",2);;
    horizontalPushback = getConfig().getBoolean("reactions.horizontal-pushback-action", false);
    needUpdate= getConfig().getBoolean("reactions.need-file-update", true);
    Shoot.actionShootBreak = getConfig().getString("actions.shoot.break-block",Shoot.actionShootBreak);
    Shoot.actionShootThrough = getConfig().getString("actions.shoot.penetrable",Shoot.actionShootThrough);
}

public static void save(){
    try {
        YamlConfiguration cfg = new YamlConfiguration();
        File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
        if (f.exists()) f.delete();
        f.createNewFile();
        for (String key : vars.keySet())
        cfg.set(key, vars.get(key));
        cfg.save(f);
        } catch (Exception e){
    }
}

public static void load(){
    vars.clear();
    try {
        YamlConfiguration cfg = new YamlConfiguration();
        File f = new File (ReActions.instance.getDataFolder()+File.separator+"variables.yml");
        if (!f.exists()) return;
        cfg.load(f);
        for (String key : cfg.getKeys(true)){
            if (!key.contains(".")) continue;
            vars.put(key,cfg.getString(key));
        }
        } catch (Exception e){
    }
}
Спасибо, но я уже понял, что этот код мне не подойдёт
 
Назад
Верх