TvTVoicedInfo.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 com.l2jserver.Config;
  17. import com.l2jserver.gameserver.cache.HtmCache;
  18. import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.entity.TvTEvent;
  21. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  22. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  23. /**
  24. * Tvt info.
  25. * @author denser
  26. */
  27. public class TvTVoicedInfo implements IVoicedCommandHandler
  28. {
  29. private static final String[] _voicedCommands =
  30. {
  31. "tvt"
  32. };
  33. /**
  34. * Set this to false and recompile script if you don't want to use string cache.<br>
  35. * This will decrease performance but will be more consistent against possible html editions during runtime Recompiling the script will get the new html would be enough too [DrHouse]
  36. */
  37. private static final boolean USE_STATIC_HTML = true;
  38. private static final String HTML = HtmCache.getInstance().getHtm(null, "data/html/mods/TvTEvent/Status.htm");
  39. @Override
  40. public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  41. {
  42. if (command.equals("tvt"))
  43. {
  44. if (TvTEvent.isStarting() || TvTEvent.isStarted())
  45. {
  46. String htmContent = (USE_STATIC_HTML && !HTML.isEmpty()) ? HTML : HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/mods/TvTEvent/Status.htm");
  47. try
  48. {
  49. NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(5);
  50. npcHtmlMessage.setHtml(htmContent);
  51. // npcHtmlMessage.replace("%objectId%",
  52. // String.valueOf(getObjectId()));
  53. npcHtmlMessage.replace("%team1name%", Config.TVT_EVENT_TEAM_1_NAME);
  54. npcHtmlMessage.replace("%team1playercount%", String.valueOf(TvTEvent.getTeamsPlayerCounts()[0]));
  55. npcHtmlMessage.replace("%team1points%", String.valueOf(TvTEvent.getTeamsPoints()[0]));
  56. npcHtmlMessage.replace("%team2name%", Config.TVT_EVENT_TEAM_2_NAME);
  57. npcHtmlMessage.replace("%team2playercount%", String.valueOf(TvTEvent.getTeamsPlayerCounts()[1]));
  58. npcHtmlMessage.replace("%team2points%", String.valueOf(TvTEvent.getTeamsPoints()[1]));
  59. activeChar.sendPacket(npcHtmlMessage);
  60. }
  61. catch (Exception e)
  62. {
  63. _log.warning("wrong TvT voiced: " + e);
  64. }
  65. }
  66. else
  67. {
  68. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  69. }
  70. }
  71. return true;
  72. }
  73. @Override
  74. public String[] getVoicedCommandList()
  75. {
  76. return _voicedCommands;
  77. }
  78. }