Clean-up for Travis.

This commit is contained in:
Ian William O'Neill
2019-06-30 02:32:13 +01:00
committed by Ian W. ONeill
parent 3c0e1bef47
commit 608471f30d
4 changed files with 37 additions and 16 deletions

View File

@@ -15,7 +15,10 @@ public interface ChatTranslationConfig extends Config
position = 0,
group = "Public Chat Translation"
)
default boolean publicChat() { return false; }
default boolean publicChat()
{
return false;
}
@ConfigItem(
keyName = "publicTargetLanguage",
@@ -38,7 +41,10 @@ public interface ChatTranslationConfig extends Config
position = 2,
group = "Player Message Translation"
)
default boolean playerChat() { return false; }
default boolean playerChat()
{
return false;
}
@ConfigItem(
keyName = "playerTargetLanguage",

View File

@@ -21,7 +21,6 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginType;
import org.apache.commons.lang3.ArrayUtils;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Provider;
import java.awt.event.KeyEvent;
@@ -32,7 +31,8 @@ import java.awt.event.KeyEvent;
tags = {"translate", "language", "english", "spanish", "dutch", "french"},
type = PluginType.UTILITY
)
public class ChatTranslationPlugin extends Plugin implements KeyListener {
public class ChatTranslationPlugin extends Plugin implements KeyListener
{
public static final String TRANSLATE = "Translate";
private static final ImmutableList<String> AFTER_OPTIONS = ImmutableList.of("Message", "Add ignore", "Remove friend", "Kick");
@@ -144,7 +144,8 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener {
Translator translator = new Translator();
try {
try
{
//Automatically check language of message and translate to selected language.
String translation = translator.translate("auto", config.publicTargetLanguage().toString(), message);
if (translation != null)
@@ -153,7 +154,9 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener {
messageNode.setRuneLiteFormatMessage(translation);
chatMessageManager.update(messageNode);
}
} catch (Exception e) {
}
catch (Exception e)
{
e.printStackTrace();
}
@@ -161,8 +164,10 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener {
}
@Override
public void keyPressed(KeyEvent event) {
if (client.getGameState() != GameState.LOADING && client.getGameState() != GameState.LOGGED_IN) {
public void keyPressed(KeyEvent event)
{
if (client.getGameState() != GameState.LOADING && client.getGameState() != GameState.LOGGED_IN)
{
return;
}
@@ -183,7 +188,8 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener {
String message = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
try {
try
{
//Automatically check language of message and translate to selected language.
String translation = translator.translate("auto", config.playerTargetLanguage().toString(), message);
@@ -191,18 +197,24 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener {
{
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translation);
clientThread.invoke(() -> {
clientThread.invoke(() ->
{
client.runScript(96, 0, translation);
});
}
);
}
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
} catch (Exception e) {
}
catch (Exception e)
{
e.printStackTrace();
}
}
} else {
}
else
{
return;
}
}

View File

@@ -1,6 +1,7 @@
package net.runelite.client.plugins.chattranslation;
public enum Languages {
public enum Languages
{
ENGLISH("en"),
DUTCH("nl"),

View File

@@ -8,7 +8,8 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class Translator {
public class Translator
{
public String translate(String source, String target, String message) throws Exception
{
@@ -23,7 +24,8 @@ public class Translator {
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
while ((inputLine = in.readLine()) != null)
{
response.append(inputLine);
}
in.close();