Olympiad database load adjustments.

This commit is contained in:
MobiusDevelopment
2020-06-11 22:40:47 +00:00
parent 4d8463a6e6
commit cb45d546cb
21 changed files with 141 additions and 123 deletions

View File

@@ -146,6 +146,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -168,7 +169,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -146,6 +146,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -168,7 +169,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -146,6 +146,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -168,7 +169,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -143,6 +143,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -165,7 +166,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -143,6 +143,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -165,7 +166,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -143,6 +143,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -165,7 +166,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -143,6 +143,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -165,7 +166,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -144,6 +144,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -166,7 +167,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `olympiad_data` (
`id` TINYINT UNSIGNED NOT NULL DEFAULT 0,
`current_cycle` MEDIUMINT UNSIGNED NOT NULL DEFAULT 1,
`period` MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
`olympiad_end` bigint(13) unsigned NOT NULL DEFAULT '0',
`validation_end` bigint(13) unsigned NOT NULL DEFAULT '0',
`next_weekly_change` bigint(13) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

View File

@@ -138,7 +138,7 @@ public class SpawnTable
} }
if (spawnDat.getTemplate().getNpcId() == Olympiad.OLY_MANAGER) if (spawnDat.getTemplate().getNpcId() == Olympiad.OLY_MANAGER)
{ {
Olympiad.olymanagers.add(spawnDat); Olympiad.OLY_MANAGERS.add(spawnDat);
} }
} }
} }

View File

