AdminDoorControl.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 com.l2jserver.gameserver.datatables.DoorTable;
  17. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  18. import com.l2jserver.gameserver.instancemanager.CastleManager;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.entity.Castle;
  23. /**
  24. * This class handles following admin commands:
  25. * - open1 = open coloseum door 24190001
  26. * - open2 = open coloseum door 24190002
  27. * - open3 = open coloseum door 24190003
  28. * - open4 = open coloseum door 24190004
  29. * - openall = open all coloseum door
  30. * - close1 = close coloseum door 24190001
  31. * - close2 = close coloseum door 24190002
  32. * - close3 = close coloseum door 24190003
  33. * - close4 = close coloseum door 24190004
  34. * - closeall = close all coloseum door
  35. *
  36. * - open = open selected door
  37. * - close = close selected door
  38. * @version $Revision: 1.2.4.5 $ $Date: 2005/04/11 10:06:06 $
  39. */
  40. public class AdminDoorControl implements IAdminCommandHandler
  41. {
  42. private static DoorTable _doorTable = DoorTable.getInstance();
  43. private static final String[] ADMIN_COMMANDS =
  44. {
  45. "admin_open",
  46. "admin_close",
  47. "admin_openall",
  48. "admin_closeall"
  49. };
  50. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  51. {
  52. try
  53. {
  54. if (command.startsWith("admin_open "))
  55. {
  56. int doorId = Integer.parseInt(command.substring(11));
  57. if (_doorTable.getDoor(doorId) != null)
  58. _doorTable.getDoor(doorId).openMe();
  59. else
  60. {
  61. for (Castle castle : CastleManager.getInstance().getCastles())
  62. if (castle.getDoor(doorId) != null)
  63. {
  64. castle.getDoor(doorId).openMe();
  65. }
  66. }
  67. }
  68. else if (command.startsWith("admin_close "))
  69. {
  70. int doorId = Integer.parseInt(command.substring(12));
  71. if (_doorTable.getDoor(doorId) != null)
  72. _doorTable.getDoor(doorId).closeMe();
  73. else
  74. {
  75. for (Castle castle : CastleManager.getInstance().getCastles())
  76. if (castle.getDoor(doorId) != null)
  77. {
  78. castle.getDoor(doorId).closeMe();
  79. }
  80. }
  81. }
  82. if (command.equals("admin_closeall"))
  83. {
  84. for (L2DoorInstance door : _doorTable.getDoors())
  85. door.closeMe();
  86. for (Castle castle : CastleManager.getInstance().getCastles())
  87. for (L2DoorInstance door : castle.getDoors())
  88. door.closeMe();
  89. }
  90. if (command.equals("admin_openall"))
  91. {
  92. for (L2DoorInstance door : _doorTable.getDoors())
  93. door.openMe();
  94. for (Castle castle : CastleManager.getInstance().getCastles())
  95. for (L2DoorInstance door : castle.getDoors())
  96. door.openMe();
  97. }
  98. if (command.equals("admin_open"))
  99. {
  100. L2Object target = activeChar.getTarget();
  101. if (target instanceof L2DoorInstance)
  102. {
  103. ((L2DoorInstance) target).openMe();
  104. }
  105. else
  106. {
  107. activeChar.sendMessage("Incorrect target.");
  108. }
  109. }
  110. if (command.equals("admin_close"))
  111. {
  112. L2Object target = activeChar.getTarget();
  113. if (target instanceof L2DoorInstance)
  114. {
  115. ((L2DoorInstance) target).closeMe();
  116. }
  117. else
  118. {
  119. activeChar.sendMessage("Incorrect target.");
  120. }
  121. }
  122. }
  123. catch (Exception e)
  124. {
  125. e.printStackTrace();
  126. }
  127. return true;
  128. }
  129. public String[] getAdminCommandList()
  130. {
  131. return ADMIN_COMMANDS;
  132. }
  133. }