AdminSummon.java 3.0 KB

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