AdminSummon.java 3.3 KB

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