This repository has been archived on 2024-10-31. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
LibZontreck/src/main/java/dev/zontreck/libzontreck/util/ChatHelpers.java
Aria c6ff1afbdc Upgrade back to 1.19.4
Increment API version
+ LibAC
- Lightmans Currency
- Parchment (Temporary)
2023-04-21 03:44:40 -07:00

101 lines
3.2 KiB
Java

package dev.zontreck.libzontreck.util;
import java.util.UUID;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.chat.ChatColor;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
public class ChatHelpers {
public static void broadcastActionBar(Component message, MinecraftServer server)
{
server.execute(new Runnable(){
@Override
public void run()
{
for (ServerPlayer player : server.getPlayerList().getPlayers()) {
player.displayClientMessage(message, true);
}
LibZontreck.LOGGER.info("[ALL] "+message.getContents());
}
});
}
public static void broadcast(Component message, MinecraftServer server)
{
server.execute(new Runnable(){
@Override
public void run()
{
for (ServerPlayer player : server.getPlayerList().getPlayers()) {
player.displayClientMessage(message, false);
}
LibZontreck.LOGGER.info("[ALL] "+message.getContents());
}
});
}
public static void broadcastTo(UUID ID, Component message, MinecraftServer server, boolean actionBar)
{
server.execute(new Runnable(){
@Override
public void run()
{
ServerPlayer play = server.getPlayerList().getPlayer(ID);
play.displayClientMessage(message, actionBar);
LibZontreck.LOGGER.info("[SERVER] -> ["+play.getName().getContents()+"] "+message.getContents());
}
});
}
public static void broadcastTo(UUID ID, Component message, MinecraftServer server)
{
broadcastTo(ID, message, server, false);
}
public static void broadcastToAbove(UUID ID, Component message, MinecraftServer server)
{
broadcastTo(ID, message, server, true);
}
public static void broadcastTo(Player ID, Component message, MinecraftServer server)
{
broadcastTo(ID.getUUID(), message, server, false);
}
public static void broadcastToAbove(Player ID, Component message, MinecraftServer server)
{
broadcastTo(ID.getUUID(), message, server, true);
}
/**
* Returns the output with colors applied, and chat entries replaced using [number] as the format
* @param input
* @param inputs Entries to replace with in input
* @return
*/
public static Component macro(String input, String... inputs)
{
return Component.literal(macroize(input,inputs));
}
/**
* Returns the output with colors applied, and chat entries replaced using [number] as the format
* @param input
* @param inputs Entries to replace with in input
* @return
*/
public static String macroize(String input, String... inputs)
{
String output = input;
for (int i = 0; i < inputs.length; i++) {
String inp = inputs[i];
output = output.replaceAll("\\["+String.valueOf(i)+"]", inp);
}
return ChatColor.doColors(output);
}
}