Skip to content

Commit

Permalink
Merge pull request #3 from RappyLabyAddons/develop
Browse files Browse the repository at this point in the history
Send and receive friend requests in chat, design icons, send and receive chat messages in chat
  • Loading branch information
RappyTV authored Feb 28, 2024
2 parents 3a87c7d + 250c6c5 commit bdf7d26
Show file tree
Hide file tree
Showing 12 changed files with 309 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,69 @@

import com.rappytv.labychatutils.command.LabyChatUtilsCommand;
import com.rappytv.labychatutils.listeners.LabyChatListener;
import net.labymod.api.Laby;
import com.rappytv.labychatutils.widgets.UnreadChatCountWidget;
import net.labymod.api.addon.LabyAddon;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.event.ClickEvent;
import net.labymod.api.client.component.event.HoverEvent;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.client.component.format.TextDecoration;
import net.labymod.api.models.addon.annotation.AddonMain;
import java.util.UUID;

@AddonMain
public class LabyChatUtilsAddon extends LabyAddon<LabyChatUtilsConfig> {

private static final Component prefix = Component.empty()
.append(
Component
.text("LCU")
.color(NamedTextColor.DARK_BLUE)
public static final Component prefix = Component.empty()
.append(Component.text("[", NamedTextColor.DARK_GRAY))
.append(Component.text("LCU", NamedTextColor.DARK_BLUE)
.decorate(TextDecoration.BOLD)
)
.append(Component.text(" » ", NamedTextColor.DARK_GRAY));
.append(Component.text("] ", NamedTextColor.DARK_GRAY));

@Override
protected void enable() {
registerSettingCategory();
registerCommand(new LabyChatUtilsCommand());
registerListener(new LabyChatListener());
labyAPI().hudWidgetRegistry().register(new UnreadChatCountWidget());
}

@Override
protected Class<? extends LabyChatUtilsConfig> configurationClass() {
return LabyChatUtilsConfig.class;
}

public static void msg(Component... lines) {
Component component = Component.empty()
.color(NamedTextColor.WHITE)
.append(Component.text(\n", NamedTextColor.DARK_GRAY));
public static Component chatMessage(String name, String message, UUID uuid, boolean elements) {

for(Component line : lines) {
component.append(prefix).append(line);
}
Component component = Component
.empty()
.append(prefix)
.append(Component.text(name, NamedTextColor.AQUA))
.append(Component.text(" » ", NamedTextColor.DARK_GRAY))
.append(Component.text(message, NamedTextColor.WHITE));

component.append(Component.text("\n»", NamedTextColor.DARK_GRAY));
Laby.references().chatExecutor().displayClientMessage(component);
if(elements) {
component
.append(Component
.text(" ✔", NamedTextColor.GREEN)
.hoverEvent(HoverEvent.showText(
Component.translatable("labychatutils.messages.read")
.color(NamedTextColor.GREEN)
))
.clickEvent(ClickEvent.runCommand("/lcu read " + uuid))
)
.append(Component
.text(" ➥", NamedTextColor.BLUE)
.hoverEvent(HoverEvent.showText(
Component.translatable("labychatutils.messages.reply")
.color(NamedTextColor.BLUE)
))
.clickEvent(ClickEvent.suggestCommand(
"/lcu reply " + name + " "
))
);
}
return component;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.rappytv.labychatutils.command;

import com.rappytv.labychatutils.LabyChatUtilsAddon;
import com.rappytv.labychatutils.command.subcommands.AcceptSubCommand;
import com.rappytv.labychatutils.command.subcommands.ClearSubCommand;
import com.rappytv.labychatutils.command.subcommands.DeclineSubCommand;
import com.rappytv.labychatutils.command.subcommands.ReadSubCommand;
import com.rappytv.labychatutils.command.subcommands.ReplySubCommand;
import com.rappytv.labychatutils.command.subcommands.SendSubCommand;
import net.labymod.api.client.chat.command.Command;
import net.labymod.api.client.chat.command.SubCommand;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
import java.util.stream.Collectors;

public class LabyChatUtilsCommand extends Command {

Expand All @@ -14,12 +21,25 @@ public LabyChatUtilsCommand() {
withSubCommand(new AcceptSubCommand());
withSubCommand(new ClearSubCommand());
withSubCommand(new DeclineSubCommand());
withSubCommand(new ReplySubCommand());
withSubCommand(new ReadSubCommand());
withSubCommand(new SendSubCommand());
}

@Override
public boolean execute(String prefix, String[] arguments) {
displayMessage(String.join(", ", arguments));
String subcommands = getSubCommands()
.stream()
.map(SubCommand::getPrefix)
.collect(Collectors.joining("|"));

displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.usage",
NamedTextColor.RED,
Component.text(
prefix + " <" + subcommands + ">"
)
)));
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ public AcceptSubCommand() {
@Override
public boolean execute(String prefix, String[] arguments) {
if(arguments.length < 1) {
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.enterPlayerName",
NamedTextColor.RED
));
)));
return true;
}
LabyConnectSession session = Laby.references().labyConnect().getSession();
if(session == null) {
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.notConnected",
NamedTextColor.RED
));
)));
return true;
}
List<IncomingFriendRequest> requests = session.getIncomingRequests();

