Advertisement
VANPER

Announce olympiad period end

Feb 11th, 2020
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.22 KB | None | 0 0
  1. Index: net.sf.l2j;Config.java
  2. ===================================================================
  3. --- net.sf.l2j;Config.java (revision 84)
  4. +++ net.sf.l2j;Config.java (working copy)
  5.  
  6. +   /** Custom Olympiad Settings */
  7. +   public static boolean OLYMPIAD_END_ANNOUNE;
  8.  
  9.  
  10. +   OLYMPIAD_END_ANNOUNE = events.getProperty("OlyEndAnnounce", true);
  11.  
  12.  
  13. Index: net.sf.l2j.gameserver.network.clientpackets;EnterWorld.java
  14. ===================================================================
  15. --- net.sf.l2j.gameserver.network.clientpackets;EnterWorld.java (revision 84)
  16. +++ net.sf.l2j.gameserver.network.clientpackets;EnterWorld.java (working copy)
  17.  
  18.         // Announcements, welcome & Seven signs period messages
  19.         activeChar.sendPacket(SystemMessageId.WELCOME_TO_LINEAGE);
  20.         activeChar.sendPacket(SevenSigns.getInstance().getCurrentPeriod().getMessageId());
  21.         AnnouncementData.getInstance().showAnnouncements(activeChar, false);
  22.        
  23. +       if (Config.OLYMPIAD_END_ANNOUNE)
  24. +           Olympiad.getInstance().olympiadEnd(activeChar);
  25.  
  26. Index: net.sf.l2j.gameserver.model.olympiad;Olympiad.java
  27. ===================================================================
  28. --- net.sf.l2j.gameserver.model.olympiad;Olympiad.java (revision 84)
  29. +++ net.sf.l2j.gameserver.model.olympiad;Olympiad.java (working copy)
  30.  
  31. +   import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  32.  
  33. -   import net.sf.l2j.gameserver.enums.OlympiadState;
  34. -   import net.sf.l2j.gameserver.model.olympiad.Olympiad.ValidationEndTask;
  35.  
  36. -   protected OlympiadState _period;
  37.  
  38. +   public static int _period;
  39.  
  40. -   protected Olympiad()
  41. -   {
  42. -       load();
  43. -      
  44. -       if (_period == OlympiadState.COMPETITION)
  45. -           init();
  46. -   }
  47.  
  48. +   protected Olympiad()
  49. +   {
  50. +       load();
  51. +      
  52. +       if (_period == 0)
  53. +           init();
  54. +   }
  55.  
  56.     private void load()
  57.     {
  58.         try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  59.             PreparedStatement ps = con.prepareStatement(OLYMPIAD_LOAD_DATA);
  60.             ResultSet rs = ps.executeQuery())
  61.         {
  62.             if (rs.next())
  63.             {
  64.                 _currentCycle = rs.getInt("current_cycle");
  65. -               _period = Enum.valueOf(OlympiadState.class, rs.getString("period"));
  66.  
  67. +               _period = rs.getInt("period");
  68.  
  69.                 _olympiadEnd = rs.getLong("olympiad_end");
  70.                 _validationEnd = rs.getLong("validation_end");
  71.                 _nextWeeklyChange = rs.getLong("next_weekly_change");
  72.             }
  73.  
  74.     _currentCycle = 1;
  75. -   _period = OlympiadState.COMPETITION
  76. +   _period = 0;
  77.     _olympiadEnd = 0;
  78.     _validationEnd = 0;
  79.     _nextWeeklyChange = 0;
  80.    
  81. -   switch (_period)
  82. -   {
  83. -       case COMPETITION:
  84. -           if (_olympiadEnd == 0 || _olympiadEnd < Calendar.getInstance().getTimeInMillis())
  85. -               setNewOlympiadEnd();
  86. -           else
  87. -               scheduleWeeklyChange();
  88. -           break;
  89. -      
  90. -       case VALIDATION:
  91. -           if (_validationEnd > Calendar.getInstance().getTimeInMillis())
  92. -           {
  93. -               loadNoblesRank();
  94. -               _scheduledValdationTask = ThreadPool.schedule(new ValidationEndTask(), getMillisToValidationEnd());
  95. -           }
  96. -           else
  97. -           {
  98. -               _currentCycle++;
  99. -               _period = OlympiadState.COMPETITION;
  100. -               deleteNobles();
  101. -               setNewOlympiadEnd();
  102. -           }
  103. -           break;
  104. -   }
  105.            
  106. +   switch (_period)
  107. +   {
  108. +       case 0:
  109. +           if (_olympiadEnd == 0 || _olympiadEnd < Calendar.getInstance().getTimeInMillis())
  110. +               setNewOlympiadEnd();
  111. +           else
  112. +               scheduleWeeklyChange();
  113. +           break;
  114. +       case 1:
  115. +           if (_validationEnd > Calendar.getInstance().getTimeInMillis())
  116. +           {
  117. +               loadNoblesRank();
  118. +               _scheduledValdationTask = ThreadPool.schedule(new ValidationEndTask(), getMillisToValidationEnd());
  119. +           }
  120. +           else
  121. +           {
  122. +               _currentCycle++;
  123. +               _period = 0;
  124. +               deleteNobles();
  125. +               setNewOlympiadEnd();
  126. +           }
  127. +           break;
  128. +       default:
  129. +           LOGGER.info("Olympiad: something went wrong loading period: " + _period);
  130. +           return;
  131. +   }
  132.  
  133. -   synchronized (this)
  134. -   {
  135. -       long milliToEnd;
  136. -       if (_period == OlympiadState.COMPETITION)
  137. -           milliToEnd = getMillisToOlympiadEnd();
  138. -       else
  139. -           milliToEnd = getMillisToValidationEnd();
  140. -      
  141. -       LOGGER.info("{} minutes until Olympiad period ends.", Math.round(milliToEnd / 60000));
  142. -      
  143. -       if (_period == OlympiadState.COMPETITION)
  144. -       {
  145. -           milliToEnd = getMillisToWeekChange();
  146. -           LOGGER.info("Next weekly Olympiad change is in {} minutes.", Math.round(milliToEnd / 60000));
  147. -       }
  148. -   }
  149.  
  150. +       synchronized (this)
  151. +       {
  152. +           if (_period == 0)
  153. +               LOGGER.info("Olympiad: Currently in Competition period.");
  154. +           else
  155. +               LOGGER.info("Olympiad: Currently in Validation period.");
  156. +          
  157. +           long milliToEnd;
  158. +           if (_period == 0)
  159. +               milliToEnd = getMillisToOlympiadEnd();
  160. +           else
  161. +               milliToEnd = getMillisToValidationEnd();
  162. +          
  163. +           double numSecs = milliToEnd / 1000 % 60;
  164. +           double countDown = (milliToEnd / 1000 - numSecs) / 60;
  165. +           final int numMins = (int) Math.floor(countDown % 60);
  166. +           countDown = (countDown - numMins) / 60;
  167. +           int numHours = (int) Math.floor(countDown % 24);
  168. +           int numDays = (int) Math.floor((countDown - numHours) / 24);
  169. +          
  170. +           LOGGER.info("Olympiad System: " + numDays + " days, " + numHours + " hours and " + numMins + " mins. until period ends");
  171. +          
  172. +           if (_period == 0)
  173. +           {
  174. +               long milliToEnd2 = getMillisToWeekChange();
  175. +              
  176. +               double numSecs1 = milliToEnd2 / 1000 % 60;
  177. +               double countDown1 = (milliToEnd2 / 1000 - numSecs1) / 60;
  178. +               final int numMins1 = (int) Math.floor(countDown1 % 60);
  179. +               countDown1 = (countDown - numMins1) / 60;
  180. +               int numHours1 = (int) Math.floor(countDown1 % 24);
  181. +               int numDays1 = (int) Math.floor((countDown1 - numHours1) / 24);
  182. +              
  183. +               LOGGER.info("Olympiad System: Next weekly change in " + numDays1 + " days, " + numHours1 + " hours and " + numMins1 + " mins.");
  184. +           }
  185. +       }
  186. +       LOGGER.info("Olympiad: Loaded " + _nobles.size() + " nobles.");
  187.  
  188. Index: no copy  }
  189.  
  190. -   protected void init()
  191. -   {
  192. -   if (_period == OlympiadState.VALIDATION)
  193. -   return;
  194.    
  195. +   protected void init()
  196. +   {
  197. +   if (_period == 1)
  198. +   return;
  199.  
  200. -   saveNobleData();
  201. +   saveNobleData();
  202.  
  203. -   _period = OlympiadState.VALIDATION;
  204.  
  205. +   _period = 1;
  206.  
  207. -   protected class ValidationEndTask implements Runnable
  208. -   {
  209. -       @Override
  210. -       public void run()
  211. -       {
  212. -           _period = OlympiadState.COMPETITION;
  213. -           _currentCycle++;
  214. -          
  215. -           deleteNobles();
  216. -           setNewOlympiadEnd();
  217. -           init();
  218. -       }
  219. -   }
  220.  
  221. +   protected class ValidationEndTask implements Runnable
  222. +   {
  223. +       @Override
  224. +       public void run()
  225. +       {
  226. +           _period = 0;
  227. +           _currentCycle++;
  228. +          
  229. +           deleteNobles();
  230. +           setNewOlympiadEnd();
  231. +           init();
  232. +       }
  233. +   }
  234.  
  235.         Calendar currentTime = Calendar.getInstance();
  236. -       currentTime.add(Calendar.MONTH, 1);
  237. -       currentTime.set(Calendar.DAY_OF_MONTH, 1);
  238. +       currentTime.set(Calendar.DAY_OF_WEEK, 7);
  239.         currentTime.set(Calendar.AM_PM, Calendar.AM);
  240.         currentTime.set(Calendar.HOUR, 12);
  241.         currentTime.set(Calendar.MINUTE, 0);
  242.  
  243. -   public boolean isOlympiadEnd()
  244. -   {
  245. -       return _period == OlympiadState.VALIDATION;
  246. -   }
  247.  
  248. +   public boolean isOlympiadEnd()
  249. +   {
  250. +       return _period != 0;
  251. +   }
  252.  
  253. -   protected synchronized void addWeeklyPoints()
  254. -   {
  255. -   if (_period == OlympiadState.VALIDATION)
  256. -   return;
  257.  
  258. +   protected synchronized void addWeeklyPoints()
  259. +   {
  260. +   if (_period == 1)
  261. +   return;
  262.  
  263. -   public void saveOlympiadStatus()
  264. -   {
  265. -       saveNobleData();
  266. -      
  267. -       try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  268. -           PreparedStatement ps = con.prepareStatement(OLYMPIAD_SAVE_DATA))
  269. -       {
  270. -           ps.setInt(1, _currentCycle);
  271. -           ps.setString(2, _period.toString());
  272. -           ps.setLong(3, _olympiadEnd);
  273. -           ps.setLong(4, _validationEnd);
  274. -           ps.setLong(5, _nextWeeklyChange);
  275. -           ps.setInt(6, _currentCycle);
  276. -           ps.setString(7, _period.toString());
  277. -           ps.setLong(8, _olympiadEnd);
  278. -           ps.setLong(9, _validationEnd);
  279. -           ps.setLong(10, _nextWeeklyChange);
  280. -           ps.execute();
  281. -       }
  282. -       catch (Exception e)
  283. -       {
  284. -           LOGGER.error("Couldn't save Olympiad status.", e);
  285. -       }
  286. -   }
  287.  
  288. +   public void olympiadEnd(Player player)
  289. +   {
  290. +       long endtime;
  291. +       if (_period == 0)
  292. +           endtime = getMillisToOlympiadEnd();
  293. +       else
  294. +           endtime = getMillisToValidationEnd();
  295. +      
  296. +       double seconds = endtime / 1000 % 60;
  297. +       double countdown = (endtime / 1000 - seconds) / 60;
  298. +       int minutes = (int) Math.floor(countdown % 60);
  299. +       countdown = (countdown - minutes) / 60;
  300. +       int hours = (int) Math.floor(countdown % 24);
  301. +       int days = (int) Math.floor((countdown - hours) / 24);
  302. +  
  303. +  
  304. +       new CreatureSay(SayType.CRITICAL_ANNOUNCE, null, "Olympiad competitions: " + days + " days, " + hours + " hours and " + minutes + " mins until period ends.");
  305. +   }
  306.  
  307. +   public void saveOlympiadStatus()
  308. +   {
  309. +       saveNobleData();
  310. +      
  311. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  312. +       {
  313. +           final PreparedStatement statement = con.prepareStatement(OLYMPIAD_SAVE_DATA);
  314. +          
  315. +           statement.setInt(1, _currentCycle);
  316. +           statement.setInt(2, _period);
  317. +           statement.setLong(3, _olympiadEnd);
  318. +           statement.setLong(4, _validationEnd);
  319. +           statement.setLong(5, _nextWeeklyChange);
  320. +           statement.setInt(6, _currentCycle);
  321. +           statement.setInt(7, _period);
  322. +           statement.setLong(8, _olympiadEnd);
  323. +           statement.setLong(9, _validationEnd);
  324. +           statement.setLong(10, _nextWeeklyChange);
  325. +          
  326. +           statement.execute();
  327. +           statement.close();
  328. +       }
  329. +       catch (SQLException e)
  330. +       {
  331. +           _log.log(Level.SEVERE, "Olympiad: Failed to save olympiad data to database: ", e);
  332. +       }
  333. +   }
  334.  
  335.     public void saveOlympiadStatus()
  336.     {
  337.     saveNobleData();
  338.     try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  339.     PreparedStatement ps = con.prepareStatement(OLYMPIAD_SAVE_DATA))
  340.     {
  341.    
  342. -   ps.setInt(1, _currentCycle);
  343. +   ps.setInt(1, _currentCycle);
  344.  
  345. -   ps.setString(2, _period.toString());
  346. +   ps.setInt(2, _period);
  347.  
  348. -   ps.setInt(6, _currentCycle);
  349. +   ps.setInt(6, _currentCycle);
  350.  
  351. -   ps.setString(7, _period.toString());
  352. +   ps.setInt(7, _period);
  353.  
  354. -   public int getNoblessePasses(Player player, boolean clear)
  355. -   {
  356. -   if (player == null || _period != OlympiadState.VALIDATION || _noblesRank.isEmpty())
  357. -   return 0;
  358.  
  359. +   public int getNoblessePasses(Player player, boolean clear)
  360. +   {
  361. +   if (player == null || _period != 1 || _noblesRank.isEmpty())
  362. +   return 0;
  363.  
  364.  
  365. Index: config/events.properties
  366. ===================================================================
  367. --- config/events.properties (revision 84)
  368. +++ config/events.properties (working copy)
  369.  
  370. +   # Announce olympiad period end
  371. +   OlyEndAnnounce = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement