Код:
Index: /trunk/GS_DAG_HighFive/.classpath
===================================================================
--- /trunk/GS_DAG_HighFive/.classpath (revision 39)
+++ /trunk/GS_DAG_HighFive/.classpath (revision 40)
@@ -15,4 +15,5 @@
<classpathentry kind="lib" path="lib/google-api-translate-java-0.94.jar"/>
<classpathentry kind="lib" path="lib/json-20090211.jar"/>
+ <classpathentry kind="lib" path="lib/InetAddressLocator.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Index: /trunk/GS_DAG_HighFive/java/config/dagoptions.properties
===================================================================
--- /trunk/GS_DAG_HighFive/java/config/dagoptions.properties (revision 39)
+++ /trunk/GS_DAG_HighFive/java/config/dagoptions.properties (revision 40)
@@ -11,2 +11,5 @@
CrystalEnchantChanceJewelry 100
+# Configuracao para tradutor do Google.
+# Para mostrar Site de Referencia.
+MySite = www.devdag.com
Index: /trunk/GS_DAG_HighFive/java/com/l2jserver/gameserver/network/clientpackets/Say2.java
===================================================================
--- /trunk/GS_DAG_HighFive/java/com/l2jserver/gameserver/network/clientpackets/Say2.java (revision 39)
+++ /trunk/GS_DAG_HighFive/java/com/l2jserver/gameserver/network/clientpackets/Say2.java (revision 40)
@@ -20,4 +20,5 @@
import com.l2jserver.Config;
+import com.l2jserver.dag.extras.L2JTradutor;
import com.l2jserver.gameserver.handler.ChatHandler;
import com.l2jserver.gameserver.handler.IChatHandler;
@@ -199,5 +200,8 @@
IChatHandler handler = ChatHandler.getInstance().getChatHandler(_type);
if (handler != null)
+ {
+ _text = L2JTradutor.handleTranslation(_text, _type, activeChar, _target);
handler.handleChat(_type, activeChar, _target, _text);
+ }
else
_log.info("No handler registered for ChatType: "+_type+ " Player: "+getClient());
Index: /trunk/GS_DAG_HighFive/java/com/l2jserver/gameserver/GameServer.java
===================================================================
--- /trunk/GS_DAG_HighFive/java/com/l2jserver/gameserver/GameServer.java (revision 39)
+++ /trunk/GS_DAG_HighFive/java/com/l2jserver/gameserver/GameServer.java (revision 40)
@@ -33,4 +33,5 @@
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.Server;
+import com.l2jserver.dag.extras.L2JTradutor;
import com.l2jserver.gameserver.cache.CrestCache;
import com.l2jserver.gameserver.cache.HtmCache;
@@ -309,4 +310,7 @@
CursedWeaponsManager.getInstance();
+ printSection("Custons TeaM DAG");
+ L2JTradutor.load();
+
printSection("Scripts");
QuestManager.getInstance();
Index: /trunk/GS_DAG_HighFive/java/com/l2jserver/Config.java
===================================================================
--- /trunk/GS_DAG_HighFive/java/com/l2jserver/Config.java (revision 39)
+++ /trunk/GS_DAG_HighFive/java/com/l2jserver/Config.java (revision 40)
@@ -635,4 +635,5 @@
public static int CRYSTAL_ENCHANT_CHANCE_ARMOR;
public static int CRYSTAL_ENCHANT_CHANCE_JEWELRY;
+ public static String END_SITE;
@@ -1201,4 +1202,5 @@
CRYSTAL_ENCHANT_CHANCE_ARMOR = Integer.parseInt(DAGSettings.getProperty("CrystalEnchantChanceArmor", "100"));
CRYSTAL_ENCHANT_CHANCE_JEWELRY = Integer.parseInt(DAGSettings.getProperty("CrystalEnchantChanceJewelry", "100"));
+ END_SITE = DAGSettings.getProperty("MySite", "www.devdag.com");
}
catch (Exception e)
Index: /trunk/GS_DAG_HighFive/java/com/l2jserver/dag/extras/L2JTradutor.java
===================================================================
--- /trunk/GS_DAG_HighFive/java/com/l2jserver/dag/extras/L2JTradutor.java (revision 40)
+++ /trunk/GS_DAG_HighFive/java/com/l2jserver/dag/extras/L2JTradutor.java (revision 40)
@@ -0,0 +1,175 @@
+package com.l2jserver.dag.extras;
+
+import java.util.Locale;
+
+import javolution.util.FastMap;
+import net.sf.javainetlocator.InetAddressLocator;
+import net.sf.javainetlocator.InetAddressLocatorException;
+
+import com.google.api.GoogleAPI;
+import com.google.api.translate.Language;
+import com.google.api.translate.Translate;
+import com.l2jserver.Config;
+import com.l2jserver.gameserver.model.L2Object;
+import com.l2jserver.gameserver.model.L2World;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author Issle - Re-Editador Over12
+ *
+ */
+public class L2JTradutor
+{
+ public static boolean allowPlayers = false;
+ public static Language baseLanguage = Language.ENGLISH;
+
+ //Keeps track of the language each person speaks
+ //besides the base language.
+ public static FastMap<Integer,Language> sessions;
+
+ //In the current version the session is one to one.
+ //Multi point ( conference ) will be supported in the
+ //future.
+ public static FastMap<Integer, Integer> partnership;
+
+ //Holds the list of available languages used by the
+ //system.
+ public static FastMap<String, Language> languages;
+
+
+ public static void load()
+ {
+ sessions = new FastMap<Integer,Language>();
+ partnership = new FastMap<Integer,Integer>();
+ languages = new FastMap<String, Language>();
+
+ //Add languages here. Could also use .toString()
+ //or .name() to get the name of the enumeration
+ //participant.
+ languages.put("spanish", Language.SPANISH);
+ languages.put("bulgarian", Language.BULGARIAN);
+ languages.put("czech", Language.CZECH);
+ languages.put("greek", Language.GREEK);
+ languages.put("polish", Language.POLISH);
+ languages.put("portuguese", Language.PORTUGUESE);
+ languages.put("romanian", Language.ROMANIAN);
+ languages.put("russian", Language.RUSSIAN);
+ }
+
+ public static void generateSession(String command, L2PcInstance activeChar, String params)
+ {
+ if(!activeChar.isGM() && !allowPlayers)
+ {
+ activeChar.sendMessage("Apenas 1 Gm por vez pode usar a traducao.");
+ return;
+ }
+
+ if(command.equals("traduzir"))
+ {
+ if(params == null || !languages.containsKey(params))
+ {
+ String totallang ="";
+ activeChar.sendMessage("Nao foi selecionado nenhum Edioma. Usa-se <language> onde pode ser:");
+ for(String s: languages.keySet())
+ {
+ totallang+= s+"/";
+ }
+ activeChar.sendMessage(totallang);
+ return;
+ }
+
+ Language targetl;
+ targetl = Language.ENGLISH;
+
+ targetl = languages.get(params);
+ activeChar.sendMessage(params+" Edioma selecionado.");
+
+ if(activeChar.getTarget()== null || !(activeChar.getTarget() instanceof L2PcInstance))
+ {
+ activeChar.sendMessage("Voce precisa selecionar algum player.");
+ return;
+ }
+
+ L2PcInstance target = (L2PcInstance)activeChar.getTarget();
+
+ sessions.put(target.getObjectId(), targetl);
+ sessions.put(activeChar.getObjectId(), baseLanguage);
+
+ partnership.put(target.getObjectId(), activeChar.getObjectId());
+ partnership.put(activeChar.getObjectId(), target.getObjectId());
+
+ activeChar.sendMessage("Voce iniciou a traducao.");
+ target.sendMessage("GM Iniciou a traducao aguarde.");
+
+ }
+ else if(command.equals("fimTradutor"))
+ {
+ if(!partnership.containsKey(activeChar.getObjectId()))
+ {
+ activeChar.sendMessage("Voce nao esta em sessao de traducao no momento.");
+ return;
+ }
+
+ int targetId = partnership.get(activeChar.getObjectId());
+ sessions.remove(targetId);
+ sessions.remove(activeChar.getObjectId());
+ partnership.remove(targetId);
+ partnership.remove(activeChar.getObjectId());
+ activeChar.sendMessage("Fim de traducao.");
+ }
+ }
+
+ public static String handleTranslation(String _text, int messageType, L2PcInstance activeChar, String target) {
+
+ L2PcInstance receiver = L2World.getInstance().getPlayer(target);
+
+ if(receiver == null)
+ return _text;
+
+ if(partnership.containsKey(activeChar.getObjectId()) && partnership.get(activeChar.getObjectId())== receiver.getObjectId())
+ {
+ GoogleAPI.setHttpReferrer(Config.END_SITE);
+ Language senderLang = sessions.get(activeChar.getObjectId());
+ Language receiverLang = sessions.get(receiver.getObjectId());
+
+ try {
+ return Translate.execute(_text, senderLang, receiverLang);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ return _text;
+ }
+
+ public static void locatePlayer(L2PcInstance activeChar)
+ {
+ L2Object target = activeChar.getTarget();
+
+ if(!(target instanceof L2PcInstance))
+ {
+ activeChar.sendMessage("Nao tem como localizar um player sem estar online.");
+ return;
+ }
+
+ L2PcInstance targetPlayer = (L2PcInstance)target;
+
+ if(activeChar.isGM() || allowPlayers)
+ {
+ try
+ {
+ byte[] ip = targetPlayer.getClient().getConnectionAddress().getAddress();
+ String location = InetAddressLocator.getLocale(ip).getDisplayCountry(Locale.ENGLISH);
+ activeChar.sendMessage("Player "+ targetPlayer.getName()+" e de: "+ location);
+ }
+ catch (InetAddressLocatorException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ else
+ activeChar.sendMessage("Voce nao tem a permisao");
+ }
+}
google-api-translate-java-0.94.jar
json-20090211.jar
InetAddressLocator.jar