Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MovTery committed Apr 23, 2024
1 parent 68529dc commit ad20e79
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/client/java/com/movtery/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void save() {

public static class Options {
public String messageValue = "Hello!";
public boolean antiFalseContact = false;
public boolean messageCoolingDown = true;
public double messageCoolingDuration = 10.0;

Expand Down
10 changes: 10 additions & 0 deletions src/client/java/com/movtery/config/YACLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public Screen configScreen(Screen parent) {
})
.controller(StringControllerBuilder::create)
.build())
//防误触
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("quick_chat.config.anti_false_contact"))
.description(OptionDescription.of(Text.translatable("quick_chat.config.anti_false_contact.desc")))
.binding(defaultVal.antiFalseContact, () -> options.antiFalseContact, newVal -> {
options.antiFalseContact = newVal;
getConfig().save();
})
.controller(BooleanControllerBuilder::create)
.build())
//快捷消息列表
.option(ButtonOption.createBuilder()
.name(Text.translatable("quick_chat.gui.message_list.title"))
Expand Down
8 changes: 8 additions & 0 deletions src/client/java/com/movtery/util/LastMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class LastMessage {
private static final LastMessage LAST_MESSAGE = new LastMessage();
private long lastTime = 0;
private long lastClick = 0;
private String lastMessage = "Hello!";

private LastMessage() {
Expand All @@ -19,6 +20,13 @@ public long getLastTime() {
public void setLastTime(long lastTime) {
this.lastTime = lastTime;
}
public long getLastClick() {
return lastClick;
}

public void setLastClick(long lastClick) {
this.lastClick = lastClick;
}

public void setLastMessage(String lastMessage) {
this.lastMessage = lastMessage;
Expand Down
13 changes: 12 additions & 1 deletion src/client/java/com/movtery/util/QuickChatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.client.option.KeyBinding;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Util;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;

Expand Down Expand Up @@ -51,6 +52,16 @@ public static void registry() {

ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (oneClick.wasPressed()) {
//开启防误触设置之后,将启用双击检测
if (getConfig().getOptions().antiFalseContact) {
LastMessage instance = LastMessage.getInstance();
long clickTime = Util.getMeasuringTimeMs();
//点击即进行判断,如果前后两次点击时间相差不超过0.25秒,那么表示这是一次双击
boolean isDoubleClick = clickTime - instance.getLastClick() < 250L;
instance.setLastClick(clickTime);

if (!isDoubleClick) break;
}
ClientPlayerEntity player = MinecraftClient.getInstance().player;
if (Objects.isNull(player)) break;

Expand Down Expand Up @@ -119,7 +130,7 @@ public static void sendMessage(@NotNull ClientPlayerEntity player, String messag
} else {
BigDecimal bigDecimal = BigDecimal.valueOf(duration);
BigDecimal t = bigDecimal.subtract(BigDecimal.valueOf(differ / 1000.0));
player.sendMessage(Text.translatable("quick_chat.chat.too_often").append(String.format(" %.2fs", t)), true);
player.sendMessage(Text.translatable("quick_chat.in_game.too_often").append(String.format(" %.2fs", t)), true);
}
}
}
Binary file modified src/main/resources/assets/quick_chat/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions src/main/resources/assets/quick_chat/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
{
"quick_chat.name": "Quick Chat",

"quick_chat.keybinding.one_click": "Send with One Click",
"modmenu.nameTranslation.quick_chat": "Quick Chat",
"modmenu.descriptionTranslation.quick_chat": "Send messages quickly by pressing keys.",

"quick_chat.keybinding.one_click": "One-click Send",
"quick_chat.keybinding.quick_message": "Open Quick Message List Screen",

"quick_chat.chat.too_often": "Message sent too often!",
"quick_chat.in_game.too_often": "Message sent too often!",

"quick_chat.config.reloaded": "Config file reloaded!",
"quick_chat.config.open": "Open",
"quick_chat.config.message": "Message content",
"quick_chat.config.message.desc": "Set the content of quick messages to send\n\nStart with \"/\" to execute as command",
"quick_chat.config.message": "Message Content",
"quick_chat.config.message.desc": "Set the content to be sent as quick messages\n\nStart with \"/\" for Mod command execution",
"quick_chat.config.anti_false_contact": "Anti False Contact",
"quick_chat.config.anti_false_contact.desc": "When enabled, you need to double-click the hotkey to send the message, avoiding accidental triggers",
"quick_chat.config.message_list": "Open Quick Message List",
"quick_chat.config.message_list.desc": "You can add more quick messages here, and quickly open this screen in-game to send what you want!",
"quick_chat.config.message_list.desc": "You can add more quick messages in this screen. After entering the game, you can quickly open this screen by pressing the key binding, then send the content you want!",
"quick_chat.config.cooldown": "Send Cooldown",
"quick_chat.config.cooldown.desc": "If disabled, cooldown duration will be set to 0.5s",
"quick_chat.config.cooldown.desc": "If turned off, cooldown duration will be set to 0.5s",
"quick_chat.config.cooldown_duration": "Cooldown Duration",
"quick_chat.config.cooldown_duration.desc": "Set the interval for sending messages",

"quick_chat.gui.message_list.title": "Quick Message List",
"quick_chat.gui.message_list.tip_empty": "No messages available, please add new ones!",
"quick_chat.gui.message_list.tip_empty": "No messages available, please add new messages!",
"quick_chat.gui.message_list.tip": "Select a message, you can delete, edit, or send it!",
"quick_chat.gui.message_list.add": "Add",
"quick_chat.gui.message_list.edit": "Edit",
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/assets/quick_chat/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"quick_chat.name": "快捷聊天",

"modmenu.nameTranslation.quick_chat": "快捷聊天",
"modmenu.descriptionTranslation.quick_chat": "通过按键快速发送消息。",

"quick_chat.keybinding.one_click": "一键发送",
"quick_chat.keybinding.quick_message": "打开快捷消息列表屏幕",

"quick_chat.chat.too_often": "消息发送过于频繁!",
"quick_chat.in_game.too_often": "消息发送过于频繁!",

"quick_chat.config.reloaded": "配置文件已重载!",
"quick_chat.config.open": "打开",
"quick_chat.config.message": "消息内容",
"quick_chat.config.message.desc": "设置快捷消息发送的内容\n\n在内容开头处加上 \"/\" 符号,Mod 会将其作为命令执行",
"quick_chat.config.anti_false_contact": "防误触",
"quick_chat.config.anti_false_contact.desc": "开启后,你需要双击快捷键后才能快捷发送消息,避免误触",
"quick_chat.config.message_list": "打开快捷消息列表",
"quick_chat.config.message_list.desc": "你可以在此屏幕内添加更多的快捷消息,进入游戏后可以通过按键绑定快速打开此屏幕,然后发送你想要的内容!",
"quick_chat.config.cooldown": "发送冷却",
Expand Down

0 comments on commit ad20e79

Please sign in to comment.