All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.carcadex.kotlinbukkitkit.messages.model.impl.serialized.SerializedMessage Maven / Gradle / Ivy

package tech.carcadex.kotlinbukkitkit.messages.model.impl.serialized;

import tech.carcadex.kotlinbukkitkit.messages.model.AbstractMessage;
import tech.carcadex.kotlinbukkitkit.messages.model.Message;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.ComponentSerializer;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.stream.Collectors;

public class SerializedMessage extends AbstractMessage {
    private final ComponentSerializer serializer;
    private final Plugin plugin;

    public SerializedMessage(List unparsed, ComponentSerializer serializer, Plugin plugin) {
        super(unparsed, plugin);
        this.serializer = serializer;
        this.plugin = plugin;
    }

    @Override
    protected Component parse(String unparsed) {
        return serializer.deserialize(unparsed);
    }

    @Override
    public @NotNull Message replaceAll(@NotNull String from, @NotNull String to) {
        return new SerializedMessage(unparsed.stream().map(it -> it.replaceAll(from, to)).collect(Collectors.toList()), serializer, plugin);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy