TvTVoicedInfo.java 3.2 KB

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