MessageDeletionTask.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.instancemanager.tasks;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import com.l2jserver.gameserver.instancemanager.MailManager;
  23. import com.l2jserver.gameserver.model.L2World;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.entity.Message;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. /**
  29. * Message deletion task.
  30. * @author xban1x
  31. */
  32. public final class MessageDeletionTask implements Runnable
  33. {
  34. private static final Logger _log = Logger.getLogger(MessageDeletionTask.class.getName());
  35. final int _msgId;
  36. public MessageDeletionTask(int msgId)
  37. {
  38. _msgId = msgId;
  39. }
  40. @Override
  41. public void run()
  42. {
  43. final Message msg = MailManager.getInstance().getMessage(_msgId);
  44. if (msg == null)
  45. {
  46. return;
  47. }
  48. if (msg.hasAttachments())
  49. {
  50. try
  51. {
  52. final L2PcInstance sender = L2World.getInstance().getPlayer(msg.getSenderId());
  53. if (sender != null)
  54. {
  55. msg.getAttachments().returnToWh(sender.getWarehouse());
  56. sender.sendPacket(SystemMessageId.MAIL_RETURNED);
  57. }
  58. else
  59. {
  60. msg.getAttachments().returnToWh(null);
  61. }
  62. msg.getAttachments().deleteMe();
  63. msg.removeAttachments();
  64. final L2PcInstance receiver = L2World.getInstance().getPlayer(msg.getReceiverId());
  65. if (receiver != null)
  66. {
  67. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.MAIL_RETURNED);
  68. // sm.addString(msg.getReceiverName());
  69. receiver.sendPacket(sm);
  70. }
  71. }
  72. catch (Exception e)
  73. {
  74. _log.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
  75. }
  76. }
  77. MailManager.getInstance().deleteMessageInDb(msg.getId());
  78. }
  79. }