Помогите StringList

EugeneRu

Новичок
Пользователь
Баллы
11
Как отправить игроку несколько строк сообщений которые указаны в конфиге.
Например вот так:
Test:
Test1:
1 - 'a'
2 - 'b'
3 - 'c'
 
Хех когда смотришь чей то код вроде все так просто, а вот когда сам что то питаешься за кодить а оно ничего не получается
 
Хех когда смотришь чей то код вроде все так просто, а вот когда сам что то питаешься за кодить а оно ничего не получается
Ибо нужно юзать фишки для людей.
YamConfig<Tests> cfg = new YamConfig<Tests>(this.plugin, "config", new Tests());
cfg.get()//TODO гетеры сетеры нашего объекта.
cfg.save();//Сохраняем обратно в файл.
Код:
package Example;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.bukkit.plugin.java.JavaPlugin;

import com.esotericsoftware.yamlbeans.YamlReader;
import com.esotericsoftware.yamlbeans.YamlWriter;

public class YamConfig<T> {
    private T t;
    private File file;

    public static boolean exist(JavaPlugin plugin, String name) {
        return new File(plugin.getDataFolder(), name + ".yml").exists();
    }

    public YamConfig(JavaPlugin plugin, String name, T o) {
        this.t = o;
        this.file = new File(plugin.getDataFolder(), name + ".yml");
        load();
    }

    private void load() {
        try {
            YamlReader reader = new YamlReader(new FileReader(this.file));
            this.t = (T) reader.read(this.t.getClass());
        } catch (Exception e) {
            try {
                this.t = (T) this.t.getClass().newInstance();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }

    public void save() {
        try {
            YamlWriter writer = new YamlWriter(new FileWriter(this.file));
            writer.getConfig().writeConfig.setWriteRootTags(false);
            writer.write(this.t);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public T get() {
        return this.t;
    }
}
 
Ибо нужно юзать фишки для людей.
YamConfig<Tests> cfg = new YamConfig<Tests>(this.plugin, "config", new Tests());
cfg.get()//TODO гетеры сетеры нашего объекта.
cfg.save();//Сохраняем обратно в файл.
Код:
package Example;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.bukkit.plugin.java.JavaPlugin;

import com.esotericsoftware.yamlbeans.YamlReader;
import com.esotericsoftware.yamlbeans.YamlWriter;

public class YamConfig<T> {
    private T t;
    private File file;

    public static boolean exist(JavaPlugin plugin, String name) {
        return new File(plugin.getDataFolder(), name + ".yml").exists();
    }

    public YamConfig(JavaPlugin plugin, String name, T o) {
        this.t = o;
        this.file = new File(plugin.getDataFolder(), name + ".yml");
        load();
    }

    private void load() {
        try {
            YamlReader reader = new YamlReader(new FileReader(this.file));
            this.t = (T) reader.read(this.t.getClass());
        } catch (Exception e) {
            try {
                this.t = (T) this.t.getClass().newInstance();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }

    public void save() {
        try {
            YamlWriter writer = new YamlWriter(new FileWriter(this.file));
            writer.getConfig().writeConfig.setWriteRootTags(false);
            writer.write(this.t);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public T get() {
        return this.t;
    }
}
Я кажется не так понял, но это же:
YamlConfiguration.load(file);
YamlConfiguration.save(file);
Нет?
 
PHP:
List<String> messages = config.getStringList("test.test1");
messages.forEach(player::sendMessage);
Будет работать, наверно
 
Назад
Верх