org.bukkit.configuration.file.YamlConfiguration.loadFromString()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.bukkit.configuration.file.YamlConfiguration.loadFromString()方法的一些代码示例,展示了YamlConfiguration.loadFromString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlConfiguration.loadFromString()方法的具体详情如下:
包路径:org.bukkit.configuration.file.YamlConfiguration
类名称:YamlConfiguration
方法名:loadFromString

YamlConfiguration.loadFromString介绍

暂无

代码示例

代码示例来源:origin: Bukkit/Bukkit

defConfig.loadFromString(text);
} catch (final InvalidConfigurationException e) {
  getLogger().log(Level.SEVERE, "Cannot load configuration from jar", e);

代码示例来源:origin: games647/ScoreboardStats

private void load(Iterable<String> lines, YamlConfiguration newConf) throws InvalidConfigurationException {
  StringBuilder builder = new StringBuilder();
  for (String line : lines) {
    //remove the silly tab error from yaml
    builder.append(line.replace("\t", "    "));
    //indicates a new line
    builder.append('\n');
  }
  newConf.loadFromString(builder.toString());
}

代码示例来源:origin: libraryaddict/LibsDisguises

public static YamlConfiguration getPluginYaml(ClassLoader loader) {
  try (InputStream stream = loader.getResourceAsStream("plugin.yml")) {
    YamlConfiguration config = new YamlConfiguration();
    config.loadFromString(IOUtils.toString(stream, "UTF-8"));
    return config;
  }
  catch (IOException | InvalidConfigurationException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: EpicEricEE/ShopChest

/**
 * Decodes an {@link ItemStack} from a Base64 String
 * @param string Base64 encoded String to decode
 * @return Decoded {@link ItemStack}
 */
public static ItemStack decode(String string) {
  YamlConfiguration config = new YamlConfiguration();
  try {
    config.loadFromString(new String(Base64.getDecoder().decode(string), StandardCharsets.UTF_8));
  } catch (IllegalArgumentException | InvalidConfigurationException e) {
    e.printStackTrace();
    return null;
  }
  return config.getItemStack("i", null);
}

代码示例来源:origin: Bkm016/TabooLib

public static YamlConfiguration loadYaml(Plugin plugin, File file) {
  YamlConfiguration configuration = new YamlConfiguration();
  try {
    String yaml = Files.toString(file, Charset.forName("utf-8"));
    configuration.loadFromString(yaml);
    return configuration;
  } catch (Exception e) {
    TLocale.Logger.error("FILE-UTILS.FAIL-LOAD-CONFIGURATION", plugin.getName(), file.getName());
  }
  return configuration;
}

代码示例来源:origin: Bkm016/TabooLib

private static YamlConfiguration getLocaleAtStream(Plugin plugin, File localeFile) {
  InputStream localeInputSteam = FileUtils.getResource(plugin, "lang/" + localeFile.getName());
  try {
    String yamlText = new String(IO.readFully(localeInputSteam), Charset.forName("utf-8"));
    YamlConfiguration yaml = new YamlConfiguration();
    yaml.loadFromString(yamlText);
    return yaml;
  } catch (Exception ignored) {
    return null;
  }
}

代码示例来源:origin: Bkm016/TabooLib

private TLib() {
  libsFolder = new File(Main.getInst().getDataFolder(), "/libs");
  if (!libsFolder.exists()) {
    libsFolder.mkdirs();
  }
  try {
    String yamlText = new String(IO.readFully(FileUtils.getResource("lang/internal.yml")), Charset.forName("utf-8"));
    internalLanguage = new YamlConfiguration();
    internalLanguage.loadFromString(yamlText);
  } catch (IOException | InvalidConfigurationException ignored) {
  }
}

代码示例来源:origin: elBukkit/MagicPlugin

public static ItemStack getReplacement(ItemStack itemStack) {
  String serialized = getMetaString(itemStack, "replacement");
  if (serialized == null || serialized.isEmpty()) {
    return null;
  }
  YamlConfiguration configuration = new YamlConfiguration();
  ItemStack replacement = null;
  try {
    configuration.loadFromString(serialized);
    replacement = configuration.getItemStack("item");
  } catch (Exception ex) {
    ex.printStackTrace();
  }
  return replacement;
}

代码示例来源:origin: garbagemule/MobArena

private static void process(Plugin plugin, String resource, ConfigurationSection section, boolean addOnlyIfEmpty, boolean removeObsolete) {
  YamlConfiguration defaults = resourceCache.computeIfAbsent(resource, res -> {
    InputStream is = plugin.getResource("res/" + res);
    if (is == null) {
      throw new IllegalStateException("Couldn't read " + res + " from jar, please re-install MobArena");
    }
    Scanner scanner = new Scanner(is).useDelimiter("\\A");
    if (!scanner.hasNext()) {
      throw new IllegalStateException("No content in " + res + " in jar, please re-install MobArena");
    }
    String contents = scanner.next();
    YamlConfiguration yaml = new YamlConfiguration();
    try {
      yaml.loadFromString(contents);
      return yaml;
    } catch (InvalidConfigurationException e) {
      throw new IllegalStateException("Invalid contents in " + res + " in jar, please re-install MobArena", e);
    }
  });
  boolean modified = process(defaults, section, addOnlyIfEmpty, removeObsolete);
  if (modified) {
    plugin.saveConfig();
  }
}

代码示例来源:origin: sgtcaze/NametagEdit

@Override
public void loadFromString(String contents) throws InvalidConfigurationException {
  if (!loadHeaders) {
    super.loadFromString(contents);
    return;
  super.loadFromString(memoryData.toString());

代码示例来源:origin: SpigotMC/Spigot-API

defConfig.loadFromString(text);
} catch (final InvalidConfigurationException e) {
  getLogger().log(Level.SEVERE, "Cannot load configuration from jar", e);

代码示例来源:origin: SkyWars/SkyWars

config.loadFromString(builder.toString());
} catch (InvalidConfigurationException ex) {
  throw new SkyConfigurationException("Couldn't load internal translation yaml file " + file, ex);

代码示例来源:origin: elBukkit/MagicPlugin

@Override
public void load(DataKey data) {
  super.load(data);
  spellKey = data.getString("spell", null);
  npcCaster = data.getBoolean("caster", false);
  targetPlayer = data.getBoolean("target_player", true);
  messagePlayer = data.getBoolean("message_player", false);
  String parameterString = data.getString("parameters", null);
  parameters = new YamlConfiguration();
  if (parameterString != null && !parameterString.isEmpty()) {
    if (!parameterString.contains(":")) {
      String[] simple = StringUtils.split(parameterString, ' ');
      if (simple.length > 0) {
        ConfigurationUtils.addParameters(simple, parameters);
      }
    } else {
      try {
        parameters.loadFromString(parameterString);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
}

代码示例来源:origin: bergerkiller/BKCommonLib

this.getSource().loadFromString(builder.toString());
} catch (InvalidConfigurationException e) {
  throw new IOException("YAML file is corrupt", e);

代码示例来源:origin: NyaaCat/RPGItems-reloaded

itemStorage = new YamlConfiguration();
  String str = new String(data, StandardCharsets.UTF_8);
  itemStorage.loadFromString(str);
} catch (IOException | InvalidConfigurationException e) {
  plugin.getLogger().log(Level.SEVERE, "Error opening " + f.getPath(), e);

代码示例来源:origin: BigScary/GriefPrevention

yaml.loadFromString(input);

代码示例来源:origin: NyaaCat/RPGItems-reloaded

try {
  itemStorage.set("id", null);
  itemStorage.loadFromString(v);
  String origin = itemStorage.getString("name");
  int uid = itemStorage.getInt("uid");

相关文章