0
0
mirror of https://github.com/Wurst-Imperium/Wurst7.git synced 2024-09-19 17:02:13 +02:00

Make ChatTranslator also work for sent messages

Fixes #320
Fixes #1021
Fixes https://wurstforum.net/d/602
This commit is contained in:
Alexander01998 2024-07-22 22:03:15 +02:00
parent 47443a815a
commit f41e49d507
10 changed files with 149 additions and 17 deletions

View File

@ -10,11 +10,14 @@ package net.wurstclient.hacks;
import net.wurstclient.Category; import net.wurstclient.Category;
import net.wurstclient.SearchTags; import net.wurstclient.SearchTags;
import net.wurstclient.events.ChatInputListener; import net.wurstclient.events.ChatInputListener;
import net.wurstclient.events.ChatOutputListener;
import net.wurstclient.hack.Hack; import net.wurstclient.hack.Hack;
import net.wurstclient.hacks.chattranslator.FilterOwnMessagesSetting; import net.wurstclient.hacks.chattranslator.FilterOwnMessagesSetting;
import net.wurstclient.hacks.chattranslator.GoogleTranslate; import net.wurstclient.hacks.chattranslator.GoogleTranslate;
import net.wurstclient.hacks.chattranslator.LanguageSetting; import net.wurstclient.hacks.chattranslator.LanguageSetting;
import net.wurstclient.hacks.chattranslator.LanguageSetting.Language; import net.wurstclient.hacks.chattranslator.LanguageSetting.Language;
import net.wurstclient.hacks.chattranslator.WhatToTranslateSetting;
import net.wurstclient.settings.CheckboxSetting;
import net.wurstclient.util.ChatUtils; import net.wurstclient.util.ChatUtils;
@SearchTags({"chat translator", "ChatTranslate", "chat translate", @SearchTags({"chat translator", "ChatTranslate", "chat translate",
@ -22,13 +25,46 @@ import net.wurstclient.util.ChatUtils;
"AutoTranslator", "auto translator", "AutoTranslation", "auto translation", "AutoTranslator", "auto translator", "AutoTranslation", "auto translation",
"GoogleTranslate", "google translate", "GoogleTranslator", "GoogleTranslate", "google translate", "GoogleTranslator",
"google translator", "GoogleTranslation", "google translation"}) "google translator", "GoogleTranslation", "google translation"})
public final class ChatTranslatorHack extends Hack implements ChatInputListener public final class ChatTranslatorHack extends Hack
implements ChatInputListener, ChatOutputListener
{ {
private final LanguageSetting translateFrom = private final WhatToTranslateSetting whatToTranslate =
LanguageSetting.withAutoDetect("Translate from", Language.AUTO_DETECT); new WhatToTranslateSetting();
private final LanguageSetting translateTo = private final LanguageSetting playerLanguage =
LanguageSetting.withoutAutoDetect("Translate to", Language.ENGLISH); LanguageSetting.withoutAutoDetect("Your language",
"The main language that you can use and understand.\n\n"
+ "Your received messages will always be translated into this"
+ " language (if enabled).\n\n"
+ "When \"Detect sent language\" is turned off, all"
+ " sent messages are assumed to be in this language.",
Language.ENGLISH);
private final LanguageSetting otherLanguage =
LanguageSetting.withoutAutoDetect("Other language",
"The main language used by other players on the server.\n\n"
+ "Your sent messages will always be translated into this"
+ " language (if enabled).\n\n"
+ "When \"Detect received language\" is turned off, all"
+ " received messages are assumed to be in this language.",
Language.CHINESE_SIMPLIFIED);
private final CheckboxSetting autoDetectReceived =
new CheckboxSetting("Detect received language",
"Automatically detect the language of received messages.\n\n"
+ "Useful if other players are using a mix of different"
+ " languages.\n\n"
+ "If everyone is using the same language, turning this off"
+ " can improve accuracy.",
true);
private final CheckboxSetting autoDetectSent =
new CheckboxSetting("Detect sent language",
"Automatically detect the language of sent messages.\n\n"
+ "Useful if you're using a mix of different languages.\n\n"
+ "If you're always using the same language, turning this off"
+ " can improve accuracy.",
true);
private final FilterOwnMessagesSetting filterOwnMessages = private final FilterOwnMessagesSetting filterOwnMessages =
new FilterOwnMessagesSetting(); new FilterOwnMessagesSetting();
@ -37,8 +73,11 @@ public final class ChatTranslatorHack extends Hack implements ChatInputListener
{ {
super("ChatTranslator"); super("ChatTranslator");
setCategory(Category.CHAT); setCategory(Category.CHAT);
addSetting(translateFrom); addSetting(whatToTranslate);
addSetting(translateTo); addSetting(playerLanguage);
addSetting(otherLanguage);
addSetting(autoDetectReceived);
addSetting(autoDetectSent);
addSetting(filterOwnMessages); addSetting(filterOwnMessages);
} }
@ -46,20 +85,26 @@ public final class ChatTranslatorHack extends Hack implements ChatInputListener
protected void onEnable() protected void onEnable()
{ {
EVENTS.add(ChatInputListener.class, this); EVENTS.add(ChatInputListener.class, this);
EVENTS.add(ChatOutputListener.class, this);
} }
@Override @Override
protected void onDisable() protected void onDisable()
{ {
EVENTS.remove(ChatInputListener.class, this); EVENTS.remove(ChatInputListener.class, this);
EVENTS.remove(ChatOutputListener.class, this);
} }
@Override @Override
public void onReceivedMessage(ChatInputEvent event) public void onReceivedMessage(ChatInputEvent event)
{ {
if(!whatToTranslate.includesReceived())
return;
String message = event.getComponent().getString(); String message = event.getComponent().getString();
Language fromLang = translateFrom.getSelected(); Language fromLang = autoDetectReceived.isChecked()
Language toLang = translateTo.getSelected(); ? Language.AUTO_DETECT : otherLanguage.getSelected();
Language toLang = playerLanguage.getSelected();
if(message.startsWith(ChatUtils.WURST_PREFIX) if(message.startsWith(ChatUtils.WURST_PREFIX)
|| message.startsWith(toLang.getPrefix())) || message.startsWith(toLang.getPrefix()))
@ -83,4 +128,37 @@ public final class ChatTranslatorHack extends Hack implements ChatInputListener
if(translated != null) if(translated != null)
MC.inGameHud.getChatHud().addMessage(toLang.prefixText(translated)); MC.inGameHud.getChatHud().addMessage(toLang.prefixText(translated));
} }
@Override
public void onSentMessage(ChatOutputEvent event)
{
if(!whatToTranslate.includesSent())
return;
String message = event.getMessage();
Language fromLang = autoDetectSent.isChecked() ? Language.AUTO_DETECT
: playerLanguage.getSelected();
Language toLang = otherLanguage.getSelected();
if(message.startsWith("/") || message.startsWith("."))
return;
event.cancel();
Thread.ofVirtual().name("ChatTranslator")
.uncaughtExceptionHandler((t, e) -> e.printStackTrace())
.start(() -> sendTranslated(message, fromLang, toLang));
}
private void sendTranslated(String message, Language fromLang,
Language toLang)
{
String translated = GoogleTranslate.translate(message,
fromLang.getValue(), toLang.getValue());
if(translated == null)
translated = message;
MC.getNetworkHandler().sendChatMessage(translated);
}
} }

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2014-2024 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.hacks.chattranslator;
import net.wurstclient.settings.EnumSetting;
public final class WhatToTranslateSetting
extends EnumSetting<WhatToTranslateSetting.WhatToTranslate>
{
public WhatToTranslateSetting()
{
super("Translate", "", WhatToTranslate.values(),
WhatToTranslate.RECEIVED_MESSAGES);
}
public boolean includesReceived()
{
return getSelected().received;
}
public boolean includesSent()
{
return getSelected().sent;
}
public enum WhatToTranslate
{
RECEIVED_MESSAGES("Received messages", true, false),
SENT_MESSAGES("Sent messages", false, true),
BOTH("Both", true, true);
private final String name;
private final boolean received;
private final boolean sent;
private WhatToTranslate(String name, boolean received, boolean sent)
{
this.name = name;
this.received = received;
this.sent = sent;
}
@Override
public String toString()
{
return name;
}
}
}

