Java Code Examples for org.bukkit.configuration.file.YamlConfiguration#loadFromString()
The following examples show how to use
org.bukkit.configuration.file.YamlConfiguration#loadFromString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TSerializer.java From TabooLib with MIT License | 5 votes |
public static <T extends ConfigurationSerializable> T deserializeCS(String s, Class<T> c) { YamlConfiguration y = new YamlConfiguration(); try { y.loadFromString(s); } catch (InvalidConfigurationException var4) { return null; } Object o = y.get("value"); return !c.isInstance(o) ? null : (T) o; }
Example 2
Source File: ConfigurationSerializer.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Nullable public static <T extends ConfigurationSerializable> T deserializeCS(final String s, final Class<T> c) { final YamlConfiguration y = new YamlConfiguration(); try { y.loadFromString(s); } catch (final InvalidConfigurationException e) { return null; } final Object o = y.get("value"); if (!c.isInstance(o)) return null; return (T) o; }
Example 3
Source File: ConfigurationSerializer.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Deprecated @Nullable public static <T extends ConfigurationSerializable> T deserializeCSOld(final String s, final Class<T> c) { final YamlConfiguration y = new YamlConfiguration(); try { y.loadFromString(s.replace("\uFEFF", "\n")); } catch (final InvalidConfigurationException e) { return null; } final Object o = y.get("value"); if (!c.isInstance(o)) return null; return (T) o; }
Example 4
Source File: Utils.java From ShopChest with MIT License | 5 votes |
/** * 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); }
Example 5
Source File: CommentedYaml.java From ScoreboardStats with MIT License | 5 votes |
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()); }
Example 6
Source File: YMLControl.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@Override public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { Validate.notNull(baseName); Validate.notNull(locale); Validate.notNull(format); Validate.notNull(loader); ResourceBundle bundle = null; if (YML_FORMAT.equals(format)) { String bundleName = toBundleName(baseName, locale); String resourceName = toResourceName(bundleName, format); URL url = null; if (mode == LoadingMode.CLASSPATH) { //The mode forces us to load the resource from classpath url = getClass().getResource(classpathDir + resourceName); } else if (mode == LoadingMode.FILE_SYSTEM) { //If we use the file system mode, try to load the resource from file first //and load it from classpath if it fails File resourceFile = new File(localeDir, resourceName); if (resourceFile.exists() && resourceFile.isFile()) { url = resourceFile.toURI().toURL(); } else { url = getClass().getResource(classpathDir + resourceName); } } if (url == null) { return null; } URLConnection connection = url.openConnection(); if (reload) { connection.setUseCaches(false); } InputStream stream = connection.getInputStream(); if (stream != null) { Reader reader = new InputStreamReader(stream, I18N.UTF8_CHARSET); YamlConfiguration config = new YamlConfiguration(); StringBuilder builder; try (BufferedReader bufferedReader = new BufferedReader(reader)) { builder = new StringBuilder(); String read; while ((read = bufferedReader.readLine()) != null) { builder.append(read); builder.append('\n'); } } try { config.loadFromString(builder.toString()); } catch (InvalidConfigurationException e) { throw new InstantiationException(e.getMessage()); } bundle = new YMLResourceBundle(config); } } else { bundle = super.newBundle(baseName, locale, format, loader, reload); } return bundle; }