Guest User

Untitled

a guest
Aug 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. public synchronized void store()
  2.     {
  3.         store(false);
  4.     }
  5.  
  6.  
  7.  
  8.     public synchronized void store(boolean items)
  9.     {
  10.         _log.warn("Store");
  11.         Connection con = null;
  12.         try
  13.         {
  14.             con = L2DatabaseFactory.getInstance().getConnection();
  15.  
  16.             if (_jailTask != null)
  17.             {
  18.                 long delay = _jailTask.getDelay(TimeUnit.MILLISECONDS);
  19.                 if (delay < 0)
  20.                     delay = 0;
  21.                 setJailTimer(delay);
  22.             }
  23.  
  24.             try
  25.             {
  26.                 storeCharBase(con);
  27.             }
  28.             catch(Exception e)
  29.             {
  30.                 _log.error("L2PcInstance: Error saving character "+getName()+", bugload possible",e);
  31.                 e.printStackTrace();
  32.             }
  33.  
  34.             try
  35.             {
  36.                 storeCharSub(con);
  37.             }
  38.             catch(Exception e)
  39.             {
  40.                 _log.error("L2PcInstance: Error saving character "+getName()+" subclasses, not fatal",e);
  41.             }
  42.  
  43.             try
  44.             {
  45.                 storeRecipeBook(con);
  46.             }
  47.             catch(Exception e)
  48.             {
  49.                 _log.error("L2PcInstance: Error saving character "+getName()+" recipies, not fatal",e);
  50.             }
  51.  
  52.             try
  53.             {
  54.                 saveSettingInDb(con);
  55.             }
  56.             catch(Exception e)
  57.             {
  58.                 _log.error("L2PcInstance: Error saving character "+getName()+" settings, not fatal",e);
  59.             }  
  60.                
  61.             if (items)
  62.             {
  63.                 getInventory().updateDatabase();
  64.                 if(_warehouse!=null)
  65.                     _warehouse.updateDatabase();
  66.                 if(_freight!=null)
  67.                     _freight.updateDatabase();
  68.                 SQLQueue.getInstance().run();
  69.             }
  70.         }
  71.         catch(SQLException e)
  72.         {
  73.             _log.error("L2PcInstance: Connection to DB lost",e);
  74.         }
  75.         finally
  76.         {
  77.             if(con!=null)
  78.                 try
  79.             {
  80.                 con.close();
  81.             }
  82.             catch(SQLException e)
  83.             {}
  84.         }
  85.        
  86.     }
  87.  
  88.     private ScheduledFuture<?> _autoSaveTask;
  89.     private class AutoSave implements Runnable
  90.     {
  91.         public void run()
  92.         {
  93.                 store();
  94.         }
  95.     }
  96.  
  97.     public void startAutoSave()
  98.     {
  99.         if (Config.CHAR_STORE_INTERVAL > 0)
  100.         {
  101.             long delay = Config.CHAR_STORE_INTERVAL * 60000L;
  102.             if (_autoSaveTask == null)
  103.                 _autoSaveTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoSave(), delay, delay);
  104.         }
  105.     }
  106.  
  107.     public void stopAutoSave()
  108.     {
  109.         if (_autoSaveTask != null)
  110.         {
  111.             _autoSaveTask.cancel(false);
  112.             _autoSaveTask = null;
  113.         }
  114.     }
  115. }
Add Comment
Please, Sign In to add comment