Wear.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.bypasshandlers;
  16. import java.util.StringTokenizer;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.TradeController;
  19. import com.l2jserver.gameserver.handler.IBypassHandler;
  20. import com.l2jserver.gameserver.model.L2TradeList;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  25. import com.l2jserver.gameserver.network.serverpackets.ShopPreviewList;
  26. public class Wear implements IBypassHandler
  27. {
  28. private static final String[] COMMANDS =
  29. {
  30. "Wear"
  31. };
  32. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  33. {
  34. if (!(target instanceof L2Npc))
  35. return false;
  36. if (!Config.ALLOW_WEAR)
  37. return false;
  38. try
  39. {
  40. StringTokenizer st = new StringTokenizer(command, " ");
  41. st.nextToken();
  42. if (st.countTokens() < 1)
  43. return false;
  44. showWearWindow(activeChar, Integer.parseInt(st.nextToken()));
  45. return true;
  46. }
  47. catch (Exception e)
  48. {
  49. _log.info("Exception in " + getClass().getSimpleName());
  50. }
  51. return false;
  52. }
  53. private static final void showWearWindow(L2PcInstance player, int val)
  54. {
  55. player.tempInventoryDisable();
  56. if (Config.DEBUG)
  57. _log.fine("Showing wearlist");
  58. L2TradeList list = TradeController.getInstance().getBuyList(val);
  59. if (list != null)
  60. {
  61. ShopPreviewList bl = new ShopPreviewList(list, player.getAdena(), player.getExpertiseLevel());
  62. player.sendPacket(bl);
  63. }
  64. else
  65. {
  66. _log.warning("no buylist with id:" + val);
  67. player.sendPacket(ActionFailed.STATIC_PACKET);
  68. }
  69. }
  70. public String[] getBypassList()
  71. {
  72. return COMMANDS;
  73. }
  74. }