Skip to content

Commit 218612e

Browse files
committed
feat: when copying chat message send Toast instead of chat message
1 parent cf5379d commit 218612e

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/main/java/com/fix3dll/skyblockaddons/mixin/transformers/ChatScreenMixin.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
import com.fix3dll.skyblockaddons.mixin.extensions.GuiMessageLineExtension;
99
import com.fix3dll.skyblockaddons.utils.DevUtils;
1010
import com.fix3dll.skyblockaddons.utils.TextUtils;
11+
import com.fix3dll.skyblockaddons.utils.Utils;
1112
import com.llamalad7.mixinextras.sugar.Local;
1213
import com.mojang.blaze3d.platform.InputConstants;
1314
import com.mojang.blaze3d.platform.Window;
1415
import net.minecraft.Util;
1516
import net.minecraft.client.Minecraft;
1617
import net.minecraft.client.gui.components.ChatComponent;
18+
import net.minecraft.client.gui.components.toasts.SystemToast;
1719
import net.minecraft.client.gui.screens.ChatScreen;
1820
import net.minecraft.client.input.MouseButtonEvent;
21+
import net.minecraft.network.chat.Component;
1922
import org.lwjgl.glfw.GLFW;
2023
import org.spongepowered.asm.mixin.Mixin;
2124
import org.spongepowered.asm.mixin.injection.At;
@@ -39,21 +42,31 @@ public class ChatScreenMixin {
3942
: InputConstants.isKeyDown(handle, GLFW.GLFW_KEY_LEFT_CONTROL);
4043

4144
if (isLeftControlDown) {
42-
ChatComponentExtension extendedChatComponent = (ChatComponentExtension) (Object) chatComponent;
45+
ChatComponentExtension extendedChatComponent = (ChatComponentExtension) chatComponent;
4346
GuiMessageLineExtension extendedLine = extendedChatComponent.sba$getGuiMessageLineAt(event, isDoubleClick);
4447

4548
if (extendedLine != null) {
4649
boolean isLeftShiftDown = InputConstants.isKeyDown(handle, GLFW.GLFW_KEY_LEFT_SHIFT);
4750
if (isLeftShiftDown) {
4851
DevUtils.copyStringToClipboard(
49-
TextUtils.getFormattedText(extendedLine.sba$getParentComponent()),
50-
ColorCode.GREEN + Translations.getMessage("messages.chatMessageCopying.formatted")
52+
TextUtils.getFormattedText(extendedLine.sba$getParentComponent()), null
5153
);
54+
Minecraft.getInstance().getToastManager().addToast(new SystemToast(
55+
new SystemToast.SystemToastId(2000L),
56+
Utils.COMPONENT_TITLE,
57+
Component.literal(Translations.getMessage("messages.chatMessageCopying.formatted"))
58+
.withColor(ColorCode.GREEN.getColor())
59+
));
5260
} else {
5361
DevUtils.copyStringToClipboard(
54-
TextUtils.stripColor(extendedLine.sba$getParentComponent().getString()),
55-
ColorCode.GREEN + Translations.getMessage("messages.chatMessageCopying.unformatted")
62+
TextUtils.stripColor(extendedLine.sba$getParentComponent().getString()), null
5663
);
64+
Minecraft.getInstance().getToastManager().addToast(new SystemToast(
65+
new SystemToast.SystemToastId(2000L),
66+
Utils.COMPONENT_TITLE,
67+
Component.literal(Translations.getMessage("messages.chatMessageCopying.unformatted"))
68+
.withColor(ColorCode.GREEN.getColor())
69+
));
5770
}
5871
}
5972
}

src/main/java/com/fix3dll/skyblockaddons/utils/Utils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public class Utils {
7272
ColorCode.GRAY + "[" + ColorCode.AQUA + SkyblockAddons.METADATA.getName() + ColorCode.GRAY + "] ";
7373
public static final String MESSAGE_PREFIX_SHORT =
7474
ColorCode.GRAY + "[" + ColorCode.AQUA + "SBA" + ColorCode.GRAY + "] " + ColorCode.RESET;
75+
public static final Component COMPONENT_TITLE = Component.literal(SkyblockAddons.METADATA.getName())
76+
.withColor(ColorCode.AQUA.getColor());
7577

7678
/**
7779
* "Skyblock" as shown on the scoreboard title in English, Chinese Simplified, Traditional Chinese.

src/main/resources/lang/en_US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@
391391
"classColoredTeammateRequirement": "Entity Outlines and Outline Dungeon Teammate features must be enabled",
392392
"perkpocalypseUnknown": "Mayor Jerry's Perkpocalypse mayor is not known! Click here to update Perkpocalypse mayor.",
393393
"chatMessageCopying": {
394-
"unformatted": "Unformatted chat message copied to clipboard!",
394+
"unformatted": "Chat message copied to clipboard!",
395395
"formatted": "Formatted chat message copied to clipboard!"
396396
}
397397
},

0 commit comments

Comments
 (0)