L2JMobius

C6 //delete command does not save to database

G-hamsteR · 4 · 5172

Online G-hamsteR

  • Viscount
  • *****
    • Posts: 335
Using the //delete command for normal spawnlist and normal npc, doesn't delete them from spawnlist. They are only deleted from the game until the next restart.

If it's used on custom npcs with custom_spawnlist, they are deleted.


Online G-hamsteR

  • Viscount
  • *****
    • Posts: 335
The problem is at SpawnTable.java

Line 320:
Code: [Select]
final PreparedStatement statement = con.prepareStatement("DELETE FROM " + (Config.SAVE_GMSPAWN_ON_CUSTOM ? "custom_spawnlist" : "spawnlist") + " WHERE id=?");
I have SAVE_GMSPAWN_ON_CUSTOM = True in my configs because I want new spawns to be inserted into the custom_spawnlist table. However, I still want to be able to delete all NPC, custom or not.

Maybe this fixes the problem:
Changing this:
Code: [Select]
try (Connection con = DatabaseFactory.getConnection())
{
final PreparedStatement statement = con.prepareStatement("DELETE FROM " + (Config.SAVE_GMSPAWN_ON_CUSTOM ? "custom_spawnlist" : "spawnlist") + " WHERE id=?");
statement.setInt(1, spawn.getId());
statement.execute();
statement.close();
}

To this:
Code: [Select]
try (Connection con = DatabaseFactory.getConnection())
{
PreparedStatement statement;
statement = con.prepareStatement("DELETE FROM custom_spawnlist WHERE id=?");
statement.setInt(1, spawn.getId());
statement.execute();
statement.close();

statement = con.prepareStatement("DELETE FROM spawnlist WHERE id=?");
statement.setInt(1, spawn.getId());
statement.execute();
statement.close();
}


Online Mobius

  • Distinguished King
  • *****
    • Posts: 16152