package ua.com.minersstudios.util.misc;
// TODO: To reorganise code for it to work.
import org.projectlombok.lombok.*;
import org.jetbrains.annotations.Nullable;
import net.kyori.adventure.text.Component;
@UtilityClass
public class IngameChatMessageFactory
{
public enum Chat {GLOBAL, LOCAL}
public enum RolePlayActionType {DO, IT, ME, TODO}
/**
* Send message to the game chat.
* @param playerInfo PlayerInfo object
* @param location sender's location
* @param chat chat to use
* @param message message to be sent
* @deprecated
*/
// TODO: Will be replaced when new API comes out.
@Deprecated
public void sendMessageToChat(
@NonNull PlayerInfo playerInfo,
@Nullable Location location,
@NonNull Chat chat,
@NonNull Component message)
{
ConfigCache configCache = Util.getConfigCache();
if (chat == Chat.LOCAL && location != null)
{
Component localMessage = space()
.append(playerInfo.getDefaultName())
.append(text(" : "))
.color(CHAT_MESSAGE_COLOR_PRIMARY)
.hoverEvent(HoverEvent.showText(text("Натисніть, щоб написати приватне повідомлення цьому гравцю", NamedTextColor.GRAY)))
.clickEvent(ClickEvent.suggestCommand("/pm {} ", playerInfo.getID())))
.append(message)
.color(CHAT_MESSAGE_COLOR_SECONDARY);
String stringLocalMessage = serializeLegacyComponent(localMessage);
sendLocalMessage(localMessage, location, configCache.localChatRadius);
Bukkit.getScheduler().runTaskAsynchronously(new Util(),
() -> sendMessage(getTextChannelById(configCache.discordLocalChannelId), stringLocalMessage));
sendInfo(stringLocalMessage);
return;
}
// TODO: prefix to config.
Component globalMessage = space()
.append(text("[WM] ")
.append(playerInfo.getDefaultName()
.append(text(" : ")))
.color(CHAT_MESSAGE_COLOR_PRIMARY)
.hoverEvent(HoverEvent.showText(text("Натисніть, щоб написати приватне повідомлення цьому гравцю", NamedTextColor.GRAY)))
.clickEvent(ClickEvent.suggestCommand("/pm {} ", playerInfo.getID())))
.append(message)
.color(CHAT_MESSAGE_COLOR_SECONDARY);
String stringGlobalMessage = serializeLegacyComponent(globalMessage);
sendGlobalMessage(globalMessage);
Bukkit.getScheduler().runTaskAsynchronously(MSUtils.getInstance(), () ->
{
sendMessage(getTextChannelById(configCache.discordGlobalChannelId), stringGlobalMessage.replaceFirst("\\[WM]", ""));
sendMessage(getTextChannelById(configCache.discordLocalChannelId), stringGlobalMessage);
});
sendInfo(stringGlobalMessage);
}
public final class Colors
{
// TODO: Move color values to config.
public final TextColor
CHAT_MESSAGE_COLOR_PRIMARY = TextColor.fromHexString("#aba494"),
CHAT_MESSAGE_COLOR_SECONDARY = TextColor.fromHexString("#f1f0e3"),
JOIN_MESSAGE_COLOR_PRIMARY = TextColor.fromHexString("#ffef93"),
JOIN_MESSAGE_COLOR_SECONDARY = TextColor.fromHexString("#fcf5c7"),
RP_MESSAGE_COLOR_PRIMARY = TextColor.fromHexString("#ffaa00"),
RP_MESSAGE_COLOR_SECONDARY = TextColor.fromHexString("#ffc369");
}
}