diff --git a/src/resources/common/BountyListItem.java b/src/resources/common/BountyListItem.java index bd10227f..f7662948 100644 --- a/src/resources/common/BountyListItem.java +++ b/src/resources/common/BountyListItem.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.common; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -28,8 +29,9 @@ import com.sleepycat.persist.model.Entity; import com.sleepycat.persist.model.PrimaryKey; @Entity(version=1) -public class BountyListItem { +public class BountyListItem implements Serializable { + private static final long serialVersionUID = 1L; @PrimaryKey private long objectId; private int creditReward; diff --git a/src/services/ConnectionService.java b/src/services/ConnectionService.java index f27e82a6..b5e5e1e7 100644 --- a/src/services/ConnectionService.java +++ b/src/services/ConnectionService.java @@ -270,7 +270,7 @@ public class ConnectionService implements INetworkDispatch { } }*/ - core.missionService.getBountyList().remove(core.getBountiesODB().get(object.getObjectId(), Long.class, BountyListItem.class)); + core.missionService.getBountyList().remove(core.getBountiesODB().get(object.getObjectId())); ghost.toggleFlag(PlayerFlags.LD); diff --git a/src/services/mission/MissionService.java b/src/services/mission/MissionService.java index ce658a23..d5f0e2bf 100644 --- a/src/services/mission/MissionService.java +++ b/src/services/mission/MissionService.java @@ -24,6 +24,8 @@ package services.mission; import java.io.File; import java.io.IOException; import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.Random; import java.util.Vector; @@ -59,6 +61,7 @@ import engine.clients.Client; import engine.resources.common.CRC; import engine.resources.common.NameGen; import engine.resources.container.Traverser; +import engine.resources.database.ODBCursor; import engine.resources.database.ObjectDatabase; import engine.resources.objects.SWGObject; import engine.resources.scene.Point3D; @@ -526,9 +529,7 @@ public class MissionService implements INetworkDispatch { if (placer != 0) bounty.getBountyPlacers().add(placer); - Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); - bountiesODB.put(bounty, Long.class, BountyListItem.class, txn); - txn.commitSync(); + bountiesODB.put(bounty.getObjectId(), bounty); bountyList.add(bounty); @@ -548,9 +549,7 @@ public class MissionService implements INetworkDispatch { if (placer != 0) bounty.getBountyPlacers().add(placer); - Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); - bountiesODB.put(bounty, Long.class, BountyListItem.class, txn); - txn.commitSync(); + bountiesODB.put(bounty.getObjectId(), bounty); //System.out.println("Added bounty of " + amountToAdd + " to " + bounty.getName()); return true; @@ -560,9 +559,9 @@ public class MissionService implements INetworkDispatch { Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); if (listRemove) - bountyList.remove(bountiesODB.get(bountyTarget.getObjectId(), Long.class, BountyListItem.class)); + bountyList.remove(bountiesODB.get(bountyTarget.getObjectId())); - bountiesODB.delete(bountyTarget.getObjectId(), Long.class, BountyListItem.class, txn); + bountiesODB.remove(bountyTarget.getObjectId()); txn.commitSync(); return true; } @@ -572,20 +571,17 @@ public class MissionService implements INetworkDispatch { } private void cleanupBounties() { - AtomicInteger bountyCount = new AtomicInteger(); - Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); - EntityCursor bountyCursor = bountiesODB.getEntityStore().getPrimaryIndex(Long.class, BountyListItem.class).entities(txn, null); - bountyCursor.forEach(bounty -> { + List bounties = new ArrayList(); + ODBCursor cursor = bountiesODB.getCursor(); + while(cursor.hasNext()) { + BountyListItem bounty = (BountyListItem) cursor.next(); if (!core.characterService.playerExists(bounty.getObjectId())) { - bountyCursor.delete(); - bountyCount.getAndIncrement(); + bounties.add(bounty); } - }); - bountyCursor.close(); - txn.commitSync(); - - if (bountyCount.get() != 0) - System.out.println("Removed " + bountyCount.get() + " bounties."); + } + bounties.stream().mapToLong(b -> b.getObjectId()).forEach(bountiesODB::remove); + if (bounties.size() != 0) + System.out.println("Removed " + bounties.size() + " bounties."); } @Override diff --git a/src/services/playercities/PlayerCityService.java b/src/services/playercities/PlayerCityService.java index 329ceede..c3ea7fc2 100644 --- a/src/services/playercities/PlayerCityService.java +++ b/src/services/playercities/PlayerCityService.java @@ -30,7 +30,6 @@ import java.util.concurrent.TimeUnit; import resources.objects.building.BuildingObject; import resources.objects.creature.CreatureObject; -import resources.objects.deed.Player_House_Deed; import resources.objects.tangible.TangibleObject; import services.sui.SUIWindow; import services.sui.SUIWindow.SUICallback;