top.hendrixshen.magiclib.util.minecraft.MessageUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magiclib-minecraft-api-1.19.3-fabric Show documentation
Show all versions of magiclib-minecraft-api-1.19.3-fabric Show documentation
Unleash magic into Minecraft, infuse souls, ascend to heaven!
package top.hendrixshen.magiclib.util.minecraft;
import org.jetbrains.annotations.NotNull;
import top.hendrixshen.magiclib.api.compat.minecraft.UtilCompat;
import top.hendrixshen.magiclib.api.compat.minecraft.network.chat.ComponentCompat;
import top.hendrixshen.magiclib.impl.minecraft.MagicLibMinecraft;
import top.hendrixshen.magiclib.util.collect.ValueContainer;
import java.util.Collection;
import net.minecraft.class_2168;
import net.minecraft.class_2561;
public class MessageUtil {
private static void sendMessage0(class_2168 source, class_2561 messages, boolean broadcastToAdmins) {
ValueContainer.ofNullable(source).ifPresent(sourceStack ->
sourceStack.method_9226(
//#if MC > 11904
//$$ () -> messages,
//#else
messages,
//#endif
broadcastToAdmins
));
}
public static void sendMessage(class_2168 source, String message, boolean broadcastToAdmins) {
MessageUtil.sendMessageCompat(source, ComponentCompat.literal(message), broadcastToAdmins);
}
public static void sendMessage(class_2168 source, class_2561 message, boolean broadcastToAdmins) {
MessageUtil.sendMessage0(source, message, broadcastToAdmins);
}
public static void sendMessageCompat(class_2168 source, @NotNull ComponentCompat message,
boolean broadcastToAdmins) {
MessageUtil.sendMessage0(source, message.get(), broadcastToAdmins);
}
public static void sendMessage(class_2168 source, String message) {
MessageUtil.sendMessage(source, message, false);
}
public static void sendMessage(class_2168 source, @NotNull class_2561 message) {
MessageUtil.sendMessage0(source, message, false);
}
public static void sendMessageCompat(class_2168 source, @NotNull ComponentCompat message) {
MessageUtil.sendMessage0(source, message.get(), false);
}
public static void sendMessage(class_2168 source, @NotNull Collection messages,
boolean broadcastToAdmins) {
messages.forEach(message -> MessageUtil.sendMessage(source, message, broadcastToAdmins));
}
public static void sendMessage(class_2168 source, @NotNull Collection messages) {
messages.forEach(message -> MessageUtil.sendMessage(source, message, false));
}
public static void sendMessageCompat(class_2168 source, @NotNull Collection messages,
boolean broadcastToAdmins) {
messages.stream()
.map(ComponentCompat::get)
.forEach(message -> MessageUtil.sendMessage(source, message, broadcastToAdmins));
}
public static void sendMessageCompat(class_2168 source, @NotNull Collection messages) {
messages.stream()
.map(ComponentCompat::get)
.forEach(message -> MessageUtil.sendMessage(source, message, false));
}
// Component I18n cannot be processed with logger.
public static void sendToConsole(String message) {
MessageUtil.sendToConsoleCompat(ComponentCompat.literal(message));
}
public static void sendToConsole(class_2561 message) {
MagicLibMinecraft.getInstance().getServer().ifPresent(server ->
//#if MC > 11802
server.sendSystemMessage(message)
//#else
//$$ server.sendMessage(message
//#if MC > 11502
//$$ , UtilCompat.NIL_UUID
//#endif
//$$ )
//#endif
);
}
public static void sendToConsoleCompat(@NotNull ComponentCompat message) {
MessageUtil.sendToConsole(message.get());
}
public static void sendServerMessage(String message) {
MessageUtil.sendServerMessageCompat(ComponentCompat.literal(message));
}
public static void sendServerMessageCompat(@NotNull ComponentCompat message) {
MessageUtil.sendServerMessage(message.get());
}
public static void sendServerMessage(class_2561 message) {
MessageUtil.sendToConsole(message);
MagicLibMinecraft.getInstance().getServer().ifPresent(server ->
server.getPlayerList().getPlayers().forEach(player ->
MessageUtil.sendMessage(player.createCommandSourceStack(), message)));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy