Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
Merge pull request #6 from RappyLabyAddons/feat/rejectRequests
Browse files Browse the repository at this point in the history
Add option to instantly deny friend requests
  • Loading branch information
RappyTV authored Mar 8, 2024
2 parents 41fefa0 + 6cacf46 commit bc2ace0
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 7 deletions.
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,13 +31,42 @@ 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")
Expand All @@ -48,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 @@ -60,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

0 comments on commit bc2ace0

Please sign in to comment.