de.eldoria.jacksonbukkit.deserializer.ComponentMiniMessageDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of paper Show documentation
Show all versions of paper Show documentation
Module for serialization on Paper based servers
The newest version!
/*
* SPDX-License-Identifier: MIT
*
* Copyright (C) EldoriaRPG Team and Contributor
*/
package de.eldoria.jacksonbukkit.deserializer;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import de.eldoria.jacksonbukkit.util.PaperFeatures;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import java.io.IOException;
import java.util.function.UnaryOperator;
/**
* Class for deserialization of {@link Component} using {@link MiniMessage}.
*/
public class ComponentMiniMessageDeserializer extends ComponentGsonDeserializer {
private final MiniMessage miniMessage;
/**
* Creates a new serializer
*
* @param miniMessage MiniMessage instance to use
*/
public ComponentMiniMessageDeserializer(MiniMessage miniMessage) {
this.miniMessage = miniMessage;
}
/**
* Creates a new serializer
*/
public ComponentMiniMessageDeserializer() {
if (PaperFeatures.HAS_COMPONENT_COMPACT) {
miniMessage = MiniMessage.builder().build();
} else {
miniMessage = MiniMessage.builder().postProcessor(UnaryOperator.identity()).build();
}
}
@Override
public Component deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
JsonNode tree = ctxt.readTree(p);
if (tree.isObject()) return parseObjectTree(tree, ctxt);
return miniMessage.deserialize(ctxt.readValue(p, String.class));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy