AdminSummon.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.logging.Logger;
  17. import com.l2jserver.gameserver.datatables.AdminCommandAccessRights;
  18. import com.l2jserver.gameserver.handler.AdminCommandHandler;
  19. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. /**
  22. *
  23. * @author poltomb
  24. */
  25. public class AdminSummon implements IAdminCommandHandler
  26. {
  27. Logger _log = Logger.getLogger(AdminSummon.class.getName());
  28. public static final String[] ADMIN_COMMANDS =
  29. {
  30. "admin_summon"
  31. };
  32. /**
  33. * @see com.l2jserver.gameserver.handler.IAdminCommandHandler#getAdminCommandList()
  34. */
  35. public String[] getAdminCommandList()
  36. {
  37. return ADMIN_COMMANDS;
  38. }
  39. /**
  40. * @see com.l2jserver.gameserver.handler.IAdminCommandHandler#useAdminCommand(java.lang.String, com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
  41. */
  42. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  43. {
  44. int id;
  45. int count=1;
  46. String[] data = command.split(" ");
  47. try
  48. {
  49. id = Integer.parseInt(data[1]);
  50. if (data.length > 2)
  51. {
  52. count = Integer.parseInt(data[2]);
  53. }
  54. }
  55. catch (NumberFormatException nfe)
  56. {
  57. activeChar.sendMessage("Incorrect format for command 'summon'");
  58. return false;
  59. }
  60. String subCommand;
  61. if (id < 1000000)
  62. {
  63. subCommand = "admin_create_item";
  64. if (!AdminCommandAccessRights.getInstance().hasAccess(subCommand, activeChar.getAccessLevel()))
  65. {
  66. activeChar.sendMessage("You don't have the access right to use this command!");
  67. _log.warning("Character " + activeChar.getName() + " tryed to use admin command " + subCommand + ", but have no access to it!");
  68. return false;
  69. }
  70. IAdminCommandHandler ach = AdminCommandHandler.getInstance().getAdminCommandHandler(subCommand);
  71. ach.useAdminCommand(subCommand + " " + id + " " + count, activeChar);
  72. }
  73. else
  74. {
  75. subCommand = "admin_spawn_once";
  76. if (!AdminCommandAccessRights.getInstance().hasAccess(subCommand, activeChar.getAccessLevel()))
  77. {
  78. activeChar.sendMessage("You don't have the access right to use this command!");
  79. _log.warning("Character " + activeChar.getName() + " tryed to use admin command " + subCommand + ", but have no access to it!");
  80. return false;
  81. }
  82. IAdminCommandHandler ach = AdminCommandHandler.getInstance().getAdminCommandHandler(subCommand);
  83. activeChar.sendMessage("This is only a temporary spawn. The mob(s) will NOT respawn.");
  84. id -= 1000000;
  85. ach.useAdminCommand(subCommand + " " + id + " " + count, activeChar);
  86. }
  87. return true;
  88. }
  89. }