CastleUpdater.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 com.l2jserver.gameserver;
  16. import java.util.logging.Level;
  17. import java.util.logging.Logger;
  18. import com.l2jserver.Config;
  19. import com.l2jserver.gameserver.instancemanager.CastleManager;
  20. import com.l2jserver.gameserver.model.L2Clan;
  21. import com.l2jserver.gameserver.model.entity.Castle;
  22. import com.l2jserver.gameserver.model.itemcontainer.ItemContainer;
  23. /**
  24. * Class managing periodical events with castle
  25. * @author Thorgrim - 2005
  26. */
  27. public class CastleUpdater implements Runnable
  28. {
  29. protected static final Logger _log = Logger.getLogger(CastleUpdater.class.getName());
  30. private L2Clan _clan;
  31. private int _runCount = 0;
  32. public CastleUpdater(L2Clan clan, int runCount)
  33. {
  34. _clan = clan;
  35. _runCount = runCount;
  36. }
  37. @Override
  38. public void run()
  39. {
  40. try
  41. {
  42. // Move current castle treasury to clan warehouse every 2 hour
  43. ItemContainer warehouse = _clan.getWarehouse();
  44. if ((warehouse != null) && (_clan.getCastleId() > 0))
  45. {
  46. Castle castle = CastleManager.getInstance().getCastleById(_clan.getCastleId());
  47. if (!Config.ALT_MANOR_SAVE_ALL_ACTIONS)
  48. {
  49. if (_runCount % Config.ALT_MANOR_SAVE_PERIOD_RATE == 0)
  50. {
  51. castle.saveSeedData();
  52. castle.saveCropData();
  53. if (Config.DEBUG)
  54. _log.info("Manor System: all data for " + castle.getName() + " saved");
  55. }
  56. }
  57. CastleUpdater cu = new CastleUpdater(_clan, ++_runCount);
  58. ThreadPoolManager.getInstance().scheduleGeneral(cu, 3600000);
  59. }
  60. }
  61. catch (Exception e)
  62. {
  63. _log.log(Level.WARNING, "", e);
  64. }
  65. }
  66. }