CastleUpdater.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* This program is free software; you can redistribute it and/or modify
  2. * it under the terms of the GNU General Public License as published by
  3. * the Free Software Foundation; either version 2, or (at your option)
  4. * any later version.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  14. * 02111-1307, USA.
  15. *
  16. * http://www.gnu.org/copyleft/gpl.html
  17. */
  18. package net.sf.l2j.gameserver;
  19. import java.util.logging.Logger;
  20. import net.sf.l2j.Config;
  21. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  22. import net.sf.l2j.gameserver.model.ItemContainer;
  23. import net.sf.l2j.gameserver.model.L2Clan;
  24. import net.sf.l2j.gameserver.model.entity.Castle;
  25. /**
  26. *
  27. * Thorgrim - 2005
  28. * Class managing periodical events with castle
  29. *
  30. */
  31. public class CastleUpdater implements Runnable
  32. {
  33. protected static Logger _log = Logger.getLogger(CastleUpdater.class.getName());
  34. private L2Clan _clan;
  35. private int _runCount = 0;
  36. public CastleUpdater(L2Clan clan, int runCount)
  37. {
  38. _clan = clan;
  39. _runCount = runCount;
  40. }
  41. public void run()
  42. {
  43. try
  44. {
  45. // Move current castle treasury to clan warehouse every 2 hour
  46. ItemContainer warehouse = _clan.getWarehouse();
  47. if ((warehouse != null) && (_clan.getHasCastle() > 0))
  48. {
  49. Castle castle = CastleManager.getInstance().getCastleById(_clan.getHasCastle());
  50. if (!Config.ALT_MANOR_SAVE_ALL_ACTIONS)
  51. {
  52. if (_runCount % Config.ALT_MANOR_SAVE_PERIOD_RATE == 0)
  53. {
  54. castle.saveSeedData();
  55. castle.saveCropData();
  56. _log.info("Manor System: all data for " + castle.getName() + " saved");
  57. }
  58. }
  59. _runCount++;
  60. CastleUpdater cu = new CastleUpdater(_clan, _runCount);
  61. ThreadPoolManager.getInstance().scheduleGeneral(cu, 3600000);
  62. }
  63. } catch (Throwable e) {
  64. e.printStackTrace();
  65. }
  66. }
  67. }