AdminEvents.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) 2004-2015 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.admincommandhandlers;
  20. import java.util.StringTokenizer;
  21. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  22. import com.l2jserver.gameserver.instancemanager.QuestManager;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.quest.Event;
  25. import com.l2jserver.gameserver.model.quest.Quest;
  26. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  27. import com.l2jserver.util.StringUtil;
  28. public class AdminEvents implements IAdminCommandHandler
  29. {
  30. private static final String[] ADMIN_COMMANDS =
  31. {
  32. "admin_event_menu",
  33. "admin_event_start",
  34. "admin_event_stop",
  35. "admin_event_start_menu",
  36. "admin_event_stop_menu",
  37. "admin_event_bypass"
  38. };
  39. @Override
  40. public String[] getAdminCommandList()
  41. {
  42. return ADMIN_COMMANDS;
  43. }
  44. @Override
  45. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  46. {
  47. if (activeChar == null)
  48. {
  49. return false;
  50. }
  51. String event_name = "";
  52. String _event_bypass = "";
  53. StringTokenizer st = new StringTokenizer(command, " ");
  54. st.nextToken();
  55. if (st.hasMoreTokens())
  56. {
  57. event_name = st.nextToken();
  58. }
  59. if (st.hasMoreTokens())
  60. {
  61. _event_bypass = st.nextToken();
  62. }
  63. if (command.contains("_menu"))
  64. {
  65. showMenu(activeChar);
  66. }
  67. if (command.startsWith("admin_event_start"))
  68. {
  69. try
  70. {
  71. if (event_name != null)
  72. {
  73. Event event = (Event) QuestManager.getInstance().getQuest(event_name);
  74. if (event != null)
  75. {
  76. if (event.eventStart(activeChar))
  77. {
  78. activeChar.sendMessage("Event " + event_name + " started.");
  79. return true;
  80. }
  81. activeChar.sendMessage("There is problem starting " + event_name + " event.");
  82. return true;
  83. }
  84. }
  85. }
  86. catch (Exception e)
  87. {
  88. activeChar.sendMessage("Usage: //event_start <eventname>");
  89. e.printStackTrace();
  90. return false;
  91. }
  92. }
  93. else if (command.startsWith("admin_event_stop"))
  94. {
  95. try
  96. {
  97. if (event_name != null)
  98. {
  99. Event event = (Event) QuestManager.getInstance().getQuest(event_name);
  100. if (event != null)
  101. {
  102. if (event.eventStop())
  103. {
  104. activeChar.sendMessage("Event " + event_name + " stopped.");
  105. return true;
  106. }
  107. activeChar.sendMessage("There is problem with stoping " + event_name + " event.");
  108. return true;
  109. }
  110. }
  111. }
  112. catch (Exception e)
  113. {
  114. activeChar.sendMessage("Usage: //event_start <eventname>");
  115. e.printStackTrace();
  116. return false;
  117. }
  118. }
  119. else if (command.startsWith("admin_event_bypass"))
  120. {
  121. try
  122. {
  123. if (event_name != null)
  124. {
  125. Event event = (Event) QuestManager.getInstance().getQuest(event_name);
  126. if (event != null)
  127. {
  128. event.eventBypass(activeChar, _event_bypass);
  129. }
  130. }
  131. }
  132. catch (Exception e)
  133. {
  134. activeChar.sendMessage("Usage: //event_bypass <eventname> <bypass>");
  135. e.printStackTrace();
  136. return false;
  137. }
  138. }
  139. return false;
  140. }
  141. private void showMenu(L2PcInstance activeChar)
  142. {
  143. final NpcHtmlMessage html = new NpcHtmlMessage();
  144. html.setFile(activeChar.getHtmlPrefix(), "data/html/admin/gm_events.htm");
  145. final StringBuilder cList = new StringBuilder(500);
  146. for (Quest event : QuestManager.getInstance().getScripts().values())
  147. {
  148. if (event instanceof Event)
  149. {
  150. StringUtil.append(cList, "<font color=\"LEVEL\">" + event.getName() + ":</font><br1>", "<table width=270><tr>", "<td><button value=\"Start\" action=\"bypass -h admin_event_start_menu " + event.getName() + "\" width=80 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>", "<td><button value=\"Stop\" action=\"bypass -h admin_event_stop_menu " + event.getName() + "\" width=80 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>", "<td><button value=\"Menu\" action=\"bypass -h admin_event_bypass " + event.getName() + "\" width=80 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>", "</tr></table><br>");
  151. }
  152. }
  153. html.replace("%LIST%", cList.toString());
  154. activeChar.sendPacket(html);
  155. }
  156. }