View File

@ -51,7 +51,7 @@
"description.wurst.hack.cameradistance": "Umožňuje změnit vzdálenost kamery ve 3. osobě.", "description.wurst.hack.cameradistance": "Umožňuje změnit vzdálenost kamery ve 3. osobě.",
"description.wurst.hack.cameranoclip": "Umožňuje kameře ve třetí osobě procházet zdmi.", "description.wurst.hack.cameranoclip": "Umožňuje kameře ve třetí osobě procházet zdmi.",
"description.wurst.hack.cavefinder": "Pomáhá najít jeskyně tím, že je zvýrazní vybranou barvou.", "description.wurst.hack.cavefinder": "Pomáhá najít jeskyně tím, že je zvýrazní vybranou barvou.",
"description.wurst.hack.chattranslator": "Překládá příchozí zprávy v chatu pomocí Google Translate.", "description.wurst.hack.chattranslator": "Překládá zprávy v chatu pomocí Google Translate.",
"description.wurst.hack.chestesp": "Zvýrazní okolní truhly.", "description.wurst.hack.chestesp": "Zvýrazní okolní truhly.",
"description.wurst.hack.clickaura": "S každým kliknutím automaticky zaútočí na nejbližší platnou entitu.\n\n§c§lWAROVÁNÍ:§r ClickAury sjou obecně podezřelejší než Killaury a jsou i snadněji rozpoznatelné pro pluginy. Doporučuje se namísto nich používat buďto Killauru, či TriggerBota.", "description.wurst.hack.clickaura": "S každým kliknutím automaticky zaútočí na nejbližší platnou entitu.\n\n§c§lWAROVÁNÍ:§r ClickAury sjou obecně podezřelejší než Killaury a jsou i snadněji rozpoznatelné pro pluginy. Doporučuje se namísto nich používat buďto Killauru, či TriggerBota.",
"description.wurst.hack.clickgui": "Okenní rozhraní ClickGUI.", "description.wurst.hack.clickgui": "Okenní rozhraní ClickGUI.",

