top.hendrixshen.magiclib.util.InfoUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magiclib-1_14_4 Show documentation
Show all versions of magiclib-1_14_4 Show documentation
To beat magic with magic :(
package top.hendrixshen.magiclib.util;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_2561;
import net.minecraft.class_310;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
//#if MC > 11802 && MC < 11903
//#if MC > 11900
//$$ import net.minecraft.Util;
//#endif
//$$ import net.minecraft.client.gui.chat.ClientChatPreview;
//$$ import net.minecraft.network.chat.Component;
//#endif
@Environment(EnvType.CLIENT)
public class InfoUtil {
public static void displayClientMessage(class_2561 component, boolean useActionBar) {
Optional.ofNullable(class_310.method_1551().field_1724).ifPresent(p -> p.method_7353(component, useActionBar));
}
public static void displayActionBarMessage(class_2561 component) {
displayClientMessage(component, true);
}
public static void displayChatMessage(class_2561 component) {
displayClientMessage(component, false);
}
public static void send(@NotNull String text) {
if (text.startsWith("/")) {
InfoUtil.sendCommand(text);
} else {
InfoUtil.sendChat(text);
}
}
public static void sendChat(@NotNull String message) {
Optional.ofNullable(class_310.method_1551().field_1724).ifPresent(player -> {
String realText = message.trim();
if (!realText.isEmpty()) {
//#if MC > 11902
//$$ player.connection.sendChat(message.trim());
//#elseif MC > 11802
//$$ player.chatSigned(message, InfoUtil.getSign(message));
//#else
player.method_3142(message.trim());
//#endif
}
});
}
public static void sendCommand(@NotNull String command) {
Optional.ofNullable(class_310.method_1551().field_1724).ifPresent(player -> {
String realText = command.trim();
if (!realText.isEmpty()) {
//#if MC > 11902
//$$ player.connection.sendCommand(command.trim());
//#elseif MC > 11802
//$$ player.commandSigned(command, InfoUtil.getSign(command));
//#else
player.method_3142(String.format("/%s", command.trim()));
//#endif
}
});
}
//#if MC > 11802 && MC < 11903
//$$ public static Component getSign(String text) {
//$$ ClientChatPreview ccp = new ClientChatPreview(Minecraft.getInstance());
//#if MC > 11900
//$$ return Util.mapNullable(ccp.pull(text), ClientChatPreview.Preview::response);
//#else
//$$ return ccp.pull(text);
//#endif
//$$ }
//#endif
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy