Added cleanup method for creature ODB.

This commit is contained in:
Light2
2014-03-30 22:04:20 +02:00
parent 6c1df547b4
commit 814f800dbf
2 changed files with 46 additions and 0 deletions
+23
View File
@@ -420,10 +420,33 @@ public class NGECore {
didServerCrash = false;
System.out.println("Started Server.");
cleanupCreatureODB();
setGalaxyStatus(2);
}
private void cleanupCreatureODB() {
EntityCursor<CreatureObject> cursor = creatureODB.getCursor(Long.class, CreatureObject.class);
Iterator<CreatureObject> it = cursor.iterator();
List<CreatureObject> deletedObjects = new ArrayList<CreatureObject>();
while(it.hasNext()) {
CreatureObject creature = it.next();
if(!characterService.playerExists(creature.getObjectID()))
deletedObjects.add(creature);
}
cursor.close();
Transaction txn = creatureODB.getEnvironment().beginTransaction(null, null);
for(CreatureObject creature : deletedObjects) {
creatureODB.delete(creature.getObjectID(), Long.class, CreatureObject.class, txn);
}
txn.commitSync();
System.out.println("Deleted " + deletedObjects.size() + " creatures.");
}
public void stop() {
System.out.println("Stopping Servers and Connections.");
databaseConnection.close();