@@ -18,7 +18,6 @@ package org.l2jmobius.gameserver.model.entity.olympiad;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -26,12 +25,10 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -39,6 +36,7 @@ import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
@@ -59,16 +57,17 @@ public class Olympiad
{ {
protected static final Logger LOGGER = Logger.getLogger(Olympiad.class.getName()); protected static final Logger LOGGER = Logger.getLogger(Olympiad.class.getName());
private static Map<Integer, StatSet> _nobles; private static Map<Integer, StatSet> NOBLES;
private static Map<Integer, StatSet> _oldnobles; private static Map<Integer, StatSet> NOBLES_RANK;
protected static List<StatSet> _heroesToBe; private static List<StatSet> HEROS_TO_BE;
private static List<PlayerInstance> _nonClassBasedRegisters; private static List<PlayerInstance> _nonClassBasedRegisters;
private static Map<Integer, List<PlayerInstance>> _classBasedRegisters; private static Map<Integer, List<PlayerInstance>> _classBasedRegisters;
public static List<Spawn> OLY_MANAGERS = new ArrayList<>();
public static final int OLY_MANAGER = 31688; public static final int OLY_MANAGER = 31688;
public static List<Spawn> olymanagers = new ArrayList<>(); private static final String OLYMPIAD_DATA_FILE = "./config/olympiad.cfg";
private static final String OLYMPIAD_DATA_FILE = "config/olympiad.cfg";
public static final String OLYMPIAD_HTML_PATH = "data/html/olympiad/"; public static final String OLYMPIAD_HTML_PATH = "data/html/olympiad/";
private static final String OLYMPIAD_LOAD_DATA = "SELECT current_cycle, period, olympiad_end, validation_end, next_weekly_change FROM olympiad_data WHERE id = 0";
private static final String OLYMPIAD_SAVE_DATA = "INSERT INTO olympiad_data (id, current_cycle, period, olympiad_end, validation_end, next_weekly_change) VALUES (0,?,?,?,?,?) ON DUPLICATE KEY UPDATE current_cycle=?, period=?, olympiad_end=?, validation_end=?, next_weekly_change=?";
private static final String OLYMPIAD_LOAD_NOBLES = "SELECT olympiad_nobles.charId, olympiad_nobles.class_id, characters.char_name, olympiad_nobles.olympiad_points, olympiad_nobles.competitions_done, olympiad_nobles.competitions_won, olympiad_nobles.competitions_lost, olympiad_nobles.competitions_drawn FROM olympiad_nobles, characters WHERE characters.obj_Id = olympiad_nobles.charId"; private static final String OLYMPIAD_LOAD_NOBLES = "SELECT olympiad_nobles.charId, olympiad_nobles.class_id, characters.char_name, olympiad_nobles.olympiad_points, olympiad_nobles.competitions_done, olympiad_nobles.competitions_won, olympiad_nobles.competitions_lost, olympiad_nobles.competitions_drawn FROM olympiad_nobles, characters WHERE characters.obj_Id = olympiad_nobles.charId";
private static final String OLYMPIAD_SAVE_NOBLES = "INSERT INTO olympiad_nobles (`charId`,`class_id`,`char_name`,`olympiad_points`,`competitions_done`,`competitions_won`,`competitions_lost`,`competitions_drawn`) VALUES (?,?,?,?,?,?,?,?)"; private static final String OLYMPIAD_SAVE_NOBLES = "INSERT INTO olympiad_nobles (`charId`,`class_id`,`char_name`,`olympiad_points`,`competitions_done`,`competitions_won`,`competitions_lost`,`competitions_drawn`) VALUES (?,?,?,?,?,?,?,?)";
private static final String OLYMPIAD_UPDATE_NOBLES = "UPDATE olympiad_nobles SET olympiad_points = ?, competitions_done = ?, competitions_won = ?, competitions_lost = ?, competitions_drawn = ? WHERE charId = ?"; private static final String OLYMPIAD_UPDATE_NOBLES = "UPDATE olympiad_nobles SET olympiad_points = ?, competitions_done = ?, competitions_won = ?, competitions_lost = ?, competitions_drawn = ? WHERE charId = ?";
@@ -178,39 +177,56 @@ public class Olympiad
private void load() private void load()
{ {
_nobles = new ConcurrentHashMap<>(); NOBLES = new ConcurrentHashMap<>();
_oldnobles = new HashMap<>(); NOBLES_RANK = new HashMap<>();
final Properties olympiadProperties = new Properties(); boolean loaded = false;
InputStream is = null; try (Connection con = DatabaseFactory.getConnection();
try PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
ResultSet rset = statement.executeQuery())
{ {
is = new FileInputStream(new File("./" + OLYMPIAD_DATA_FILE)); while (rset.next())
olympiadProperties.load(is); {
_currentCycle = rset.getInt("current_cycle");
_period = rset.getInt("period");
_olympiadEnd = rset.getLong("olympiad_end");
_validationEnd = rset.getLong("validation_end");
_nextWeeklyChange = rset.getLong("next_weekly_change");
loaded = true;
}
} }
catch (Exception e) catch (Exception e)
{ {
LOGGER.warning(OLYMPIAD_DATA_FILE + " cannot be loaded... It will be created on next save or server shutdown.."); LOGGER.log(Level.WARNING, "Olympiad System: Error loading olympiad data from database: ", e);
} }
finally
if (!loaded)
{ {
// LOGGER.log(Level.INFO, "Olympiad System: failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties();
InputStream is = null;
try try
{ {
if (is != null) final File file = new File(OLYMPIAD_DATA_FILE);
if (file.exists())
{ {
is.close(); is = new FileInputStream(file);
olympiadProperties.load(is);
} }
} }
catch (Exception e) catch (Exception e)
{ {
LOGGER.log(Level.SEVERE, "Olympiad System: Error loading olympiad properties: ", e);
return;
} }
}
_currentCycle = Integer.parseInt(olympiadProperties.getProperty("CurrentCycle", "1")); _currentCycle = Integer.parseInt(olympiadProperties.getProperty("CurrentCycle", "1"));
_period = Integer.parseInt(olympiadProperties.getProperty("Period", "0")); _period = Integer.parseInt(olympiadProperties.getProperty("Period", "0"));
_olympiadEnd = Long.parseLong(olympiadProperties.getProperty("OlympiadEnd", "0")); _olympiadEnd = Long.parseLong(olympiadProperties.getProperty("OlympiadEnd", "0"));
_validationEnd = Long.parseLong(olympiadProperties.getProperty("ValdationEnd", "0")); _validationEnd = Long.parseLong(olympiadProperties.getProperty("ValidationEnd", "0"));
_nextWeeklyChange = Long.parseLong(olympiadProperties.getProperty("NextWeeklyChange", "0")); _nextWeeklyChange = Long.parseLong(olympiadProperties.getProperty("NextWeeklyChange", "0"));
}
switch (_period) switch (_period)
{ {
@@ -265,7 +281,7 @@ public class Olympiad
statData.set(COMP_LOST, rset.getInt(COMP_LOST)); statData.set(COMP_LOST, rset.getInt(COMP_LOST));
statData.set(COMP_DRAWN, rset.getInt(COMP_DRAWN)); statData.set(COMP_DRAWN, rset.getInt(COMP_DRAWN));
statData.set("to_save", false); statData.set("to_save", false);
_nobles.put(charId, statData); NOBLES.put(charId, statData);
} }
rset.close(); rset.close();
@@ -293,7 +309,7 @@ public class Olympiad
statData.set(COMP_LOST, rset.getInt(COMP_LOST)); statData.set(COMP_LOST, rset.getInt(COMP_LOST));
statData.set(COMP_DRAWN, rset.getInt(COMP_DRAWN)); statData.set(COMP_DRAWN, rset.getInt(COMP_DRAWN));
statData.set("to_save", false); statData.set("to_save", false);
_oldnobles.put(charId, statData); NOBLES_RANK.put(charId, statData);
} }
rset.close(); rset.close();
@@ -335,7 +351,7 @@ public class Olympiad
} }
} }
LOGGER.info("Olympiad System: Loaded " + _nobles.size() + " Nobles"); LOGGER.info("Olympiad System: Loaded " + NOBLES.size() + " Nobles");
} }
protected final void init() protected final void init()
@@ -410,7 +426,7 @@ public class Olympiad
_period = 1; _period = 1;
sortHerosToBe(); sortHerosToBe();
giveHeroBonus(); giveHeroBonus();
Hero.getInstance().computeNewHeroes(_heroesToBe); Hero.getInstance().computeNewHeroes(HEROS_TO_BE);
saveOlympiadStatus(); saveOlympiadStatus();
updateMonthlyData(); updateMonthlyData();
@@ -529,7 +545,7 @@ public class Olympiad
return false; return false;
} }
if (!_nobles.containsKey(noble.getObjectId())) if (!NOBLES.containsKey(noble.getObjectId()))
{ {
final StatSet statDat = new StatSet(); final StatSet statDat = new StatSet();
statDat.set(CLASS_ID, noble.getClassId().getId()); statDat.set(CLASS_ID, noble.getClassId().getId());
@@ -540,7 +556,7 @@ public class Olympiad
statDat.set(COMP_LOST, 0); statDat.set(COMP_LOST, 0);
statDat.set(COMP_DRAWN, 0); statDat.set(COMP_DRAWN, 0);
statDat.set("to_save", true); statDat.set("to_save", true);
_nobles.put(noble.getObjectId(), statDat); NOBLES.put(noble.getObjectId(), statDat);
} }
if (classBased && (getNoblePoints(noble.getObjectId()) < 3)) if (classBased && (getNoblePoints(noble.getObjectId()) < 3))
@@ -586,24 +602,24 @@ public class Olympiad
protected static int getNobleCount() protected static int getNobleCount()
{ {
return _nobles.size(); return NOBLES.size();
} }
protected static StatSet getNobleStats(int playerId) protected static StatSet getNobleStats(int playerId)
{ {
return _nobles.get(playerId); return NOBLES.get(playerId);
} }
protected static synchronized void updateNobleStats(int playerId, StatSet stats) protected static synchronized void updateNobleStats(int playerId, StatSet stats)
{ {
_nobles.remove(playerId); NOBLES.remove(playerId);
_nobles.put(playerId, stats); NOBLES.put(playerId, stats);
} }
protected static synchronized void updateOldNobleStats(int playerId, StatSet stats) protected static synchronized void updateOldNobleStats(int playerId, StatSet stats)
{ {
_oldnobles.remove(playerId); NOBLES_RANK.remove(playerId);
_oldnobles.put(playerId, stats); NOBLES_RANK.put(playerId, stats);
getInstance().saveOldNobleData(playerId); getInstance().saveOldNobleData(playerId);
} }
@@ -987,7 +1003,7 @@ public class Olympiad
return; return;
} }
for (Entry<Integer, StatSet> entry : _nobles.entrySet()) for (Entry<Integer, StatSet> entry : NOBLES.entrySet())
{ {
final Integer nobleId = entry.getKey(); final Integer nobleId = entry.getKey();
final StatSet nobleInfo = entry.getValue(); final StatSet nobleInfo = entry.getValue();
@@ -1102,7 +1118,7 @@ public class Olympiad
protected synchronized void saveNobleData() protected synchronized void saveNobleData()
{ {
Connection con = null; Connection con = null;
if ((_nobles == null) || _nobles.isEmpty()) if ((NOBLES == null) || NOBLES.isEmpty())
{ {
return; return;
} }
@@ -1111,7 +1127,7 @@ public class Olympiad
{ {
con = DatabaseFactory.getConnection(); con = DatabaseFactory.getConnection();
PreparedStatement statement; PreparedStatement statement;
for (Entry<Integer, StatSet> entry : _nobles.entrySet()) for (Entry<Integer, StatSet> entry : NOBLES.entrySet())
{ {
final Integer nobleId = entry.getKey(); final Integer nobleId = entry.getKey();
final StatSet nobleInfo = entry.getValue(); final StatSet nobleInfo = entry.getValue();
@@ -1175,7 +1191,7 @@ public class Olympiad
PreparedStatement statement = null; PreparedStatement statement = null;
try (Connection con = DatabaseFactory.getConnection()) try (Connection con = DatabaseFactory.getConnection())
{ {
final StatSet nobleInfo = _oldnobles.get(nobleId); final StatSet nobleInfo = NOBLES_RANK.get(nobleId);
if (nobleInfo == null) if (nobleInfo == null)
{ {
return; return;
@@ -1203,51 +1219,28 @@ public class Olympiad
} }
} }
/**
* Save olympiad.cfg file with current olympiad status and update noblesse table in database
*/
public void saveOlympiadStatus() public void saveOlympiadStatus()
{ {
saveNobleData(); saveNobleData();
final Properties olympiadProperties = new Properties(); try (Connection con = DatabaseFactory.getConnection();
FileOutputStream fos = null; PreparedStatement statement = con.prepareStatement(OLYMPIAD_SAVE_DATA))
try
{ {
fos = new FileOutputStream(new File("./" + OLYMPIAD_DATA_FILE)); statement.setInt(1, _currentCycle);
olympiadProperties.setProperty("CurrentCycle", String.valueOf(_currentCycle)); statement.setInt(2, _period);
olympiadProperties.setProperty("Period", String.valueOf(_period)); statement.setLong(3, _olympiadEnd);
olympiadProperties.setProperty("OlympiadEnd", String.valueOf(_olympiadEnd)); statement.setLong(4, _validationEnd);
olympiadProperties.setProperty("ValdationEnd", String.valueOf(_validationEnd)); statement.setLong(5, _nextWeeklyChange);
olympiadProperties.setProperty("NextWeeklyChange", String.valueOf(_nextWeeklyChange)); statement.setInt(6, _currentCycle);
statement.setInt(7, _period);
final GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance(); statement.setLong(8, _olympiadEnd);
gc.clear(); statement.setLong(9, _validationEnd);
gc.setTimeInMillis(_nextWeeklyChange); statement.setLong(10, _nextWeeklyChange);
statement.execute();
olympiadProperties.setProperty("NextWeeklyChange_DateFormat", DateFormat.getDateTimeInstance().format(gc.getTime()));
gc.clear();
gc.setTimeInMillis(_olympiadEnd);
olympiadProperties.setProperty("OlympiadEnd_DateFormat", DateFormat.getDateTimeInstance().format(gc.getTime()));
olympiadProperties.store(fos, "Olympiad Properties");
} }
catch (Exception e) catch (SQLException e)
{ {
LOGGER.warning("Olympiad System: Unable to save olympiad properties to file: " + e); LOGGER.log(Level.SEVERE, "Olympiad System: Failed to save olympiad data to database: ", e);
}
finally
{
try
{
if (fos != null)
{
fos.close();
}
}
catch (Exception e)
{
}
} }
} }
@@ -1276,9 +1269,9 @@ public class Olympiad
return; return;
} }
if (_nobles != null) if (NOBLES != null)
{ {
for (Entry<Integer, StatSet> entry : _nobles.entrySet()) for (Entry<Integer, StatSet> entry : NOBLES.entrySet())
{ {
final Integer nobleId = entry.getKey(); final Integer nobleId = entry.getKey();
final StatSet nobleInfo = entry.getValue(); final StatSet nobleInfo = entry.getValue();
@@ -1296,7 +1289,7 @@ public class Olympiad
} }
} }
_heroesToBe = new ArrayList<>(); HEROS_TO_BE = new ArrayList<>();
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rset = null; ResultSet rset = null;
try (Connection con = DatabaseFactory.getConnection()) try (Connection con = DatabaseFactory.getConnection())
@@ -1315,7 +1308,7 @@ public class Olympiad
hero.set(CHAR_ID, rset.getInt(CHAR_ID)); hero.set(CHAR_ID, rset.getInt(CHAR_ID));
hero.set(CHAR_NAME, rset.getString(CHAR_NAME)); hero.set(CHAR_NAME, rset.getString(CHAR_NAME));
logResult(hero.getString(CHAR_NAME), "", hero.getDouble(CHAR_ID), hero.getDouble(CLASS_ID), 0, 0, "awarded hero", 0, ""); logResult(hero.getString(CHAR_NAME), "", hero.getDouble(CHAR_ID), hero.getDouble(CLASS_ID), 0, 0, "awarded hero", 0, "");
_heroesToBe.add(hero); HEROS_TO_BE.add(hero);
} }
statement.close(); statement.close();
} }
@@ -1362,15 +1355,15 @@ public class Olympiad
protected void giveHeroBonus() protected void giveHeroBonus()
{ {
if (_heroesToBe.isEmpty()) if (HEROS_TO_BE.isEmpty())
{ {
return; return;
} }
for (StatSet hero : _heroesToBe) for (StatSet hero : HEROS_TO_BE)
{ {
final int charId = hero.getInt(CHAR_ID); final int charId = hero.getInt(CHAR_ID);
final StatSet noble = _nobles.get(charId); final StatSet noble = NOBLES.get(charId);
int currentPoints = noble.getInt(POINTS); int currentPoints = noble.getInt(POINTS);
currentPoints += Config.ALT_OLY_HERO_POINTS; currentPoints += Config.ALT_OLY_HERO_POINTS;
noble.set(POINTS, currentPoints); noble.set(POINTS, currentPoints);
@@ -1382,12 +1375,12 @@ public class Olympiad
{ {
if (_period == 1) if (_period == 1)
{ {
if (_nobles.isEmpty()) if (NOBLES.isEmpty())
{ {
return 0; return 0;
} }
final StatSet noble = _nobles.get(objId); final StatSet noble = NOBLES.get(objId);
if (noble == null) if (noble == null)
{ {
return 0; return 0;
@@ -1404,12 +1397,12 @@ public class Olympiad
return points; return points;
} }
if (_oldnobles.isEmpty()) if (NOBLES_RANK.isEmpty())
{ {
return 0; return 0;
} }
final StatSet noble = _oldnobles.get(objId); final StatSet noble = NOBLES_RANK.get(objId);
if (noble == null) if (noble == null)
{ {
return 0; return 0;
@@ -1445,12 +1438,12 @@ public class Olympiad
public int getNoblePoints(int objId) public int getNoblePoints(int objId)
{ {
if (_nobles.isEmpty()) if (NOBLES.isEmpty())
{ {
return 0; return 0;
} }
final StatSet noble = _nobles.get(objId); final StatSet noble = NOBLES.get(objId);
if (noble == null) if (noble == null)
{ {
return 0; return 0;
@@ -1461,12 +1454,12 @@ public class Olympiad
public int getCompetitionDone(int objId) public int getCompetitionDone(int objId)
{ {
if (_nobles.isEmpty()) if (NOBLES.isEmpty())
{ {
return 0; return 0;
} }
final StatSet noble = _nobles.get(objId); final StatSet noble = NOBLES.get(objId);
if (noble == null) if (noble == null)
{ {
return 0; return 0;
@@ -1477,12 +1470,12 @@ public class Olympiad
public int getCompetitionWon(int objId) public int getCompetitionWon(int objId)
{ {
if (_nobles.isEmpty()) if (NOBLES.isEmpty())
{ {
return 0; return 0;
} }
final StatSet noble = _nobles.get(objId); final StatSet noble = NOBLES.get(objId);
if (noble == null) if (noble == null)
{ {
return 0; return 0;
@@ -1493,12 +1486,12 @@ public class Olympiad
public int getCompetitionLost(int objId) public int getCompetitionLost(int objId)
{ {
if (_nobles.isEmpty()) if (NOBLES.isEmpty())
{ {
return 0; return 0;
} }
final StatSet noble = _nobles.get(objId); final StatSet noble = NOBLES.get(objId);
if (noble == null) if (noble == null)
{ {
return 0; return 0;
@@ -1521,9 +1514,9 @@ public class Olympiad
LOGGER.warning("Olympiad System: Couldnt delete nobles from DB"); LOGGER.warning("Olympiad System: Couldnt delete nobles from DB");
} }
_oldnobles.clear(); NOBLES_RANK.clear();
_oldnobles = _nobles; NOBLES_RANK = NOBLES;
_nobles = new ConcurrentHashMap<>(); NOBLES = new ConcurrentHashMap<>();
} }
/** /**

View File

@@ -981,7 +981,7 @@ class OlympiadGame
protected void announceGame() protected void announceGame()
{ {
for (Spawn manager : Olympiad.olymanagers) for (Spawn manager : Olympiad.OLY_MANAGERS)
{ {
if ((manager != null) && (manager.getLastSpawn() != null)) if ((manager != null) && (manager.getLastSpawn() != null))
{ {

View File

@@ -62,7 +62,7 @@ public class Olympiad extends ListenersContainer
protected static final Logger LOGGER_OLYMPIAD = Logger.getLogger("olympiad"); protected static final Logger LOGGER_OLYMPIAD = Logger.getLogger("olympiad");
private static final Map<Integer, StatSet> NOBLES = new ConcurrentHashMap<>(); private static final Map<Integer, StatSet> NOBLES = new ConcurrentHashMap<>();
protected static List<StatSet> HEROS_TO_BE; private static List<StatSet> HEROS_TO_BE;
private static Map<Integer, Integer> NOBLES_RANK = new HashMap<>(); private static Map<Integer, Integer> NOBLES_RANK = new HashMap<>();
private static List<PlayerInstance> _nonClassBasedRegisters; private static List<PlayerInstance> _nonClassBasedRegisters;
private static Map<Integer, List<PlayerInstance>> _classBasedRegisters; private static Map<Integer, List<PlayerInstance>> _classBasedRegisters;
@@ -184,6 +184,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -206,13 +207,13 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.log(Level.INFO, "Olympiad System: failed to load data from database, trying to load from file."); // LOGGER.log(Level.INFO, "Olympiad System: failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
InputStream is = null; InputStream is = null;
try try
{ {
is = new FileInputStream(new File("./" + Config.OLYMPIAD_CONFIG_FILE)); is = new FileInputStream(new File(Config.OLYMPIAD_CONFIG_FILE));
olympiadProperties.load(is); olympiadProperties.load(is);
} }
catch (Exception e) catch (Exception e)

View File

@@ -201,7 +201,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -145,6 +145,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -167,7 +168,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -145,6 +145,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -167,7 +168,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -145,6 +145,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -167,7 +168,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -145,6 +145,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -167,7 +168,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -145,6 +145,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -167,7 +168,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -146,6 +146,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -168,7 +169,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))

View File

@@ -145,6 +145,7 @@ public class Olympiad extends ListenersContainer
private void load() private void load()
{ {
NOBLES.clear(); NOBLES.clear();
boolean loaded = false; boolean loaded = false;
try (Connection con = DatabaseFactory.getConnection(); try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA); PreparedStatement statement = con.prepareStatement(OLYMPIAD_LOAD_DATA);
@@ -167,7 +168,7 @@ public class Olympiad extends ListenersContainer
if (!loaded) if (!loaded)
{ {
LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file."); // LOGGER.info("Olympiad System: Failed to load data from database, trying to load from file.");
final Properties olympiadProperties = new Properties(); final Properties olympiadProperties = new Properties();
try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE)) try (InputStream is = new FileInputStream(Config.OLYMPIAD_CONFIG_FILE))