AdminShop.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.Config;
  18. import com.l2jserver.gameserver.TradeController;
  19. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  20. import com.l2jserver.gameserver.model.L2TradeList;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  23. import com.l2jserver.gameserver.network.serverpackets.BuyList;
  24. import com.l2jserver.gameserver.network.serverpackets.ExBuySellListPacket;
  25. /**
  26. * This class handles following admin commands:
  27. * - gmshop = shows menu
  28. * - buy id = shows shop with respective id
  29. * @version $Revision: 1.2.4.4 $ $Date: 2005/04/11 10:06:06 $
  30. */
  31. public class AdminShop implements IAdminCommandHandler
  32. {
  33. private static Logger _log = Logger.getLogger(AdminShop.class.getName());
  34. private static final String[] ADMIN_COMMANDS =
  35. {
  36. "admin_buy",
  37. "admin_gmshop"
  38. };
  39. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  40. {
  41. if (command.startsWith("admin_buy"))
  42. {
  43. try
  44. {
  45. handleBuyRequest(activeChar, command.substring(10));
  46. }
  47. catch (IndexOutOfBoundsException e)
  48. {
  49. activeChar.sendMessage("Please specify buylist.");
  50. }
  51. }
  52. else if (command.equals("admin_gmshop"))
  53. {
  54. AdminHelpPage.showHelpPage(activeChar, "gmshops.htm");
  55. }
  56. return true;
  57. }
  58. public String[] getAdminCommandList()
  59. {
  60. return ADMIN_COMMANDS;
  61. }
  62. private void handleBuyRequest(L2PcInstance activeChar, String command)
  63. {
  64. int val = -1;
  65. try
  66. {
  67. val = Integer.parseInt(command);
  68. }
  69. catch (Exception e)
  70. {
  71. _log.warning("admin buylist failed:" + command);
  72. }
  73. L2TradeList list = TradeController.getInstance().getBuyList(val);
  74. if (list != null)
  75. {
  76. activeChar.sendPacket(new BuyList(list, activeChar.getAdena(), 0));
  77. activeChar.sendPacket(new ExBuySellListPacket(activeChar, list, 0, false));
  78. if (Config.DEBUG)
  79. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") opened GM shop id " + val);
  80. }
  81. else
  82. {
  83. _log.warning("no buylist with id:" + val);
  84. }
  85. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  86. }
  87. }