View File

@ -54,7 +54,7 @@
"description.wurst.hack.cameradistance": "Ermöglicht dir, den Kamera-Abstand in der 3rd-Person-Ansicht zu ändern.", "description.wurst.hack.cameradistance": "Ermöglicht dir, den Kamera-Abstand in der 3rd-Person-Ansicht zu ändern.",
"description.wurst.hack.cameranoclip": "Ermöglicht der Kamera in der 3rd-Person-Ansicht, durch Wände zu gehen.", "description.wurst.hack.cameranoclip": "Ermöglicht der Kamera in der 3rd-Person-Ansicht, durch Wände zu gehen.",
"description.wurst.hack.cavefinder": "Markiert Höhlen in der ausgewählten Farbe, sodass du sie leichter finden kannst.", "description.wurst.hack.cavefinder": "Markiert Höhlen in der ausgewählten Farbe, sodass du sie leichter finden kannst.",
"description.wurst.hack.chattranslator": "Übersetzt eingehende Chat-Nachrichten mit dem Google-Übersetzer.", "description.wurst.hack.chattranslator": "Übersetzt Chat-Nachrichten mit dem Google-Übersetzer.",
"description.wurst.hack.chestesp": "Markiert Kisten in deiner Umgebung.", "description.wurst.hack.chestesp": "Markiert Kisten in deiner Umgebung.",
"description.wurst.hack.clickaura": "Greift bei jedem Mausklick automatisch den nächsten Mob oder Spieler an.\n\n§c§lWARNUNG:§r ClickAuras sind generell auffälliger als Killauras und für Plugins leichter zu erkennen. Es ist empfohlen, statt ClickAura Killaura oder TriggerBot zu benutzen.", "description.wurst.hack.clickaura": "Greift bei jedem Mausklick automatisch den nächsten Mob oder Spieler an.\n\n§c§lWARNUNG:§r ClickAuras sind generell auffälliger als Killauras und für Plugins leichter zu erkennen. Es ist empfohlen, statt ClickAura Killaura oder TriggerBot zu benutzen.",
"description.wurst.hack.clickgui": "Fenster-basierte ClickGUI.", "description.wurst.hack.clickgui": "Fenster-basierte ClickGUI.",

