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 Project: GriefDefender   Author: bloodmc   File: ComponentConfigSerializer.java    License: MIT License 6 votes vote down vote up
@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 Project: GriefDefender   Author: bloodmc   File: ComponentConfigSerializer.java    License: MIT License 6 votes vote down vote up
@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 Project: BlueMap   Author: BlueMap-Minecraft   File: WebSettings.java    License: MIT License 5 votes vote down vote up
public WebSettings(File settingsFile) throws IOException {
	
	if (!settingsFile.exists()) {
		settingsFile.getParentFile().mkdirs();
		settingsFile.createNewFile();
	}
	
	configLoader = GsonConfigurationLoader.builder()
			.setFile(settingsFile)
			.build();
	
	load();
}
 
Example #4
Source Project: BlueMap   Author: BlueMap-Minecraft   File: ConfigManager.java    License: MIT License 5 votes vote down vote up
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 Project: BlueMap   Author: BlueMap-Minecraft   File: MarkerAPIImpl.java    License: MIT License 5 votes vote down vote up
@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 Project: helper   Author: lucko   File: ConfigFactory.java    License: MIT License 5 votes vote down vote up
@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 Project: LuckPerms   Author: lucko   File: JsonLoader.java    License: MIT License 5 votes vote down vote up
@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 Project: BlueMap   Author: BlueMap-Minecraft   File: ConfigManager.java    License: MIT License 4 votes vote down vote up
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 Project: BlueMap   Author: BlueMap-Minecraft   File: ConfigManager.java    License: MIT License 4 votes vote down vote up
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 Project: helper   Author: lucko   File: ConfigFactory.java    License: MIT License 4 votes vote down vote up
@Nonnull
public static ConfigFactory<ConfigurationNode, GsonConfigurationLoader> gson() {
    return GSON;
}