chattranslationplugin: Combine nested if statemnets
This commit is contained in:
@@ -3,8 +3,17 @@ package net.runelite.client.plugins.chattranslation;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
import net.runelite.api.*;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.VarClientStr;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
@@ -24,11 +33,6 @@ import net.runelite.client.plugins.PluginType;
|
||||
import net.runelite.client.util.Text;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Chat Translator",
|
||||
description = "Translates messages from one Language to another.",
|
||||
@@ -84,12 +88,9 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
||||
{
|
||||
updateConfig();
|
||||
|
||||
if (client != null)
|
||||
if (client != null && this.translateOptionVisable)
|
||||
{
|
||||
if (this.translateOptionVisable)
|
||||
{
|
||||
menuManager.get().addPlayerMenuItem(TRANSLATE);
|
||||
}
|
||||
menuManager.get().addPlayerMenuItem(TRANSLATE);
|
||||
}
|
||||
keyManager.registerKeyListener(this);
|
||||
|
||||
@@ -99,12 +100,9 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
||||
@Override
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
if (client != null)
|
||||
if (client != null && this.translateOptionVisable)
|
||||
{
|
||||
if (this.translateOptionVisable)
|
||||
{
|
||||
menuManager.get().removePlayerMenuItem(TRANSLATE);
|
||||
}
|
||||
menuManager.get().removePlayerMenuItem(TRANSLATE);
|
||||
}
|
||||
keyManager.unregisterKeyListener(this);
|
||||
|
||||
@@ -246,47 +244,44 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
||||
|
||||
Widget chatboxParent = client.getWidget(WidgetInfo.CHATBOX_PARENT);
|
||||
|
||||
if (chatboxParent != null && chatboxParent.getOnKeyListener() != null)
|
||||
if (chatboxParent != null && chatboxParent.getOnKeyListener() != null && event.getKeyCode() == 0xA)
|
||||
{
|
||||
if (event.getKeyCode() == 0xA)
|
||||
Translator translator = new Translator();
|
||||
String message = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
|
||||
|
||||
if (message.startsWith("/"))
|
||||
{
|
||||
Translator translator = new Translator();
|
||||
String message = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
|
||||
|
||||
if (message.startsWith("/"))
|
||||
{
|
||||
try
|
||||
{
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translator.translate("auto", config.playerTargetLanguage().toString(), message));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
event.consume();
|
||||
|
||||
try
|
||||
{
|
||||
//Automatically check language of message and translate to selected language.
|
||||
String translation = translator.translate("auto", this.playerTargetLanguage.toString(), message);
|
||||
if (translation != null)
|
||||
{
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translation);
|
||||
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
client.runScript(96, 0, translation);
|
||||
});
|
||||
}
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translator.translate("auto", config.playerTargetLanguage().toString(), message));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
event.consume();
|
||||
|
||||
try
|
||||
{
|
||||
//Automatically check language of message and translate to selected language.
|
||||
String translation = translator.translate("auto", this.playerTargetLanguage.toString(), message);
|
||||
if (translation != null)
|
||||
{
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translation);
|
||||
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
client.runScript(96, 0, translation);
|
||||
});
|
||||
}
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user