CastleUpdater.java 2.3 KB

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