AdminEvents.java 4.8 KB

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