View File

@ -73,7 +73,7 @@
"description.wurst.hack.cameradistance": "Allows you to change the camera distance in 3rd person.", "description.wurst.hack.cameradistance": "Allows you to change the camera distance in 3rd person.",
"description.wurst.hack.cameranoclip": "Allows the camera in 3rd person to go through walls.", "description.wurst.hack.cameranoclip": "Allows the camera in 3rd person to go through walls.",
"description.wurst.hack.cavefinder": "Helps you to find caves by highlighting them in the selected color.", "description.wurst.hack.cavefinder": "Helps you to find caves by highlighting them in the selected color.",
"description.wurst.hack.chattranslator": "Translates incoming chat messages using Google Translate.", "description.wurst.hack.chattranslator": "Translates chat messages using Google Translate.",
"description.wurst.hack.chestesp": "Highlights nearby chests.", "description.wurst.hack.chestesp": "Highlights nearby chests.",
"description.wurst.hack.clickaura": "Automatically attacks the closest valid entity whenever you click.\n\n§c§lWARNING:§r ClickAuras generally look more suspicious than Killauras and are easier for plugins to detect. It is recommended to use Killaura or TriggerBot instead.", "description.wurst.hack.clickaura": "Automatically attacks the closest valid entity whenever you click.\n\n§c§lWARNING:§r ClickAuras generally look more suspicious than Killauras and are easier for plugins to detect. It is recommended to use Killaura or TriggerBot instead.",
"description.wurst.hack.clickgui": "Window-based ClickGUI.", "description.wurst.hack.clickgui": "Window-based ClickGUI.",

View File

@ -48,7 +48,7 @@
"description.wurst.hack.bunnyhop": "Vous fait sauter automatiquement.", "description.wurst.hack.bunnyhop": "Vous fait sauter automatiquement.",
"description.wurst.hack.cameranoclip": "Permet à la caméra à la 3ème personne de traverser les murs.", "description.wurst.hack.cameranoclip": "Permet à la caméra à la 3ème personne de traverser les murs.",
"description.wurst.hack.cavefinder": "Vous aide à trouver des grottes en les mettant en surbrillance dans la couleur sélectionnée.", "description.wurst.hack.cavefinder": "Vous aide à trouver des grottes en les mettant en surbrillance dans la couleur sélectionnée.",
"description.wurst.hack.chattranslator": "Traduit les messages de chat entrants à l'aide de Google Traduction.", "description.wurst.hack.chattranslator": "Traduit les messages de chat à l'aide de Google Traduction.",
"description.wurst.hack.chestesp": "Met en évidence les coffres à proximité.", "description.wurst.hack.chestesp": "Met en évidence les coffres à proximité.",
"description.wurst.hack.clickaura": "Attaque automatiquement l'entité valide la plus proche chaque fois que vous cliquez.\n\n§c§lATTENTION:§r ClickAuras semble généralement plus suspect que Killauras et est plus facile à détecter pour les plugins. Il est recommandé d'utiliser Killaura ou TriggerBot à la place.", "description.wurst.hack.clickaura": "Attaque automatiquement l'entité valide la plus proche chaque fois que vous cliquez.\n\n§c§lATTENTION:§r ClickAuras semble généralement plus suspect que Killauras et est plus facile à détecter pour les plugins. Il est recommandé d'utiliser Killaura ou TriggerBot à la place.",
"description.wurst.hack.clickgui": "ClickGUI basé sur une fenêtre.", "description.wurst.hack.clickgui": "ClickGUI basé sur une fenêtre.",

