Lang.java 2.6 KB

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