TvTVoicedInfo.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  39. {
  40. if (command.equalsIgnoreCase("tvt"))
  41. {
  42. if (TvTEvent.isStarting() || TvTEvent.isStarted())
  43. {
  44. String htmContent = (USE_STATIC_HTML && !HTML.isEmpty()) ? HTML :
  45. HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/mods/TvTEvent/Status.htm");
  46. try
  47. {
  48. NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(5);
  49. npcHtmlMessage.setHtml(htmContent);
  50. // npcHtmlMessage.replace("%objectId%",
  51. // String.valueOf(getObjectId()));
  52. npcHtmlMessage.replace("%team1name%", Config.TVT_EVENT_TEAM_1_NAME);
  53. npcHtmlMessage.replace("%team1playercount%", String.valueOf(TvTEvent.getTeamsPlayerCounts()[0]));
  54. npcHtmlMessage.replace("%team1points%", String.valueOf(TvTEvent.getTeamsPoints()[0]));
  55. npcHtmlMessage.replace("%team2name%", Config.TVT_EVENT_TEAM_2_NAME);
  56. npcHtmlMessage.replace("%team2playercount%", String.valueOf(TvTEvent.getTeamsPlayerCounts()[1]));
  57. npcHtmlMessage.replace("%team2points%", String.valueOf(TvTEvent.getTeamsPoints()[1]));
  58. activeChar.sendPacket(npcHtmlMessage);
  59. }
  60. catch (Exception e)
  61. {
  62. _log.warning("wrong TvT voiced: " + e);
  63. }
  64. }
  65. else
  66. {
  67. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  68. }
  69. }
  70. return true;
  71. }
  72. public String[] getVoicedCommandList()
  73. {
  74. return _voicedCommands;
  75. }
  76. }