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

top.hendrixshen.magiclib.util.MessageUtil Maven / Gradle / Ivy

There is a newer version: 0.7.398+fe2125a-beta
Show newest version
package top.hendrixshen.magiclib.util;

import net.minecraft.class_2168;
import net.minecraft.class_2554;
import net.minecraft.class_2561;
import net.minecraft.class_2874;
import net.minecraft.server.MinecraftServer;
import org.jetbrains.annotations.NotNull;
import top.hendrixshen.magiclib.MagicLibReference;
import top.hendrixshen.magiclib.compat.minecraft.api.network.chat.ComponentCompatApi;

import java.util.List;
import java.util.Optional;

public class MessageUtil {
    public static void sendMessage(class_2168 source, String message) {
        MessageUtil.sendMessage(source, ComponentCompatApi.literal(message));
    }

    public static void sendMessage(class_2168 source, class_2561 messages) {
        //#if MC > 11904
        //$$ Optional.ofNullable(source).ifPresent(sourceStack -> sourceStack.sendSuccess(() -> messages, source.getServer().getLevel(Level.OVERWORLD) != null));
        //#elseif MC > 11502
        //$$ Optional.ofNullable(source).ifPresent(sourceStack -> sourceStack.sendSuccess(messages, source.getServer().getLevel(Level.OVERWORLD) != null));
        //#else
        Optional.ofNullable(source).ifPresent(sourceStack -> sourceStack.method_9226(messages, source.method_9211() != null && source.method_9211().method_3847(class_2874.field_13072) != null));
        //#endif
    }

    public static void sendMessage(class_2168 source, @NotNull List messages) {
        class_2554 mutableComponent = ComponentCompatApi.literal("");
        messages.forEach(mutableComponent::method_10852);
        MessageUtil.sendMessage(source, mutableComponent);
    }

    public static void sendServerMessage(MinecraftServer server, String message) {
        MessageUtil.sendServerMessage(server, ComponentCompatApi.literal(message));
    }

    public static void sendServerMessage(MinecraftServer server, class_2561 message) {
        Optional.of(server).ifPresent(s -> {
            MagicLibReference.getLogger().info(message.getString());
            s.method_3760().method_14571().forEach(p ->
                    //#if MC > 11802
                    //$$ p.sendSystemMessage(message));
                    //#elseif MC > 11502
                    //$$ p.sendMessage(message, p.getUUID()));
                    //#else
                    p.method_9203(message));
                    //#endif
        });
    }

    public static void sendServerMessage(MinecraftServer server, @NotNull List component) {
        class_2554 mutableComponent = ComponentCompatApi.literal("");
        component.forEach(mutableComponent::method_10852);
        MessageUtil.sendServerMessage(server, mutableComponent);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy