AdminDoorControl.java 4.3 KB

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