View File

@ -56,7 +56,7 @@
"description.wurst.hack.cameradistance": "3人称視点でカメラとプレイヤーの距離が変更できるようになる。", "description.wurst.hack.cameradistance": "3人称視点でカメラとプレイヤーの距離が変更できるようになる。",
"description.wurst.hack.cameranoclip": "三人称視点のカメラがブロックを貫通するようになる。", "description.wurst.hack.cameranoclip": "三人称視点のカメラがブロックを貫通するようになる。",
"description.wurst.hack.cavefinder": "洞窟を選択した色でハイライト表示し、探しやすくする。", "description.wurst.hack.cavefinder": "洞窟を選択した色でハイライト表示し、探しやすくする。",
"description.wurst.hack.chattranslator": "受信したメッセージをGoogle翻訳で翻訳する。", "description.wurst.hack.chattranslator": "チャットメッセージをGoogle翻訳で翻訳する。",
"description.wurst.hack.chestesp": "付近のチェストをハイライト表示する。", "description.wurst.hack.chestesp": "付近のチェストをハイライト表示する。",
"description.wurst.hack.clickaura": "クリックすると、自動で一番近い有効なエンティティを攻撃する。\n\n§c§l注意: §rClickAuraはKillauraよりも怪しまれやすく、かつPluginに検知されやすいため、代わりにKillauraやTriggerBotの使用を推奨する。", "description.wurst.hack.clickaura": "クリックすると、自動で一番近い有効なエンティティを攻撃する。\n\n§c§l注意: §rClickAuraはKillauraよりも怪しまれやすく、かつPluginに検知されやすいため、代わりにKillauraやTriggerBotの使用を推奨する。",
"description.wurst.hack.clickgui": "ウィンドウタイプのClickGUI。", "description.wurst.hack.clickgui": "ウィンドウタイプのClickGUI。",

View File

@ -51,7 +51,7 @@
"description.wurst.hack.cameradistance": "Pozwala zmienić odległość kamery w trzeciej osobie.", "description.wurst.hack.cameradistance": "Pozwala zmienić odległość kamery w trzeciej osobie.",
"description.wurst.hack.cameranoclip": "Umożliwia kamerze trzecio-osobowej na przenikanie przez ściany.", "description.wurst.hack.cameranoclip": "Umożliwia kamerze trzecio-osobowej na przenikanie przez ściany.",
"description.wurst.hack.cavefinder": "Pomaga znaleźć jaskinie, podświetlając je wybranym kolorem.", "description.wurst.hack.cavefinder": "Pomaga znaleźć jaskinie, podświetlając je wybranym kolorem.",
"description.wurst.hack.chattranslator": "Tłumaczy przychodzące wiadomości z czatu za pomocą Tłumacza Google.", "description.wurst.hack.chattranslator": "Tłumaczy wiadomości z czatu za pomocą Tłumacza Google.",
"description.wurst.hack.chestesp": "Podświetla pobliskie skrzynie.", "description.wurst.hack.chestesp": "Podświetla pobliskie skrzynie.",
"description.wurst.hack.clickaura": "Automatycznie atakuje najbliższy prawidłowy byt za każdym razem, gdy klikniesz.\n\n§c§lOSTRZEŻENIE:§r ClickAury generalnie wyglądają bardziej podejrzanie niż Killaury i są łatwiejsze do wykrycia przez pluginy. Zamiast tego zaleca się użycie Killaury lub TriggerBota.", "description.wurst.hack.clickaura": "Automatycznie atakuje najbliższy prawidłowy byt za każdym razem, gdy klikniesz.\n\n§c§lOSTRZEŻENIE:§r ClickAury generalnie wyglądają bardziej podejrzanie niż Killaury i są łatwiejsze do wykrycia przez pluginy. Zamiast tego zaleca się użycie Killaury lub TriggerBota.",
"description.wurst.hack.clickgui": "ClickGUI oparty na okienkach.", "description.wurst.hack.clickgui": "ClickGUI oparty na okienkach.",

