TvTVoicedInfo.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. *
  26. * @author denser
  27. */
  28. public class TvTVoicedInfo implements IVoicedCommandHandler
  29. {
  30. private static final String[] _voicedCommands = { "tvt" };
  31. /**
  32. * Set this to false and recompile script if you dont want to use string cache.
  33. * This will decrease performance but will be more consistent against possible html editions during runtime
  34. * Recompiling the script will get the new html would be enough too [DrHouse]
  35. */
  36. private static final boolean USE_STATIC_HTML = true;
  37. private static final String HTML = HtmCache.getInstance().getHtm(null, "data/html/mods/TvTEvent/Status.htm");
  38. @Override
  39. public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  40. {
  41. if (command.equalsIgnoreCase("tvt"))
  42. {
  43. if (TvTEvent.isStarting() || TvTEvent.isStarted())
  44. {
  45. String htmContent = (USE_STATIC_HTML && !HTML.isEmpty()) ? HTML :
  46. 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. }