Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to instantly deny friend requests #6

Merged
merged 10 commits into from
Mar 8, 2024
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ labyMod {
author = "RappyTV"
description = "Interact with the LabyConnect chat by your minecraft chat."
minecraftVersion = "*"
version = System.getenv().getOrDefault("VERSION", "1.0.0")
version = System.getenv().getOrDefault("VERSION", "1.0.1")
}

minecraft {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import com.rappytv.labychatutils.command.LabyChatUtilsCommand;
import com.rappytv.labychatutils.listeners.LabyChatListener;
import com.rappytv.labychatutils.widgets.UnreadChatCountWidget;
import net.labymod.api.Laby;
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 net.labymod.api.revision.SimpleRevision;
import net.labymod.api.util.version.SemanticVersion;
import java.util.UUID;

@AddonMain
Expand All @@ -22,6 +25,11 @@ public class LabyChatUtilsAddon extends LabyAddon<LabyChatUtilsConfig> {
)
.append(Component.text("] ", NamedTextColor.DARK_GRAY));

@Override
protected void preConfigurationLoad() {
Laby.references().revisionRegistry().register(new SimpleRevision("labychatutils", new SemanticVersion("1.0.1"), "2024-03-08"));
}

@Override
protected void enable() {
registerSettingCategory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.labymod.api.addon.AddonConfig;
import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget.SwitchSetting;
import net.labymod.api.configuration.loader.annotation.IntroducedIn;
import net.labymod.api.configuration.loader.property.ConfigProperty;
import net.labymod.api.configuration.settings.annotation.SettingRequires;
import net.labymod.api.configuration.settings.annotation.SettingSection;
Expand All @@ -11,10 +12,14 @@ public class LabyChatUtilsConfig extends AddonConfig {
@SwitchSetting
private final ConfigProperty<Boolean> enabled = new ConfigProperty<>(true);
@SettingSection("friends")
@SettingRequires(value = "denyRequests", invert = true)
@SwitchSetting
private final ConfigProperty<Boolean> showIncomingRequests = new ConfigProperty<>(true);
@SwitchSetting
private final ConfigProperty<Boolean> showRemovedFriends = new ConfigProperty<>(true);
@IntroducedIn(namespace = "labychatutils", value = "1.0.1")
@SwitchSetting
private final ConfigProperty<Boolean> denyRequests = new ConfigProperty<>(false);
@SettingSection("messages")
@SwitchSetting
private final ConfigProperty<Boolean> showAnyMessages = new ConfigProperty<>(true);
Expand All @@ -32,6 +37,9 @@ public boolean showIncomingRequests() {
public boolean showRemovedFriends() {
return showRemovedFriends.get();
}
public boolean denyRequests() {
return denyRequests.get();
}
public boolean showAnyMessages() {
return showAnyMessages.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public boolean execute(String prefix, String[] arguments) {
)));
return true;
}
if(message.isRead()) {
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.alreadyRead",
NamedTextColor.RED
)));
return true;
}
message.markAsRead();
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable("labychatutils.messages.markedRead")));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean execute(String prefix, String[] arguments) {

if(chat.isEmpty()) {
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.request.notFound",
"labychatutils.messages.notFound",
NamedTextColor.RED
)));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public boolean execute(String prefix, String[] arguments) {
session.sendFriendRequest(arguments[0]);
displayMessage(LabyChatUtilsAddon.prefix.copy().append(Component.translatable(
"labychatutils.messages.request.sent",
NamedTextColor.RED,
NamedTextColor.GREEN,
Component.text(arguments[0])
)));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.labymod.api.event.labymod.labyconnect.session.friend.LabyConnectFriendRemoveEvent;
import net.labymod.api.event.labymod.labyconnect.session.request.LabyConnectIncomingFriendRequestAddEvent;
import net.labymod.api.labyconnect.protocol.model.chat.TextChatMessage;
import net.labymod.api.labyconnect.protocol.model.request.IncomingFriendRequest;
import net.labymod.api.notification.Notification;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -30,14 +31,44 @@ public LabyChatListener(LabyChatUtilsAddon addon) {

@Subscribe
public void onFriendRequestReceive(LabyConnectIncomingFriendRequestAddEvent event) {
IncomingFriendRequest request = event.request();

if(config.denyRequests()) {
event.request().decline();
Laby.references().chatExecutor().displayClientMessage(
Component.empty()
.append(LabyChatUtilsAddon.prefix)
.append(Component.translatable(
"labychatutils.messages.request.autoDeclined",
NamedTextColor.RED,
Component.text(request.getName(), NamedTextColor.AQUA)
.hoverEvent(HoverEvent.showText(Component.translatable(
"labychatutils.messages.showProfile",
NamedTextColor.AQUA
)))
.clickEvent(ClickEvent.openUrl(
"https://laby.net/@" + request.getName()
))
))
);
return;
}
if(!config.showIncomingRequests()) return;
Laby.references().chatExecutor().displayClientMessage(
Component.empty()
.append(LabyChatUtilsAddon.prefix)
.append(Component.translatable(
"labychatutils.messages.request.incoming",
Component.text(event.request().getName(), NamedTextColor.AQUA)
Component.text(request.getName(), NamedTextColor.AQUA)
.hoverEvent(HoverEvent.showText(Component.translatable(
"labychatutils.messages.showProfile",
NamedTextColor.AQUA
)))
.clickEvent(ClickEvent.openUrl(
"https://laby.net/@" + request.getName()
))
))
.append(Component.text(" "))
.append(Component.translatable("labychatutils.messages.request.accept")
.color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD)
Expand All @@ -47,7 +78,7 @@ public void onFriendRequestReceive(LabyConnectIncomingFriendRequestAddEvent even
.color(NamedTextColor.AQUA)
))
.clickEvent(ClickEvent.runCommand(
"/lcu accept " + event.request().getName()
"/lcu accept " + request.getName()
)))
.append(Component.text(" • ", NamedTextColor.DARK_GRAY))
.append(Component.translatable("labychatutils.messages.request.decline")
Expand All @@ -59,7 +90,7 @@ public void onFriendRequestReceive(LabyConnectIncomingFriendRequestAddEvent even
.color(NamedTextColor.AQUA)
))
.clickEvent(ClickEvent.runCommand(
"/lcu decline " + event.request().getName()
"/lcu decline " + request.getName()
))
)
);
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/resources/assets/labychatutils/i18n/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"name": "Notify you if one of your friends removes you.",
"description": "Note that this will also notify you when you remove them from your friend list as there is no way to check who was performing the action."
},
"denyRequests": {
"name": "Automatically deny friend requests",
"description": "This option will prevent any request from getting trough to you. It will tell you in chat tho. This option will deny all current requests after a restart."
},
"showAnyMessages": {
"name": "Show any received messages in chat",
"description": "Disabling this will completely hide received messages in chat."
Expand All @@ -31,6 +35,7 @@
"messages": {
"usage": "Usage: /%s",
"clickable": "Clickable",
"showProfile": "Show laby.net profile",
"request": {
"incoming": "%s just sent you a friend request!",
"accept": "Accept",
Expand All @@ -40,17 +45,20 @@
"notFound": "There was no request found that matches your search!",
"accepted": "You and %s are now friends!",
"declined": "Successfully declined friend request!",
"autoDeclined": "Incoming request by %s was automatically declined.",
"cleared": "Successfully revoked %s outgoing friend requests!",
"sent": "Successfully sent friend request to %s!"
},
"enterPlayerName": "Please enter a player name!",
"notConnected": "You're not connected to the LabyChat!",
"reply": "Reply",
"read": "Mark as read",
"notFound": "Player not found!",
"alreadyRead": "You've already read that message!",
"markedRead": "The message was marked as read.",
"manual": "This command can't be run manually!",
"remove": {
"title": "LabyMod friendship ended!",
"title": "Friend removed!",
"description": "Either you removed %s as a friend or they removed you."
}
}
Expand Down
Loading