CastleUpdater.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 net.sf.l2j.gameserver;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  19. import net.sf.l2j.gameserver.model.ItemContainer;
  20. import net.sf.l2j.gameserver.model.L2Clan;
  21. import net.sf.l2j.gameserver.model.entity.Castle;
  22. /**
  23. *
  24. * Thorgrim - 2005
  25. * Class managing periodical events with castle
  26. *
  27. */
  28. public class CastleUpdater implements Runnable
  29. {
  30. protected static final Logger _log = Logger.getLogger(CastleUpdater.class.getName());
  31. private L2Clan _clan;
  32. private int _runCount = 0;
  33. public CastleUpdater(L2Clan clan, int runCount)
  34. {
  35. _clan = clan;
  36. _runCount = runCount;
  37. }
  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.getHasCastle() > 0))
  45. {
  46. Castle castle = CastleManager.getInstance().getCastleById(_clan.getHasCastle());
  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. _log.info("Manor System: all data for " + castle.getName() + " saved");
  54. }
  55. }
  56. _runCount++;
  57. CastleUpdater cu = new CastleUpdater(_clan, _runCount);
  58. ThreadPoolManager.getInstance().scheduleGeneral(cu, 3600000);
  59. }
  60. } catch (Throwable e) {
  61. e.printStackTrace();
  62. }
  63. }
  64. }