From a380113f8feac3a7ea19cfc020315ebc0df91d16 Mon Sep 17 00:00:00 2001 From: RTTV Date: Sun, 23 Jun 2024 12:38:12 -0400 Subject: [PATCH 01/21] added creply / cr --- .../clientcommands/ClientCommands.java | 1 + .../clientcommands/command/ReplyCommand.java | 47 +++++++++++++++++++ .../commands/generic/ChatScreenMixin.java | 8 ++++ .../generic/ClientPacketListenerMixin.java | 29 ++++++++++++ .../assets/clientcommands/lang/en_us.json | 2 + src/main/resources/mixins.clientcommands.json | 1 + 6 files changed, 88 insertions(+) create mode 100644 src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java create mode 100644 src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java diff --git a/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java b/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java index fcdf9e61e..ba1a81ccd 100644 --- a/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java +++ b/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java @@ -157,6 +157,7 @@ public static void registerCommands(CommandDispatcher PosCommand.register(dispatcher); RelogCommand.register(dispatcher); RenderCommand.register(dispatcher); + ReplyCommand.register(dispatcher); ShrugCommand.register(dispatcher); SignSearchCommand.register(dispatcher); SnakeCommand.register(dispatcher); diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java new file mode 100644 index 000000000..b68135091 --- /dev/null +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -0,0 +1,47 @@ +package net.earthcomputer.clientcommands.command; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static dev.xpple.clientarguments.arguments.CMessageArgument.*; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*; + +public class ReplyCommand { + private static final SimpleCommandExceptionType NO_TARGET_FOUND = new SimpleCommandExceptionType(Component.translatable("commands.creply.noTargetFound")); + + @Nullable + private static String mostRecentWhisper = null; + @Nullable + private static String currentTarget = null; + + public static void onChatOpened() { + currentTarget = mostRecentWhisper; + } + + public static void setMostRecentWhisper(@NotNull String username) { + mostRecentWhisper = username; + } + + public static void register(CommandDispatcher dispatcher) { + var command = dispatcher.register(literal("creply") + .then(argument("message", message()) + .executes(ctx -> reply(ctx.getSource(), getMessage(ctx, "message"))))); + dispatcher.register(literal("cr").redirect(command)); + } + + public static int reply(FabricClientCommandSource source, Component message) throws CommandSyntaxException { + if (currentTarget == null) { + throw NO_TARGET_FOUND.create(); + } + + source.getClient().getConnection().sendCommand(String.format("msg %s %s", currentTarget, message.getString())); + + return Command.SINGLE_SUCCESS; + } +} diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ChatScreenMixin.java b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ChatScreenMixin.java index 03751cbb8..00db7589a 100644 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ChatScreenMixin.java +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ChatScreenMixin.java @@ -1,11 +1,14 @@ package net.earthcomputer.clientcommands.mixin.commands.generic; import net.earthcomputer.clientcommands.ClientCommands; +import net.earthcomputer.clientcommands.command.ReplyCommand; import net.earthcomputer.clientcommands.command.VarCommand; import net.minecraft.client.gui.screens.ChatScreen; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ChatScreen.class) public class ChatScreenMixin { @@ -19,4 +22,9 @@ private String onHandleChatInput(String message) { } return command; } + + @Inject(method = "init", at = @At("TAIL")) + private void onInit(CallbackInfo ci) { + ReplyCommand.onChatOpened(); + } } diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java new file mode 100644 index 000000000..540139142 --- /dev/null +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java @@ -0,0 +1,29 @@ +package net.earthcomputer.clientcommands.mixin.commands.generic; + +import net.earthcomputer.clientcommands.command.ReplyCommand; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.chat.ChatType; +import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ClientPacketListener.class) +public class ClientPacketListenerMixin { + @Shadow private ClientLevel level; + + @Inject(method = "handlePlayerChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/PacketUtils;ensureRunningOnSameThread(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;Lnet/minecraft/util/thread/BlockableEventLoop;)V", shift = At.Shift.AFTER)) + private void onHandlePlayerChat(ClientboundPlayerChatPacket packet, CallbackInfo ci) { + if (packet.chatType().chatType().is(ChatType.MSG_COMMAND_INCOMING) || packet.chatType().chatType().is(ChatType.MSG_COMMAND_OUTGOING)) { + level.players() + .stream() + .filter(player -> player.getUUID().equals(packet.sender())) + .findAny() + .map(player -> player.getGameProfile().getName()) + .ifPresent(ReplyCommand::setMostRecentWhisper); + } + } +} diff --git a/src/main/resources/assets/clientcommands/lang/en_us.json b/src/main/resources/assets/clientcommands/lang/en_us.json index ec1169c12..dfc029fd9 100644 --- a/src/main/resources/assets/clientcommands/lang/en_us.json +++ b/src/main/resources/assets/clientcommands/lang/en_us.json @@ -189,6 +189,8 @@ "commands.crender.entities.success": "Entity rendering rules have been updated", + "commands.creply.noTargetFound": "Could not find a target to reply to.", + "commands.csignsearch.starting": "Searching signs", "commands.cstartup.add.success": "Added command to startup file", diff --git a/src/main/resources/mixins.clientcommands.json b/src/main/resources/mixins.clientcommands.json index a7ff82f6d..73b98659d 100644 --- a/src/main/resources/mixins.clientcommands.json +++ b/src/main/resources/mixins.clientcommands.json @@ -65,6 +65,7 @@ "commands.alias.ClientSuggestionProviderMixin", "commands.enchant.MultiPlayerGameModeMixin", "commands.findblock.ClientLevelMixin", + "commands.generic.ClientPacketListenerMixin", "commands.generic.CommandSuggestionsMixin", "dataqueryhandler.ClientPacketListenerMixin", "events.ClientPacketListenerMixin", From bb269be0125319b053dbc82d994a7a556e6f5ddd Mon Sep 17 00:00:00 2001 From: Katie <72476111+RealRTTV@users.noreply.github.com> Date: Sun, 23 Jun 2024 17:09:27 -0400 Subject: [PATCH 02/21] Made changes in response to review Co-authored-by: Frederik van der Els <49305700+xpple@users.noreply.github.com> --- src/main/resources/assets/clientcommands/lang/en_us.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/assets/clientcommands/lang/en_us.json b/src/main/resources/assets/clientcommands/lang/en_us.json index dfc029fd9..2e83e53ad 100644 --- a/src/main/resources/assets/clientcommands/lang/en_us.json +++ b/src/main/resources/assets/clientcommands/lang/en_us.json @@ -189,7 +189,7 @@ "commands.crender.entities.success": "Entity rendering rules have been updated", - "commands.creply.noTargetFound": "Could not find a target to reply to.", + "commands.creply.noTargetFound": "Could not find a target to reply to", "commands.csignsearch.starting": "Searching signs", From 2c754777bb94049f7f6d618afe58a082cbf1d07e Mon Sep 17 00:00:00 2001 From: RTTV Date: Sun, 23 Jun 2024 18:04:07 -0400 Subject: [PATCH 03/21] fine then earth --- .../mixin/commands/generic/ChatScreenMixin.java | 8 -------- .../mixin/commands/reply/ChatScreenMixin.java | 16 ++++++++++++++++ src/main/resources/mixins.clientcommands.json | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ChatScreenMixin.java b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ChatScreenMixin.java index 00db7589a..03751cbb8 100644 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ChatScreenMixin.java +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ChatScreenMixin.java @@ -1,14 +1,11 @@ package net.earthcomputer.clientcommands.mixin.commands.generic; import net.earthcomputer.clientcommands.ClientCommands; -import net.earthcomputer.clientcommands.command.ReplyCommand; import net.earthcomputer.clientcommands.command.VarCommand; import net.minecraft.client.gui.screens.ChatScreen; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ChatScreen.class) public class ChatScreenMixin { @@ -22,9 +19,4 @@ private String onHandleChatInput(String message) { } return command; } - - @Inject(method = "init", at = @At("TAIL")) - private void onInit(CallbackInfo ci) { - ReplyCommand.onChatOpened(); - } } diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java new file mode 100644 index 000000000..f952151c5 --- /dev/null +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java @@ -0,0 +1,16 @@ +package net.earthcomputer.clientcommands.mixin.commands.reply; + +import net.earthcomputer.clientcommands.command.ReplyCommand; +import net.minecraft.client.gui.screens.ChatScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ChatScreen.class) +public class ChatScreenMixin { + @Inject(method = "init", at = @At("TAIL")) + private void onInit(CallbackInfo ci) { + ReplyCommand.onChatOpened(); + } +} diff --git a/src/main/resources/mixins.clientcommands.json b/src/main/resources/mixins.clientcommands.json index 73b98659d..da6a8e198 100644 --- a/src/main/resources/mixins.clientcommands.json +++ b/src/main/resources/mixins.clientcommands.json @@ -67,6 +67,7 @@ "commands.findblock.ClientLevelMixin", "commands.generic.ClientPacketListenerMixin", "commands.generic.CommandSuggestionsMixin", + "commands.reply.ChatScreenMixin", "dataqueryhandler.ClientPacketListenerMixin", "events.ClientPacketListenerMixin", "lengthextender.ChatScreenMixin", From bc45c419903ab256fb03d6ae7b0c38c6219727f1 Mon Sep 17 00:00:00 2001 From: RTTV Date: Sat, 29 Jun 2024 17:12:22 -0400 Subject: [PATCH 04/21] changed it to not crash cross-dimensionally, and to allow for max length messages --- .../clientcommands/command/ReplyCommand.java | 2 +- .../generic/ClientPacketListenerMixin.java | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index b68135091..972164320 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -40,7 +40,7 @@ public static int reply(FabricClientCommandSource source, Component message) thr throw NO_TARGET_FOUND.create(); } - source.getClient().getConnection().sendCommand(String.format("msg %s %s", currentTarget, message.getString())); + source.getClient().getConnection().sendCommand(String.format("w %s %s", currentTarget, message.getString())); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java index 540139142..59f696744 100644 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java @@ -1,29 +1,30 @@ package net.earthcomputer.clientcommands.mixin.commands.generic; import net.earthcomputer.clientcommands.command.ReplyCommand; -import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.network.chat.ChatType; import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.UUID; + @Mixin(ClientPacketListener.class) -public class ClientPacketListenerMixin { - @Shadow private ClientLevel level; +public abstract class ClientPacketListenerMixin { + @Shadow public abstract @Nullable PlayerInfo getPlayerInfo(UUID uniqueId); @Inject(method = "handlePlayerChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/PacketUtils;ensureRunningOnSameThread(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;Lnet/minecraft/util/thread/BlockableEventLoop;)V", shift = At.Shift.AFTER)) private void onHandlePlayerChat(ClientboundPlayerChatPacket packet, CallbackInfo ci) { if (packet.chatType().chatType().is(ChatType.MSG_COMMAND_INCOMING) || packet.chatType().chatType().is(ChatType.MSG_COMMAND_OUTGOING)) { - level.players() - .stream() - .filter(player -> player.getUUID().equals(packet.sender())) - .findAny() - .map(player -> player.getGameProfile().getName()) - .ifPresent(ReplyCommand::setMostRecentWhisper); + PlayerInfo info = getPlayerInfo(packet.sender()); + if (info != null) { + ReplyCommand.setMostRecentWhisper(info.getProfile().getName()); + } } } } From 5cdff653e325d1d1a2a4e91e5ecb44cd9ddd7dce Mon Sep 17 00:00:00 2001 From: RTTV Date: Sun, 30 Jun 2024 13:11:43 -0400 Subject: [PATCH 05/21] ok thats fine --- .../commands/{generic => reply}/ClientPacketListenerMixin.java | 2 +- src/main/resources/mixins.clientcommands.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/java/net/earthcomputer/clientcommands/mixin/commands/{generic => reply}/ClientPacketListenerMixin.java (95%) diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ClientPacketListenerMixin.java similarity index 95% rename from src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java rename to src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ClientPacketListenerMixin.java index 59f696744..38b7171af 100644 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/generic/ClientPacketListenerMixin.java +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ClientPacketListenerMixin.java @@ -1,4 +1,4 @@ -package net.earthcomputer.clientcommands.mixin.commands.generic; +package net.earthcomputer.clientcommands.mixin.commands.reply; import net.earthcomputer.clientcommands.command.ReplyCommand; import net.minecraft.client.multiplayer.ClientPacketListener; diff --git a/src/main/resources/mixins.clientcommands.json b/src/main/resources/mixins.clientcommands.json index da6a8e198..0c3cf4d88 100644 --- a/src/main/resources/mixins.clientcommands.json +++ b/src/main/resources/mixins.clientcommands.json @@ -65,7 +65,7 @@ "commands.alias.ClientSuggestionProviderMixin", "commands.enchant.MultiPlayerGameModeMixin", "commands.findblock.ClientLevelMixin", - "commands.generic.ClientPacketListenerMixin", + "commands.reply.ClientPacketListenerMixin", "commands.generic.CommandSuggestionsMixin", "commands.reply.ChatScreenMixin", "dataqueryhandler.ClientPacketListenerMixin", From a2f70db528f7a85a4b4e0e59dbcecfa88751cfe1 Mon Sep 17 00:00:00 2001 From: Katie <72476111+RealRTTV@users.noreply.github.com> Date: Fri, 19 Jul 2024 05:57:52 -0400 Subject: [PATCH 06/21] Update ReplyCommand.java --- .../net/earthcomputer/clientcommands/command/ReplyCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 972164320..0efe2e100 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -13,7 +13,8 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*; public class ReplyCommand { - private static final SimpleCommandExceptionType NO_TARGET_FOUND = new SimpleCommandExceptionType(Component.translatable("commands.creply.noTargetFound")); + private static final SimpleCommandExceptionType NO_TARGET_FOUND_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.creply.noTargetFound")); + private static final Dyanmic2ExceptionType MESSAGE_TOO_LONG_EXCEPTION = new Dyanmic2CommandExceptionType((a, b) -> Component.translatable("commands.creply.messageTooLong", a, b)); @Nullable private static String mostRecentWhisper = null; From 519fe59350d3813f59c1da3cc9707c0259380e3d Mon Sep 17 00:00:00 2001 From: Katie <72476111+RealRTTV@users.noreply.github.com> Date: Fri, 19 Jul 2024 05:57:56 -0400 Subject: [PATCH 07/21] Update ReplyCommand.java --- .../net/earthcomputer/clientcommands/command/ReplyCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 0efe2e100..2cbed1ed2 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -38,7 +38,7 @@ public static void register(CommandDispatcher dispatc public static int reply(FabricClientCommandSource source, Component message) throws CommandSyntaxException { if (currentTarget == null) { - throw NO_TARGET_FOUND.create(); + throw NO_TARGET_FOUND_EXCEPTION.create(); } source.getClient().getConnection().sendCommand(String.format("w %s %s", currentTarget, message.getString())); From 9c1db38d0411072d8aabdfedb8f249ec569d92f6 Mon Sep 17 00:00:00 2001 From: Katie <72476111+RealRTTV@users.noreply.github.com> Date: Fri, 19 Jul 2024 05:58:02 -0400 Subject: [PATCH 08/21] Update en_us.json --- src/main/resources/assets/clientcommands/lang/en_us.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/assets/clientcommands/lang/en_us.json b/src/main/resources/assets/clientcommands/lang/en_us.json index 2e83e53ad..cc59b4f89 100644 --- a/src/main/resources/assets/clientcommands/lang/en_us.json +++ b/src/main/resources/assets/clientcommands/lang/en_us.json @@ -190,6 +190,7 @@ "commands.crender.entities.success": "Entity rendering rules have been updated", "commands.creply.noTargetFound": "Could not find a target to reply to", + "commands.creply.messageTooLong": "Your reply was too long (maximum: %d, given: %d)", "commands.csignsearch.starting": "Searching signs", From 9a889d503db781a40674a95b088b8f75d95f2a01 Mon Sep 17 00:00:00 2001 From: Katie <72476111+RealRTTV@users.noreply.github.com> Date: Fri, 19 Jul 2024 05:58:06 -0400 Subject: [PATCH 09/21] Update ReplyCommand.java --- .../net/earthcomputer/clientcommands/command/ReplyCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 2cbed1ed2..25b3704e8 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import com.mojang.brigadier.exceptions.Dyanmic2CommandExceptionType; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; From a2891bb0b2e28953ddcd4b78a4701475118c69ca Mon Sep 17 00:00:00 2001 From: Katie <72476111+RealRTTV@users.noreply.github.com> Date: Fri, 19 Jul 2024 05:58:13 -0400 Subject: [PATCH 10/21] Update ReplyCommand.java --- .../clientcommands/command/ReplyCommand.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 25b3704e8..12c80285b 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -42,7 +42,13 @@ public static int reply(FabricClientCommandSource source, Component message) thr throw NO_TARGET_FOUND_EXCEPTION.create(); } - source.getClient().getConnection().sendCommand(String.format("w %s %s", currentTarget, message.getString())); + String text = message.getString(); + + if (3 + currentTarget.length() + 1 + text.length() > 256) { + throw MESSAGE_TOO_LONG_EXCEPTION.create(256 - (3 + currentTarget.length() + 1), text.length()); + } + + source.getClient().getConnection().sendCommand(String.format("w %s %s", currentTarget, text)); return Command.SINGLE_SUCCESS; } From 75b9f471077cc86db4c0e4d06b38cbea21c94116 Mon Sep 17 00:00:00 2001 From: Katie <72476111+RealRTTV@users.noreply.github.com> Date: Fri, 19 Jul 2024 06:01:51 -0400 Subject: [PATCH 11/21] Update ReplyCommand.java --- .../net/earthcomputer/clientcommands/command/ReplyCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 12c80285b..222ebff68 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -15,7 +15,7 @@ public class ReplyCommand { private static final SimpleCommandExceptionType NO_TARGET_FOUND_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.creply.noTargetFound")); - private static final Dyanmic2ExceptionType MESSAGE_TOO_LONG_EXCEPTION = new Dyanmic2CommandExceptionType((a, b) -> Component.translatable("commands.creply.messageTooLong", a, b)); + private static final Dyanmic2CommandExceptionType MESSAGE_TOO_LONG_EXCEPTION = new Dyanmic2CommandExceptionType((a, b) -> Component.translatable("commands.creply.messageTooLong", a, b)); @Nullable private static String mostRecentWhisper = null; From 2aeee657a0f63d7095d377639da503533ff9e321 Mon Sep 17 00:00:00 2001 From: Katie <72476111+RealRTTV@users.noreply.github.com> Date: Fri, 19 Jul 2024 06:06:46 -0400 Subject: [PATCH 12/21] Update ReplyCommand.java --- .../net/earthcomputer/clientcommands/command/ReplyCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 222ebff68..755b598e8 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import com.mojang.brigadier.exceptions.Dyanmic2CommandExceptionType; +import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; From 9b76e03d806223e07d8ac9349d43b4c9dedad2c5 Mon Sep 17 00:00:00 2001 From: Katie <72476111+RealRTTV@users.noreply.github.com> Date: Fri, 19 Jul 2024 06:06:52 -0400 Subject: [PATCH 13/21] Update ReplyCommand.java --- .../net/earthcomputer/clientcommands/command/ReplyCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 755b598e8..7621311f2 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -15,7 +15,7 @@ public class ReplyCommand { private static final SimpleCommandExceptionType NO_TARGET_FOUND_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.creply.noTargetFound")); - private static final Dyanmic2CommandExceptionType MESSAGE_TOO_LONG_EXCEPTION = new Dyanmic2CommandExceptionType((a, b) -> Component.translatable("commands.creply.messageTooLong", a, b)); + private static final Dynamic2CommandExceptionType MESSAGE_TOO_LONG_EXCEPTION = new Dynamic2CommandExceptionType((a, b) -> Component.translatable("commands.creply.messageTooLong", a, b)); @Nullable private static String mostRecentWhisper = null; From cdae3786fbd5ba207d1bf4aa23bf5feaae335bc7 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 19 Jul 2024 16:44:37 +0100 Subject: [PATCH 14/21] Add intellij project icon --- .gitignore | 3 ++- .idea/icon.svg | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .idea/icon.svg diff --git a/.gitignore b/.gitignore index 05961ed81..a51657876 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,8 @@ out/ # idea -.idea/ +.idea/* +!.idea/icon.svg *.iml *.ipr *.iws diff --git a/.idea/icon.svg b/.idea/icon.svg new file mode 100644 index 000000000..739777d22 --- /dev/null +++ b/.idea/icon.svg @@ -0,0 +1,7 @@ + + + + + + + From 1cfe2791d1bba9206da111d5d8d341ceba1dc79e Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 24 Jul 2024 18:05:15 +0100 Subject: [PATCH 15/21] Remove incompatibility with seedcrackerx. Closes #653 --- src/main/resources/fabric.mod.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f05af91d2..b3c09cd62 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -31,9 +31,6 @@ "fabric-api": "*", "clientarguments": ">=1.3.0" }, - "breaks": { - "seedcrackerx": "*" - }, "mixins": [ "mixins.clientcommands.json" ], From 3227e5368d22639ba1267fd6c4de336f1b37f6be Mon Sep 17 00:00:00 2001 From: RTTV Date: Sat, 28 Sep 2024 10:34:58 -0400 Subject: [PATCH 16/21] np --- .../clientcommands/command/ReplyCommand.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 7621311f2..d9660d1b3 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -42,11 +42,11 @@ public static int reply(FabricClientCommandSource source, Component message) thr throw NO_TARGET_FOUND_EXCEPTION.create(); } - String text = message.getString(); + String text = message.getString(); - if (3 + currentTarget.length() + 1 + text.length() > 256) { - throw MESSAGE_TOO_LONG_EXCEPTION.create(256 - (3 + currentTarget.length() + 1), text.length()); - } + if (3 + currentTarget.length() + 1 + text.length() > 256) { + throw MESSAGE_TOO_LONG_EXCEPTION.create(256 - (3 + currentTarget.length() + 1), text.length()); + } source.getClient().getConnection().sendCommand(String.format("w %s %s", currentTarget, text)); From e1ca3e657dc79cbc7ae6f8b9bdf60658a14d7e4f Mon Sep 17 00:00:00 2001 From: RTTV Date: Sat, 28 Sep 2024 10:37:55 -0400 Subject: [PATCH 17/21] made the code a bit prettier --- .../earthcomputer/clientcommands/command/ReplyCommand.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index d9660d1b3..26c806a50 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -43,12 +43,13 @@ public static int reply(FabricClientCommandSource source, Component message) thr } String text = message.getString(); + String command = String.format("w %s %s", currentTarget, text); - if (3 + currentTarget.length() + 1 + text.length() > 256) { - throw MESSAGE_TOO_LONG_EXCEPTION.create(256 - (3 + currentTarget.length() + 1), text.length()); + if (command.length() > 256) { + throw MESSAGE_TOO_LONG_EXCEPTION.create(256 - (command.length() - text.length()), text.length()); } - source.getClient().getConnection().sendCommand(String.format("w %s %s", currentTarget, text)); + source.getClient().getConnection().sendCommand(command); return Command.SINGLE_SUCCESS; } From 13235aaa940e41ea48e803636f3b94fe9143ea43 Mon Sep 17 00:00:00 2001 From: RTTV Date: Sun, 29 Sep 2024 16:35:42 -0400 Subject: [PATCH 18/21] ok --- .../net/earthcomputer/clientcommands/command/ReplyCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 26c806a50..16454c195 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -6,6 +6,7 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.SharedConstants; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -46,7 +47,7 @@ public static int reply(FabricClientCommandSource source, Component message) thr String command = String.format("w %s %s", currentTarget, text); if (command.length() > 256) { - throw MESSAGE_TOO_LONG_EXCEPTION.create(256 - (command.length() - text.length()), text.length()); + throw MESSAGE_TOO_LONG_EXCEPTION.create(SharedConstants.MAX_CHAT_LENGTH - (command.length() - text.length()), text.length()); } source.getClient().getConnection().sendCommand(command); From 39bd27db36c208735c0664d1132bc13b91da46db Mon Sep 17 00:00:00 2001 From: RTTV Date: Sun, 29 Sep 2024 16:39:51 -0400 Subject: [PATCH 19/21] ok --- .../net/earthcomputer/clientcommands/command/ReplyCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 16454c195..4423e4cb1 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -46,7 +46,7 @@ public static int reply(FabricClientCommandSource source, Component message) thr String text = message.getString(); String command = String.format("w %s %s", currentTarget, text); - if (command.length() > 256) { + if (command.length() > SharedConstants.MAX_CHAT_LENGTH) { throw MESSAGE_TOO_LONG_EXCEPTION.create(SharedConstants.MAX_CHAT_LENGTH - (command.length() - text.length()), text.length()); } From 837c6790befb3dc4ec290bc0b1f0b5810d25909d Mon Sep 17 00:00:00 2001 From: RTTV Date: Sun, 29 Sep 2024 16:42:50 -0400 Subject: [PATCH 20/21] ok --- .../net/earthcomputer/clientcommands/command/ReplyCommand.java | 2 +- .../clientcommands/mixin/commands/reply/ChatScreenMixin.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 4423e4cb1..9c68443cc 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -23,7 +23,7 @@ public class ReplyCommand { @Nullable private static String currentTarget = null; - public static void onChatOpened() { + public static void refreshCurrentTarget() { currentTarget = mostRecentWhisper; } diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java index f952151c5..95b1f56e0 100644 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java @@ -11,6 +11,6 @@ public class ChatScreenMixin { @Inject(method = "init", at = @At("TAIL")) private void onInit(CallbackInfo ci) { - ReplyCommand.onChatOpened(); + ReplyCommand.refreshCurrentTarget(); } } From 5a0d6414742a60892d24bdf42e9a95297f68c584 Mon Sep 17 00:00:00 2001 From: RTTV Date: Thu, 28 Nov 2024 00:18:30 -0500 Subject: [PATCH 21/21] changed it to be a 0.5 second threshold --- .../earthcomputer/clientcommands/Configs.java | 6 +++ .../clientcommands/command/ReplyCommand.java | 51 ++++++++++++++----- .../mixin/commands/reply/ChatScreenMixin.java | 16 ------ .../reply/ClientPacketListenerMixin.java | 2 +- src/main/resources/mixins.clientcommands.json | 1 - 5 files changed, 45 insertions(+), 31 deletions(-) delete mode 100644 src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java diff --git a/src/main/java/net/earthcomputer/clientcommands/Configs.java b/src/main/java/net/earthcomputer/clientcommands/Configs.java index 63f3e13e0..e6085ccef 100644 --- a/src/main/java/net/earthcomputer/clientcommands/Configs.java +++ b/src/main/java/net/earthcomputer/clientcommands/Configs.java @@ -176,4 +176,10 @@ public enum PacketDumpMethod { @Config public static int maximumPacketFieldDepth = 10; + + @Config(temporary = true, setter = @Config.Setter("setMinimumReplyDelaySeconds")) + public static float minimumReplyDelaySeconds = 0.5f; + public static void setMinimumReplyDelaySeconds(float minimumReplyDelaySeconds) { + Configs.minimumReplyDelaySeconds = Math.clamp(minimumReplyDelaySeconds, 0.0f, 10.0f); + } } diff --git a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java index 9c68443cc..d446600f1 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/ReplyCommand.java @@ -3,32 +3,53 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import net.earthcomputer.clientcommands.Configs; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.SharedConstants; import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static dev.xpple.clientarguments.arguments.CMessageArgument.*; -import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*; +import java.util.ArrayList; +import java.util.List; + +import static dev.xpple.clientarguments.arguments.CMessageArgument.getMessage; +import static dev.xpple.clientarguments.arguments.CMessageArgument.message; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; public class ReplyCommand { + public static final float MAXIMUM_REPLY_DELAY_SECONDS = 10.0f; + private static final SimpleCommandExceptionType NO_TARGET_FOUND_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.creply.noTargetFound")); private static final Dynamic2CommandExceptionType MESSAGE_TOO_LONG_EXCEPTION = new Dynamic2CommandExceptionType((a, b) -> Component.translatable("commands.creply.messageTooLong", a, b)); + private static final List replyCandidates = new ArrayList<>(); + @Nullable - private static String mostRecentWhisper = null; - @Nullable - private static String currentTarget = null; + public static String getCurrentTarget() { + long now = System.currentTimeMillis(); - public static void refreshCurrentTarget() { - currentTarget = mostRecentWhisper; + for (int i = 0; i < replyCandidates.size(); i++) { + ReplyCandidate candidate = replyCandidates.get(i); + if ((now - candidate.timestampMs) / 1_000.0f > MAXIMUM_REPLY_DELAY_SECONDS) { + replyCandidates.remove(i--); + } + } + + for (int i = replyCandidates.size() - 1; i >= 0; i--) { + ReplyCandidate candidate = replyCandidates.get(i); + if ((now - candidate.timestampMs) / 1_000.0f >= Configs.minimumReplyDelaySeconds) { + return candidate.username; + } + } + + return null; } - public static void setMostRecentWhisper(@NotNull String username) { - mostRecentWhisper = username; + public static void addReplyCandidate(String username, long timestamp) { + replyCandidates.add(new ReplyCandidate(username, timestamp)); } public static void register(CommandDispatcher dispatcher) { @@ -39,12 +60,13 @@ public static void register(CommandDispatcher dispatc } public static int reply(FabricClientCommandSource source, Component message) throws CommandSyntaxException { - if (currentTarget == null) { + @Nullable String target = ReplyCommand.getCurrentTarget(); + if (target == null) { throw NO_TARGET_FOUND_EXCEPTION.create(); } String text = message.getString(); - String command = String.format("w %s %s", currentTarget, text); + String command = String.format("w %s %s", target, text); if (command.length() > SharedConstants.MAX_CHAT_LENGTH) { throw MESSAGE_TOO_LONG_EXCEPTION.create(SharedConstants.MAX_CHAT_LENGTH - (command.length() - text.length()), text.length()); @@ -54,4 +76,7 @@ public static int reply(FabricClientCommandSource source, Component message) thr return Command.SINGLE_SUCCESS; } + + private record ReplyCandidate(String username, long timestampMs) { + } } diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java deleted file mode 100644 index 95b1f56e0..000000000 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ChatScreenMixin.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.earthcomputer.clientcommands.mixin.commands.reply; - -import net.earthcomputer.clientcommands.command.ReplyCommand; -import net.minecraft.client.gui.screens.ChatScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ChatScreen.class) -public class ChatScreenMixin { - @Inject(method = "init", at = @At("TAIL")) - private void onInit(CallbackInfo ci) { - ReplyCommand.refreshCurrentTarget(); - } -} diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ClientPacketListenerMixin.java b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ClientPacketListenerMixin.java index 38b7171af..000a1a6fa 100644 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ClientPacketListenerMixin.java +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/commands/reply/ClientPacketListenerMixin.java @@ -23,7 +23,7 @@ private void onHandlePlayerChat(ClientboundPlayerChatPacket packet, CallbackInfo if (packet.chatType().chatType().is(ChatType.MSG_COMMAND_INCOMING) || packet.chatType().chatType().is(ChatType.MSG_COMMAND_OUTGOING)) { PlayerInfo info = getPlayerInfo(packet.sender()); if (info != null) { - ReplyCommand.setMostRecentWhisper(info.getProfile().getName()); + ReplyCommand.addReplyCandidate(info.getProfile().getName(), System.currentTimeMillis()); } } } diff --git a/src/main/resources/mixins.clientcommands.json b/src/main/resources/mixins.clientcommands.json index 5e33027f8..409b38d74 100644 --- a/src/main/resources/mixins.clientcommands.json +++ b/src/main/resources/mixins.clientcommands.json @@ -70,7 +70,6 @@ "commands.generic.CommandSuggestionsMixin", "commands.glow.LivingEntityRenderStateMixin", "commands.snap.MinecraftMixin", - "commands.reply.ChatScreenMixin", "dataqueryhandler.ClientPacketListenerMixin", "events.ClientPacketListenerMixin", "lengthextender.ChatScreenMixin",