Wear.java 2.6 KB

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