ninja.leaping.configurate.gson.GsonConfigurationLoader Java Examples
The following examples show how to use
ninja.leaping.configurate.gson.GsonConfigurationLoader.
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: ComponentConfigSerializer.java From GriefDefender with MIT License | 6 votes |
@Override public Component deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { if (node.getString() == null || node.getString().isEmpty()) { return TextComponent.empty(); } if (node.getString().contains("text=")) { // Try sponge data StringWriter writer = new StringWriter(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setIndent(0) .setSink(() -> new BufferedWriter(writer)) .setHeaderMode(HeaderMode.NONE) .build(); try { gsonLoader.save(node); } catch (IOException e) { throw new ObjectMappingException(e); } return GsonComponentSerializer.INSTANCE.deserialize(writer.toString()); } return LegacyComponentSerializer.legacy().deserialize(node.getString(), '&'); }
Example #2
Source File: ComponentConfigSerializer.java From GriefDefender with MIT License | 6 votes |
@Override public Component deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { if (node.getString() == null || node.getString().isEmpty()) { return TextComponent.empty(); } if (node.getString().contains("text=")) { // Try sponge data StringWriter writer = new StringWriter(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setIndent(0) .setSink(() -> new BufferedWriter(writer)) .setHeaderMode(HeaderMode.NONE) .build(); try { gsonLoader.save(node); } catch (IOException e) { throw new ObjectMappingException(e); } return GsonComponentSerializer.INSTANCE.deserialize(writer.toString()); } return LegacyComponentSerializer.legacy().deserialize(node.getString(), '&'); }
Example #3
Source File: WebSettings.java From BlueMap with MIT License | 5 votes |
public WebSettings(File settingsFile) throws IOException { if (!settingsFile.exists()) { settingsFile.getParentFile().mkdirs(); settingsFile.createNewFile(); } configLoader = GsonConfigurationLoader.builder() .setFile(settingsFile) .build(); load(); }
Example #4
Source File: ConfigManager.java From BlueMap with MIT License | 5 votes |
private ConfigurationLoader<? extends ConfigurationNode> getLoader(String filename, InputStream is){ BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); if (filename.endsWith(".json")) return GsonConfigurationLoader.builder().setSource(() -> reader).build(); if (filename.endsWith(".yaml") || filename.endsWith(".yml")) return YAMLConfigurationLoader.builder().setSource(() -> reader).build(); else return HoconConfigurationLoader.builder().setSource(() -> reader).build(); }
Example #5
Source File: MarkerAPIImpl.java From BlueMap with MIT License | 5 votes |
@Override public synchronized void save() throws IOException { load(false); GsonConfigurationLoader loader = GsonConfigurationLoader.builder().setFile(markerFile).build(); ConfigurationNode node = loader.createEmptyNode(); for (MarkerSetImpl set : markerSets.values()) { set.save(node.getNode("markerSets").getAppendedNode()); } loader.save(node); removedMarkerSets.clear(); }
Example #6
Source File: ConfigFactory.java From helper with MIT License | 5 votes |
@Nonnull @Override public GsonConfigurationLoader loader(@Nonnull Path path) { GsonConfigurationLoader.Builder builder = GsonConfigurationLoader.builder() .setIndent(2) .setSource(() -> Files.newBufferedReader(path, StandardCharsets.UTF_8)) .setSink(() -> Files.newBufferedWriter(path, StandardCharsets.UTF_8)); builder.setDefaultOptions(builder.getDefaultOptions().setSerializers(TYPE_SERIALIZERS)); return builder.build(); }
Example #7
Source File: JsonLoader.java From LuckPerms with MIT License | 5 votes |
@Override public ConfigurationLoader<? extends ConfigurationNode> loader(Path path) { return GsonConfigurationLoader.builder() .setIndent(2) .setSource(() -> Files.newBufferedReader(path, StandardCharsets.UTF_8)) .setSink(() -> Files.newBufferedWriter(path, StandardCharsets.UTF_8)) .build(); }
Example #8
Source File: ConfigManager.java From BlueMap with MIT License | 4 votes |
private ConfigurationLoader<? extends ConfigurationNode> getLoader(URL url){ if (url.getFile().endsWith(".json")) return GsonConfigurationLoader.builder().setURL(url).build(); if (url.getFile().endsWith(".yaml") || url.getFile().endsWith(".yml")) return YAMLConfigurationLoader.builder().setURL(url).build(); else return HoconConfigurationLoader.builder().setURL(url).build(); }
Example #9
Source File: ConfigManager.java From BlueMap with MIT License | 4 votes |
private ConfigurationLoader<? extends ConfigurationNode> getLoader(File file){ if (file.getName().endsWith(".json")) return GsonConfigurationLoader.builder().setFile(file).build(); if (file.getName().endsWith(".yaml") || file.getName().endsWith(".yml")) return YAMLConfigurationLoader.builder().setFile(file).build(); else return HoconConfigurationLoader.builder().setFile(file).build(); }
Example #10
Source File: ConfigFactory.java From helper with MIT License | 4 votes |
@Nonnull public static ConfigFactory<ConfigurationNode, GsonConfigurationLoader> gson() { return GSON; }