AdminShop.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 java.util.logging.Logger;
  21. import com.l2jserver.gameserver.data.xml.impl.BuyListData;
  22. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.buylist.L2BuyList;
  25. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  26. import com.l2jserver.gameserver.network.serverpackets.BuyList;
  27. import com.l2jserver.gameserver.network.serverpackets.ExBuySellList;
  28. /**
  29. * This class handles following admin commands:
  30. * <ul>
  31. * <li>gmshop = shows menu</li>
  32. * <li>buy id = shows shop with respective id</li>
  33. * </ul>
  34. */
  35. public class AdminShop implements IAdminCommandHandler
  36. {
  37. private static final Logger _log = Logger.getLogger(AdminShop.class.getName());
  38. private static final String[] ADMIN_COMMANDS =
  39. {
  40. "admin_buy",
  41. "admin_gmshop"
  42. };
  43. @Override
  44. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  45. {
  46. if (command.startsWith("admin_buy"))
  47. {
  48. try
  49. {
  50. handleBuyRequest(activeChar, command.substring(10));
  51. }
  52. catch (IndexOutOfBoundsException e)
  53. {
  54. activeChar.sendMessage("Please specify buylist.");
  55. }
  56. }
  57. else if (command.equals("admin_gmshop"))
  58. {
  59. AdminHtml.showAdminHtml(activeChar, "gmshops.htm");
  60. }
  61. return true;
  62. }
  63. @Override
  64. public String[] getAdminCommandList()
  65. {
  66. return ADMIN_COMMANDS;
  67. }
  68. private void handleBuyRequest(L2PcInstance activeChar, String command)
  69. {
  70. int val = -1;
  71. try
  72. {
  73. val = Integer.parseInt(command);
  74. }
  75. catch (Exception e)
  76. {
  77. _log.warning("admin buylist failed:" + command);
  78. }
  79. L2BuyList buyList = BuyListData.getInstance().getBuyList(val);
  80. if (buyList != null)
  81. {
  82. activeChar.sendPacket(new BuyList(buyList, activeChar.getAdena(), 0));
  83. activeChar.sendPacket(new ExBuySellList(activeChar, false));
  84. }
  85. else
  86. {
  87. _log.warning("no buylist with id:" + val);
  88. }
  89. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  90. }
  91. }