Removed quest_global_data SQL table.

This commit is contained in:
MobiusDev
2017-08-15 16:26:18 +00:00
parent e8a760de9c
commit c06f5fb5db
77 changed files with 208 additions and 576 deletions

View File

@ -1655,97 +1655,6 @@ public class Quest extends AbstractScript implements IIdentifiable
}
}
/**
* Insert (or update) in the database variables that need to stay persistent for this quest after a reboot.<br>
* This function is for storage of values that do not related to a specific player but are global for all characters.<br>
* For example, if we need to disable a quest-gatekeeper until a certain time (as is done with some grand-boss gatekeepers), we can save that time in the DB.
* @param var the name of the variable to save
* @param value the value of the variable
*/
public final void saveGlobalQuestVar(String var, String value)
{
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("REPLACE INTO quest_global_data (quest_name,var,value) VALUES (?,?,?)"))
{
statement.setString(1, getName());
statement.setString(2, var);
statement.setString(3, value);
statement.executeUpdate();
}
catch (Exception e)
{
_log.log(Level.WARNING, "could not insert global quest variable:", e);
}
}
/**
* Read from the database a previously saved variable for this quest.<br>
* Due to performance considerations, this function should best be used only when the quest is first loaded.<br>
* Subclasses of this class can define structures into which these loaded values can be saved.<br>
* However, on-demand usage of this function throughout the script is not prohibited, only not recommended.<br>
* Values read from this function were entered by calls to "saveGlobalQuestVar".
* @param var the name of the variable to load
* @return the current value of the specified variable, or an empty string if the variable does not exist
*/
public final String loadGlobalQuestVar(String var)
{
String result = "";
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT value FROM quest_global_data WHERE quest_name = ? AND var = ?"))
{
statement.setString(1, getName());
statement.setString(2, var);
try (ResultSet rs = statement.executeQuery())
{
if (rs.first())
{
result = rs.getString(1);
}
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "could not load global quest variable:", e);
}
return result;
}
/**
* Permanently delete from the database a global quest variable that was previously saved for this quest.
* @param var the name of the variable to delete
*/
public final void deleteGlobalQuestVar(String var)
{
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("DELETE FROM quest_global_data WHERE quest_name = ? AND var = ?"))
{
statement.setString(1, getName());
statement.setString(2, var);
statement.executeUpdate();
}
catch (Exception e)
{
_log.log(Level.WARNING, "could not delete global quest variable:", e);
}
}
/**
* Permanently delete from the database all global quest variables that were previously saved for this quest.
*/
public final void deleteAllGlobalQuestVars()
{
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("DELETE FROM quest_global_data WHERE quest_name = ?"))
{
statement.setString(1, getName());
statement.executeUpdate();
}
catch (Exception e)
{
_log.log(Level.WARNING, "could not delete global quest variables:", e);
}
}
/**
* Insert in the database the quest for the player.
* @param qs the {@link QuestState} object whose variable to insert