View File

@ -48,7 +48,7 @@
"description.wurst.hack.bunnyhop": "Sari automat.", "description.wurst.hack.bunnyhop": "Sari automat.",
"description.wurst.hack.cameranoclip": "Permite camerei 3rd person sa vada prin pereti.", "description.wurst.hack.cameranoclip": "Permite camerei 3rd person sa vada prin pereti.",
"description.wurst.hack.cavefinder": "Te ajuta sa gasesti pesteri conturandu-le in culoarea aleasa.", "description.wurst.hack.cavefinder": "Te ajuta sa gasesti pesteri conturandu-le in culoarea aleasa.",
"description.wurst.hack.chattranslator": "Traduce mesajele de pe chat folosind Google Translate.", "description.wurst.hack.chattranslator": "Traduce mesajele din chat folosind Google Translate.",
"description.wurst.hack.chestesp": "Contureaza chesturile din apropiere.", "description.wurst.hack.chestesp": "Contureaza chesturile din apropiere.",
"description.wurst.hack.clickaura": "Ataca automat cea mai apropiata entitate atunci cand dai click.\n\n§c§lATENTIE:§r ClickAura este mai suspicios decat Killaura si este mai usor de detectat de catre anumite plugin-uri. Este recomandat in schimb sa folosesti Killaura sau TriggerBot.", "description.wurst.hack.clickaura": "Ataca automat cea mai apropiata entitate atunci cand dai click.\n\n§c§lATENTIE:§r ClickAura este mai suspicios decat Killaura si este mai usor de detectat de catre anumite plugin-uri. Este recomandat in schimb sa folosesti Killaura sau TriggerBot.",
"description.wurst.hack.clickgui": "ClickGUI bazat pe windows.", "description.wurst.hack.clickgui": "ClickGUI bazat pe windows.",

View File

@ -47,7 +47,7 @@
"description.wurst.hack.bunnyhop": "Примушує вас постійно стрибати.", "description.wurst.hack.bunnyhop": "Примушує вас постійно стрибати.",
"description.wurst.hack.cameranoclip": "Дозволяє камеру від 3-ї особи пройти через стіни.", "description.wurst.hack.cameranoclip": "Дозволяє камеру від 3-ї особи пройти через стіни.",
"description.wurst.hack.cavefinder": "Допомагає знайти печери, підсвічуючи їх вибраним кольором.", "description.wurst.hack.cavefinder": "Допомагає знайти печери, підсвічуючи їх вибраним кольором.",
"description.wurst.hack.chattranslator": "Всі вхідні повідомлення в чаті будуть перекладатися Google перекладачем.", "description.wurst.hack.chattranslator": "Перекладає повідомлення в чаті за допомогою Google перекладача.",
"description.wurst.hack.chestesp": "Підсвічує вибраним кольором скрині поблизу.", "description.wurst.hack.chestesp": "Підсвічує вибраним кольором скрині поблизу.",
"description.wurst.hack.clickaura": "Автоматично атакує найближчу сутність, коли ви натискаєте ЛКМ.\n\n§c§lУВАГА:§r ClickAura'и звичайно виглядають більш підозріло, ніж Killaura'и і легше виявляються плагінами. Краще використовувати Killaura або TriggerBot.", "description.wurst.hack.clickaura": "Автоматично атакує найближчу сутність, коли ви натискаєте ЛКМ.\n\n§c§lУВАГА:§r ClickAura'и звичайно виглядають більш підозріло, ніж Killaura'и і легше виявляються плагінами. Краще використовувати Killaura або TriggerBot.",
"description.wurst.hack.clickgui": "Інтерфейс із панелями.", "description.wurst.hack.clickgui": "Інтерфейс із панелями.",