AdminEvents.java 4.8 KB

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