本文整理了Java中com.avairebot.config.YamlConfiguration
类的一些代码示例,展示了YamlConfiguration
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlConfiguration
类的具体详情如下:
包路径:com.avairebot.config.YamlConfiguration
类名称:YamlConfiguration
[英]An implementation of Configuration which saves all files in Yaml. Note that this implementation is not synchronized.
[中]将所有文件保存在Yaml中的配置实现。请注意,此实现是不同步的。
代码示例来源:origin: avaire/avaire
private void mergeConfiguration(Language language, YamlConfiguration pluginConfig) {
LanguageContainer locale = I18n.getLocale(language);
for (String key : pluginConfig.getKeys(true)) {
if (!locale.getConfig().contains(key)) {
locale.getConfig().set(key, pluginConfig.get(key));
}
}
}
代码示例来源:origin: avaire/avaire
PluginLoader(File file, File dataFolder) throws InvalidPluginException, IOException {
this.file = file;
this.dataFolder = dataFolder;
if (!file.exists()) {
throw new InvalidPluginException(file.getPath() + " does not exists");
}
jarFile = new JarFile(file);
configuration = YamlConfiguration.loadConfiguration(new InputStreamReader(getResource("plugin.yml")));
checkIfPluginYamlIsValid();
if (configuration.contains("authors")) {
authors.addAll(configuration.getStringList("authors"));
} else if (configuration.contains("author")) {
authors.add(configuration.getString("author"));
}
classLoader = new PluginClassLoader(this, AvaIre.class.getClassLoader(), dataFolder, file);
}
代码示例来源:origin: avaire/avaire
/**
* Creates a new {@link YamlConfiguration}, loading from the given reader.
* <p>
* Any errors loading the Configuration will be logged and then ignored.
* If the specified input is not a valid config, a blank config will be
* returned.
*
* @param reader input
* @return resulting configuration
* @throws IllegalArgumentException Thrown if stream is null
*/
public static YamlConfiguration loadConfiguration(Reader reader) {
Validate.notNull(reader, "Stream cannot be null");
YamlConfiguration config = new YamlConfiguration();
try {
config.load(reader);
} catch (IOException ex) {
Configuration.log.warn("Cannot load configuration from stream", ex);
} catch (InvalidConfigurationException ex) {
Configuration.log.warn("Cannot load configuration from stream", ex);
}
return config;
}
代码示例来源:origin: avaire/avaire
/**
* Registers an I18n string, the string will be parsed through the
* {@link YamlConfiguration#loadFromString(String)} methods to be
* parsed to a YAML object, to then be merged with the default
* language file, only keys that doesn't already exists in
* the default language file will be added.
*
* @param language The language that the input stream should be merged with.
* @param yaml The YAML as a string that should be parsed and merged with the given language.
* @throws InvalidConfigurationException Thrown if the given string can not be parsed correctly to a YAML object.
*/
public final void registerI18n(Language language, @Nonnull String yaml) throws InvalidConfigurationException {
YamlConfiguration pluginConfig = new YamlConfiguration();
pluginConfig.loadFromString(yaml);
mergeConfiguration(language, pluginConfig);
}
代码示例来源:origin: avaire/avaire
/**
* Gets the version of the plugin.
*
* @return The version of the plugin.
*/
public String getVersion() {
return configuration.getString("version");
}
代码示例来源:origin: avaire/avaire
private void checkIfPluginYamlIsValid() throws InvalidPluginException {
if (!configuration.contains("name")) {
throw new InvalidPluginException(file.getName() + ": Invalid plugin.yml file, the plugin must have a name value at root!");
}
if (!configuration.contains("main")) {
throw new InvalidPluginException(getName() + ": Invalid plugin.yml file, the plugin must have a main value at root!");
}
if (!configuration.contains("version")) {
throw new InvalidPluginException(getName() + ": Invalid plugin.yml file, the plugin must have a version value at root!");
}
if (configuration.contains("requires") && !compareVersion(configuration.getString("requires"))) {
throw new InvalidPluginException(getName() + ": Invalid plugin.yml file, the plugin requires AvaIre version %s or higher to work correctly!",
configuration.getString("requires")
);
}
}
代码示例来源:origin: avaire/avaire
@Override
public void loadFromString(String contents) throws InvalidConfigurationException {
Validate.notNull(contents, "Contents cannot be null");
Map<?, ?> input;
try {
input = (Map<?, ?>) yaml.load(contents);
} catch (YAMLException e) {
throw new InvalidConfigurationException(e);
} catch (ClassCastException e) {
throw new InvalidConfigurationException("Top level is not a Map.");
}
String header = parseHeader(contents);
if (header.length() > 0) {
options().header(header);
}
if (input != null) {
convertMapsToSections(input, this);
}
}
代码示例来源:origin: avaire/avaire
@Override
public String saveToString() {
yamlOptions.setIndent(options().indent());
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
yamlOptions.setAllowUnicode(systemUTF);
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
String header = buildHeader();
String dump = yaml.dump(getValues(false));
if (dump.equals(BLANK_CONFIG)) {
dump = "";
}
return header + dump;
}
代码示例来源:origin: avaire/avaire
@Override
public boolean onCommand(CommandMessage context, String[] args) {
if (args.length == 0) {
return sendErrorMessage(context, context.i18n("mustIncludeQuestion"));
}
String answers = context.getI18nCommandPrefix() + ".answers";
// Loads the answers from the selected i18n file
if (context.getI18n().contains(answers) && context.getI18n().isList(answers)) {
return sendAnswerFromList(context, context.getI18n().getStringList(answers));
}
// Tries to load the answers from the default i18n file instead
if (I18n.getDefaultLanguage().getConfig().contains(answers) && I18n.getDefaultLanguage().getConfig().isList(answers)) {
return sendAnswerFromList(context, I18n.getDefaultLanguage().getConfig().getStringList(answers));
}
// Sends the default list
return sendAnswerFromList(context, this.answers);
}
代码示例来源:origin: avaire/avaire
@Override
public String buildHeader() {
String header = options().header();
if (options().copyHeader()) {
ConfigurationBase def = getDefaults();
if ((def != null) && (def instanceof FileConfiguration)) {
FileConfiguration filedefaults = (FileConfiguration) def;
String defaultsHeader = filedefaults.buildHeader();
if ((defaultsHeader != null) && (defaultsHeader.length() > 0)) {
return defaultsHeader;
}
}
}
if (header == null) {
return "";
}
StringBuilder builder = new StringBuilder();
String[] lines = header.split("\r?\n", -1);
boolean startedHeader = false;
for (int i = lines.length - 1; i >= 0; i--) {
builder.insert(0, "\n");
if ((startedHeader) || (lines[i].length() != 0)) {
builder.insert(0, lines[i]);
builder.insert(0, COMMENT_PREFIX);
startedHeader = true;
}
}
return builder.toString();
}
代码示例来源:origin: avaire/avaire
private Set<String> getKeys(LanguageContainer locale) {
return locale.getConfig().getKeys(true);
}
}
代码示例来源:origin: avaire/avaire
private void convertMapsToSections(Map<?, ?> input, ConfigurationSection section) {
for (Map.Entry<?, ?> entry : input.entrySet()) {
String key = entry.getKey().toString();
Object value = entry.getValue();
if (value instanceof Map) {
convertMapsToSections((Map<?, ?>) value, section.createSection(key));
} else {
section.set(key, value);
}
}
}
代码示例来源:origin: avaire/avaire
private String loadRandomLevelupMessage(GuildTransformer guild, boolean hasLevelupRole) {
return (String) RandomUtil.pickRandom(
I18n.getLocale(guild).getConfig().getStringList(hasLevelupRole ? "levelupRoleMessages" : "levelupMessages")
);
}
代码示例来源:origin: avaire/avaire
/**
* Gets the full class package path to the main class for the plugin.
*
* @return The full class package path to th main class for the plugin.
*/
public String getMain() {
return configuration.getString("main");
}
代码示例来源:origin: avaire/avaire
@Override
@CheckReturnValue
public String i18nRaw(@Nonnull String key) {
if (getI18n().contains(key)) {
return getI18n().getString(key)
.replace("\\n", "\n")
.replace("\\t", "\t");
} else {
log.warn("Missing language entry for key {} in language {}", key, I18n.getLocale(getGuild()).getLanguage().getCode());
return I18n.getDefaultLanguage().getConfig().getString(key)
.replace("\\n", "\n")
.replace("\\t", "\t");
}
}
代码示例来源:origin: avaire/avaire
/**
* Gets the name of the plugin.
*
* @return The name of the plugin.
*/
public String getName() {
return configuration.getString("name");
}
代码示例来源:origin: avaire/avaire
/**
* Creates a new {@link YamlConfiguration}, loading from the given file.
* <p>
* Any errors loading the Configuration will be logged and then ignored.
* If the specified input is not a valid config, a blank config will be
* returned.
* <p>
* The encoding used may follow the system dependent default.
*
* @param file Input file
* @return Resulting configuration
* @throws IllegalArgumentException Thrown if file is null
*/
public static YamlConfiguration loadConfiguration(File file) {
Validate.notNull(file, "File cannot be null");
YamlConfiguration config = new YamlConfiguration();
try {
config.load(file);
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
Configuration.log.warn("Cannot load " + file, ex);
} catch (InvalidConfigurationException ex) {
Configuration.log.warn("Cannot load " + file, ex);
}
return config;
}
代码示例来源:origin: avaire/avaire
/**
* Gets the description of the plugin.
*
* @return Possibly-null, the description of the plugin.
*/
@Nullable
public String getDescription() {
return configuration.getString("description");
}
代码示例来源:origin: avaire/avaire
/**
* Gets the given string from the guilds selected language, if not string
* was found for the guilds selected language, the default language
* will be used instead, if no matches was found there either,
* then <code>NULL</code> will be returned instead.
*
* @param guild The JDA guild instance that should be used for loading the language.
* @param string The string that should be loaded from the language files.
* @return The language string from the given guilds selected language, or the default
* language if it doesn't exists in the guilds selected language, or
* <code>NULL</code> if it doesn't exist anywhere.
*/
@Nullable
public static String getString(@Nullable Guild guild, String string) {
if (string == null) {
return null;
}
return get(guild).getString(string, defaultLanguage.getConfig().getString(string, null));
}
代码示例来源:origin: avaire/avaire
.getConfig().getString("music.internal.endedDueToInactivity", "The music has ended due to inactivity."))
.queue();
内容来源于网络,如有侵权,请联系作者删除!