if(requests.isEmpty()) {
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.request.empty",
NamedTextColor.RED
));
)));
return true;
}
Optional<IncomingFriendRequest> request = requests
Expand All @@ -48,17 +48,17 @@ public boolean execute(String prefix, String[] arguments) {
.findFirst();

if(request.isEmpty()) {
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.request.notFound",
NamedTextColor.RED
));
)));
return true;
}
request.get().accept();
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.request.accepted",
Component.text(request.get().getName(), NamedTextColor.AQUA)
).color(NamedTextColor.GREEN));
).color(NamedTextColor.GREEN)));
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public ClearSubCommand() {
public boolean execute(String prefix, String[] arguments) {
LabyConnectSession session = Laby.references().labyConnect().getSession();
if(session == null) {
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.notConnected",
NamedTextColor.RED
));
)));
return true;
}
List<OutgoingFriendRequest> requests = session.getOutgoingRequests();

if(requests.isEmpty()) {
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.request.outEmpty",
NamedTextColor.RED
));
)));
return true;
}

Expand All @@ -44,12 +44,12 @@ public boolean execute(String prefix, String[] arguments) {
names.add(request.getName());
}

LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.request.cleared",
Component.text(names.size())
.decorate(TextDecoration.UNDERLINED)
.hoverEvent(HoverEvent.showText(Component.text(String.join(", ", names))))
).color(NamedTextColor.GREEN));
).color(NamedTextColor.GREEN)));
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ public DeclineSubCommand() {
@Override
public boolean execute(String prefix, String[] arguments) {
if(arguments.length < 1) {
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.enterPlayerName",
NamedTextColor.RED
));
)));
return true;
}
LabyConnectSession session = Laby.references().labyConnect().getSession();
if(session == null) {
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.notConnected",
NamedTextColor.RED
));
)));
return true;
}
List<IncomingFriendRequest> requests = session.getIncomingRequests();

if(requests.isEmpty()) {
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.request.empty",
NamedTextColor.RED
));
)));
return true;
}
Optional<IncomingFriendRequest> request = requests
Expand All @@ -48,17 +48,17 @@ public boolean execute(String prefix, String[] arguments) {
.findFirst();

if(request.isEmpty()) {
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.request.notFound",
NamedTextColor.RED
));
)));
return true;
}
request.get().decline();
LabyChatUtilsAddon.msg(Component.translatable(
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.request.declined",
Component.text(request.get().getName())
).color(NamedTextColor.GREEN));
).color(NamedTextColor.GREEN)));
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.rappytv.labychatutils.command.subcommands;

import com.rappytv.labychatutils.LabyChatUtilsAddon;
import com.rappytv.labychatutils.listeners.LabyChatListener;
import net.labymod.api.Laby;
import net.labymod.api.client.chat.command.SubCommand;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.labyconnect.protocol.model.chat.TextChatMessage;
import java.util.UUID;

public class ReadSubCommand extends SubCommand {

public ReadSubCommand() {
super("read");
}

@Override
public boolean execute(String prefix, String[] arguments) {
if(Laby.references().labyConnect().getSession() == null) {
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.notConnected",
NamedTextColor.RED
)));
return true;
}
if(arguments.length < 1) {
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.manual",
NamedTextColor.RED
)));
return true;
}
UUID uuid;
try {
uuid = UUID.fromString(arguments[0]);
} catch (IllegalArgumentException e) {
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.manual",
NamedTextColor.RED
)));
return true;
}

TextChatMessage message = LabyChatListener.getMessage(uuid);

if(message == null) {
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.manual",
NamedTextColor.RED
)));
return true;
}
message.markAsRead();
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable("labychatutils.messages.markedRead")));
return true;
}
}
Loading

0 comments on commit bdf7d26

Please sign in to comment.