CastleUpdater.java 2.2 KB

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