Remove non existent respawns from database.

This commit is contained in:
MobiusDevelopment
2021-04-25 23:13:08 +00:00
parent a2f02ea969
commit 42af50a931
19 changed files with 266 additions and 19 deletions

View File

@ -87,7 +87,8 @@ public class DBSpawnManager
{
while (rset.next())
{
final NpcTemplate template = getValidTemplate(rset.getInt("id"));
final int id = rset.getInt("id");
final NpcTemplate template = getValidTemplate(id);
if (template != null)
{
final Spawn spawn = new Spawn(template);
@ -139,6 +140,18 @@ public class DBSpawnManager
else
{
LOGGER.warning(getClass().getSimpleName() + ": Could not load npc #" + rset.getInt("id") + " from DB");
// Remove non existent NPC respawn.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement statement2 = con2.prepareStatement("DELETE FROM npc_respawns WHERE id=?"))
{
statement2.setInt(1, id);
statement2.execute();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Could not remove npc #" + id + " from DB: ", e);
}
}
}