Я хочу добавить новый объект в мой объект "yamlFile" при инициализации.
public yamlFile config = new yamlFile() {
protected ServerGroup GROUP_BELOW_16, GROUP_16, GROUP_17, GROUP_18, GROUP_ABOVE_18;
@Override
public void load() {
super.load();
try {
GROUP_BELOW_16 = Bot.getServergroupById(Bot.getFileManager().getConfigConfiguration().getInt("age.-16"));
GROUP_16 = Bot.getServergroupById(Bot.getFileManager().getConfigConfiguration().getInt("age.16"));
GROUP_17 = Bot.getServergroupById(Bot.getFileManager().getConfigConfiguration().getInt("age.17"));
GROUP_18 = Bot.getServergroupById(Bot.getFileManager().getConfigConfiguration().getInt("age.18"));
GROUP_ABOVE_18 = Bot.getServergroupById(Bot.getFileManager().getConfigConfiguration().getInt("age.+18"));
} catch (final NullPointerException e) {
Bot.getLogger().warning("Path existiert nicht");
e.printStackTrace();
} catch (final Exception e) {
e.printStackTrace();
}
}
}.setFolder("data").setFilename("config.yml").build();
Таким образом, в объекте yamlFile нет объектов "ServerGroup".Поэтому я хочу добавить немного.Поэтому я добавил их при инициализации, но они недоступны из других источников.Поэтому я не могу использовать их в другом методе, таком как:
public void method(){
config.GROUP_16 = null;
}
Мой вопрос: что я должен сделать, чтобы сделать объекты ServerGroup доступными без их реализации в «оригинальном» классе yamlFile?
Оригинальный класс yamlFile:
public class yamlFile {
/**
*
* var methods
*
**/
private String folder;
private String filename;
public String getFolder() {
return folder;
}
public yamlFile setFolder(String folder) {
this.folder = folder;
return this;
}
public String getFilename() {
return filename;
}
public yamlFile setFilename(String filename) {
this.filename = filename;
return this;
}
/**
*
* file methods
*
**/
private File file;
public yamlFile set() {
file = new File(getFolder(), getFilename());
return this;
}
final private YamlConfiguration yamlConfiguration = new YamlConfiguration();
/**
* Checks for the specific file if it exists.
*/
public void fileExists() throws FileNotFoundException {
try {
if (!file.exists()) {
yamlConfiguration.options().copyDefaults(true);
file = new File(getFolder(), getFilename());
yamlConfiguration.save(file);
}
} catch (final NullPointerException e) {
e.printStackTrace();
} catch (final IllegalArgumentException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
}
}
public void load() {
try {
fileExists();
} catch (final FileNotFoundException e) {
Bot.getLogger().info("Creating file: " + getFolder() + "/" + getFilename());
}
try {
yamlConfiguration.load(file);
} catch (final FileNotFoundException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
} catch (final InvalidConfigurationException e) {
e.printStackTrace();
}
}
public void save() {
try {
yamlConfiguration.save(file);
} catch (final IOException e) {
e.printStackTrace();
}
}
public YamlConfiguration getFile() {
return yamlConfiguration;
}
}