Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: net.sf.l2j;Config.java
- ===================================================================
- --- net.sf.l2j;Config.java (revision 84)
- +++ net.sf.l2j;Config.java (working copy)
- + /** Custom Olympiad Settings */
- + public static boolean OLYMPIAD_END_ANNOUNE;
- + OLYMPIAD_END_ANNOUNE = events.getProperty("OlyEndAnnounce", true);
- Index: net.sf.l2j.gameserver.network.clientpackets;EnterWorld.java
- ===================================================================
- --- net.sf.l2j.gameserver.network.clientpackets;EnterWorld.java (revision 84)
- +++ net.sf.l2j.gameserver.network.clientpackets;EnterWorld.java (working copy)
- // Announcements, welcome & Seven signs period messages
- activeChar.sendPacket(SystemMessageId.WELCOME_TO_LINEAGE);
- activeChar.sendPacket(SevenSigns.getInstance().getCurrentPeriod().getMessageId());
- AnnouncementData.getInstance().showAnnouncements(activeChar, false);
- + if (Config.OLYMPIAD_END_ANNOUNE)
- + Olympiad.getInstance().olympiadEnd(activeChar);
- Index: net.sf.l2j.gameserver.model.olympiad;Olympiad.java
- ===================================================================
- --- net.sf.l2j.gameserver.model.olympiad;Olympiad.java (revision 84)
- +++ net.sf.l2j.gameserver.model.olympiad;Olympiad.java (working copy)
- + import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
- - import net.sf.l2j.gameserver.enums.OlympiadState;
- - import net.sf.l2j.gameserver.model.olympiad.Olympiad.ValidationEndTask;
- - protected OlympiadState _period;
- + public static int _period;
- - protected Olympiad()
- - {
- - load();
- -
- - if (_period == OlympiadState.COMPETITION)
- - init();
- - }
- + protected Olympiad()
- + {
- + load();
- +
- + if (_period == 0)
- + init();
- + }
- private void load()
- {
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement(OLYMPIAD_LOAD_DATA);
- ResultSet rs = ps.executeQuery())
- {
- if (rs.next())
- {
- _currentCycle = rs.getInt("current_cycle");
- - _period = Enum.valueOf(OlympiadState.class, rs.getString("period"));
- + _period = rs.getInt("period");
- _olympiadEnd = rs.getLong("olympiad_end");
- _validationEnd = rs.getLong("validation_end");
- _nextWeeklyChange = rs.getLong("next_weekly_change");
- }
- _currentCycle = 1;
- - _period = OlympiadState.COMPETITION
- + _period = 0;
- _olympiadEnd = 0;
- _validationEnd = 0;
- _nextWeeklyChange = 0;
- - switch (_period)
- - {
- - case COMPETITION:
- - if (_olympiadEnd == 0 || _olympiadEnd < Calendar.getInstance().getTimeInMillis())
- - setNewOlympiadEnd();
- - else
- - scheduleWeeklyChange();
- - break;
- -
- - case VALIDATION:
- - if (_validationEnd > Calendar.getInstance().getTimeInMillis())
- - {
- - loadNoblesRank();
- - _scheduledValdationTask = ThreadPool.schedule(new ValidationEndTask(), getMillisToValidationEnd());
- - }
- - else
- - {
- - _currentCycle++;
- - _period = OlympiadState.COMPETITION;
- - deleteNobles();
- - setNewOlympiadEnd();
- - }
- - break;
- - }
- + switch (_period)
- + {
- + case 0:
- + if (_olympiadEnd == 0 || _olympiadEnd < Calendar.getInstance().getTimeInMillis())
- + setNewOlympiadEnd();
- + else
- + scheduleWeeklyChange();
- + break;
- + case 1:
- + if (_validationEnd > Calendar.getInstance().getTimeInMillis())
- + {
- + loadNoblesRank();
- + _scheduledValdationTask = ThreadPool.schedule(new ValidationEndTask(), getMillisToValidationEnd());
- + }
- + else
- + {
- + _currentCycle++;
- + _period = 0;
- + deleteNobles();
- + setNewOlympiadEnd();
- + }
- + break;
- + default:
- + LOGGER.info("Olympiad: something went wrong loading period: " + _period);
- + return;
- + }
- - synchronized (this)
- - {
- - long milliToEnd;
- - if (_period == OlympiadState.COMPETITION)
- - milliToEnd = getMillisToOlympiadEnd();
- - else
- - milliToEnd = getMillisToValidationEnd();
- -
- - LOGGER.info("{} minutes until Olympiad period ends.", Math.round(milliToEnd / 60000));
- -
- - if (_period == OlympiadState.COMPETITION)
- - {
- - milliToEnd = getMillisToWeekChange();
- - LOGGER.info("Next weekly Olympiad change is in {} minutes.", Math.round(milliToEnd / 60000));
- - }
- - }
- + synchronized (this)
- + {
- + if (_period == 0)
- + LOGGER.info("Olympiad: Currently in Competition period.");
- + else
- + LOGGER.info("Olympiad: Currently in Validation period.");
- +
- + long milliToEnd;
- + if (_period == 0)
- + milliToEnd = getMillisToOlympiadEnd();
- + else
- + milliToEnd = getMillisToValidationEnd();
- +
- + double numSecs = milliToEnd / 1000 % 60;
- + double countDown = (milliToEnd / 1000 - numSecs) / 60;
- + final int numMins = (int) Math.floor(countDown % 60);
- + countDown = (countDown - numMins) / 60;
- + int numHours = (int) Math.floor(countDown % 24);
- + int numDays = (int) Math.floor((countDown - numHours) / 24);
- +
- + LOGGER.info("Olympiad System: " + numDays + " days, " + numHours + " hours and " + numMins + " mins. until period ends");
- +
- + if (_period == 0)
- + {
- + long milliToEnd2 = getMillisToWeekChange();
- +
- + double numSecs1 = milliToEnd2 / 1000 % 60;
- + double countDown1 = (milliToEnd2 / 1000 - numSecs1) / 60;
- + final int numMins1 = (int) Math.floor(countDown1 % 60);
- + countDown1 = (countDown - numMins1) / 60;
- + int numHours1 = (int) Math.floor(countDown1 % 24);
- + int numDays1 = (int) Math.floor((countDown1 - numHours1) / 24);
- +
- + LOGGER.info("Olympiad System: Next weekly change in " + numDays1 + " days, " + numHours1 + " hours and " + numMins1 + " mins.");
- + }
- + }
- + LOGGER.info("Olympiad: Loaded " + _nobles.size() + " nobles.");
- Index: no copy }
- - protected void init()
- - {
- - if (_period == OlympiadState.VALIDATION)
- - return;
- + protected void init()
- + {
- + if (_period == 1)
- + return;
- - saveNobleData();
- + saveNobleData();
- - _period = OlympiadState.VALIDATION;
- + _period = 1;
- - protected class ValidationEndTask implements Runnable
- - {
- - @Override
- - public void run()
- - {
- - _period = OlympiadState.COMPETITION;
- - _currentCycle++;
- -
- - deleteNobles();
- - setNewOlympiadEnd();
- - init();
- - }
- - }
- + protected class ValidationEndTask implements Runnable
- + {
- + @Override
- + public void run()
- + {
- + _period = 0;
- + _currentCycle++;
- +
- + deleteNobles();
- + setNewOlympiadEnd();
- + init();
- + }
- + }
- Calendar currentTime = Calendar.getInstance();
- - currentTime.add(Calendar.MONTH, 1);
- - currentTime.set(Calendar.DAY_OF_MONTH, 1);
- + currentTime.set(Calendar.DAY_OF_WEEK, 7);
- currentTime.set(Calendar.AM_PM, Calendar.AM);
- currentTime.set(Calendar.HOUR, 12);
- currentTime.set(Calendar.MINUTE, 0);
- - public boolean isOlympiadEnd()
- - {
- - return _period == OlympiadState.VALIDATION;
- - }
- + public boolean isOlympiadEnd()
- + {
- + return _period != 0;
- + }
- - protected synchronized void addWeeklyPoints()
- - {
- - if (_period == OlympiadState.VALIDATION)
- - return;
- + protected synchronized void addWeeklyPoints()
- + {
- + if (_period == 1)
- + return;
- - public void saveOlympiadStatus()
- - {
- - saveNobleData();
- -
- - try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- - PreparedStatement ps = con.prepareStatement(OLYMPIAD_SAVE_DATA))
- - {
- - ps.setInt(1, _currentCycle);
- - ps.setString(2, _period.toString());
- - ps.setLong(3, _olympiadEnd);
- - ps.setLong(4, _validationEnd);
- - ps.setLong(5, _nextWeeklyChange);
- - ps.setInt(6, _currentCycle);
- - ps.setString(7, _period.toString());
- - ps.setLong(8, _olympiadEnd);
- - ps.setLong(9, _validationEnd);
- - ps.setLong(10, _nextWeeklyChange);
- - ps.execute();
- - }
- - catch (Exception e)
- - {
- - LOGGER.error("Couldn't save Olympiad status.", e);
- - }
- - }
- + public void olympiadEnd(Player player)
- + {
- + long endtime;
- + if (_period == 0)
- + endtime = getMillisToOlympiadEnd();
- + else
- + endtime = getMillisToValidationEnd();
- +
- + double seconds = endtime / 1000 % 60;
- + double countdown = (endtime / 1000 - seconds) / 60;
- + int minutes = (int) Math.floor(countdown % 60);
- + countdown = (countdown - minutes) / 60;
- + int hours = (int) Math.floor(countdown % 24);
- + int days = (int) Math.floor((countdown - hours) / 24);
- +
- +
- + new CreatureSay(SayType.CRITICAL_ANNOUNCE, null, "Olympiad competitions: " + days + " days, " + hours + " hours and " + minutes + " mins until period ends.");
- + }
- + public void saveOlympiadStatus()
- + {
- + saveNobleData();
- +
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + final PreparedStatement statement = con.prepareStatement(OLYMPIAD_SAVE_DATA);
- +
- + statement.setInt(1, _currentCycle);
- + statement.setInt(2, _period);
- + statement.setLong(3, _olympiadEnd);
- + statement.setLong(4, _validationEnd);
- + statement.setLong(5, _nextWeeklyChange);
- + statement.setInt(6, _currentCycle);
- + statement.setInt(7, _period);
- + statement.setLong(8, _olympiadEnd);
- + statement.setLong(9, _validationEnd);
- + statement.setLong(10, _nextWeeklyChange);
- +
- + statement.execute();
- + statement.close();
- + }
- + catch (SQLException e)
- + {
- + _log.log(Level.SEVERE, "Olympiad: Failed to save olympiad data to database: ", e);
- + }
- + }
- public void saveOlympiadStatus()
- {
- saveNobleData();
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement(OLYMPIAD_SAVE_DATA))
- {
- - ps.setInt(1, _currentCycle);
- + ps.setInt(1, _currentCycle);
- - ps.setString(2, _period.toString());
- + ps.setInt(2, _period);
- - ps.setInt(6, _currentCycle);
- + ps.setInt(6, _currentCycle);
- - ps.setString(7, _period.toString());
- + ps.setInt(7, _period);
- - public int getNoblessePasses(Player player, boolean clear)
- - {
- - if (player == null || _period != OlympiadState.VALIDATION || _noblesRank.isEmpty())
- - return 0;
- + public int getNoblessePasses(Player player, boolean clear)
- + {
- + if (player == null || _period != 1 || _noblesRank.isEmpty())
- + return 0;
- Index: config/events.properties
- ===================================================================
- --- config/events.properties (revision 84)
- +++ config/events.properties (working copy)
- + # Announce olympiad period end
- + OlyEndAnnounce = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement