Lang.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.voicedcommandhandlers;
  16. import java.util.StringTokenizer;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  21. import com.l2jserver.util.StringUtil;
  22. public class Lang implements IVoicedCommandHandler
  23. {
  24. private static final String[] VOICED_COMMANDS =
  25. {
  26. "lang"
  27. };
  28. /**
  29. *
  30. * @see com.l2jserver.gameserver.handler.IVoicedCommandHandler#useVoicedCommand(java.lang.String, com.l2jserver.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
  31. */
  32. public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
  33. {
  34. if (!Config.L2JMOD_MULTILANG_ENABLE
  35. || !Config.L2JMOD_MULTILANG_VOICED_ALLOW)
  36. return false;
  37. NpcHtmlMessage msg = new NpcHtmlMessage(1);
  38. if (params == null)
  39. {
  40. final StringBuilder html = StringUtil.startAppend(100);
  41. for (String lang : Config.L2JMOD_MULTILANG_ALLOWED)
  42. {
  43. StringUtil.append(html,
  44. "<button value=\"",
  45. lang.toUpperCase(),
  46. "\" action=\"bypass -h voice .lang ",
  47. lang,
  48. "\" width=60 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br>"
  49. );
  50. }
  51. msg.setFile(activeChar.getHtmlPrefix(), "data/html/mods/Lang/LanguageSelect.htm");
  52. msg.replace("%list%", html.toString());
  53. activeChar.sendPacket(msg);
  54. return true;
  55. }
  56. StringTokenizer st = new StringTokenizer(params);
  57. if (st.hasMoreTokens())
  58. {
  59. final String lang = st.nextToken().trim();
  60. if (activeChar.setLang(lang))
  61. {
  62. msg.setFile(activeChar.getHtmlPrefix(), "data/html/mods/Lang/Ok.htm");
  63. activeChar.sendPacket(msg);
  64. return true;
  65. }
  66. else
  67. {
  68. msg.setFile(activeChar.getHtmlPrefix(), "data/html/mods/Lang/Error.htm");
  69. activeChar.sendPacket(msg);
  70. }
  71. }
  72. return false;
  73. }
  74. /**
  75. *
  76. * @see com.l2jserver.gameserver.handler.IVoicedCommandHandler#getVoicedCommandList()
  77. */
  78. public String[] getVoicedCommandList()
  79. {
  80. return VOICED_COMMANDS;
  81. }
  82. }