Fix memory leaking in ShopLoader

This commit is contained in:
Ghost_chu committed 2021-06-05 17:14:10 +08:00
1 parent 7a0cc3c0a5
commit bf92e5c441
3 files changed
+19

No files matched your search

@@ -198,6 +198,7 @@ public class DatabaseHelper {
}
public void removeShop(Shop shop) {
plugin.getShopLoader().removeShopFromShopLoader(shop);
plugin.log("[DATABASE HELPER] Removing shop in the database: " + shop.toString());
if (plugin.getConfig().getBoolean("debug.shop-deletion")) {
for (StackTraceElement stackTraceElement : new Exception().getStackTrace()) {
@@ -426,6 +426,7 @@ public class ContainerShop implements Shop {
}
plugin.getShopManager().removeShop(this);
plugin.getDatabaseHelper().removeShop(this);
plugin.getShopLoader().removeShopFromShopLoader(this);
}
// Use that copy we saved earlier (which is now deleted) to refresh it's now alone neighbor
if (neighbor != null) {
@@ -330,6 +330,23 @@ public class ShopLoader {
return new ArrayList<>(shopsInDatabase);
}
public void removeShopFromShopLoader(Shop shop) {
if (this.shopsInDatabase.remove(shop)) {
for (ShopDatabaseInfoOrigin origin : this.originShopsInDatabase) {
if (Objects.equals(shop.getLocation().getWorld().getName(), origin.getWorld())) {
if (shop.getLocation().getBlockX() == origin.getX()) {
if (shop.getLocation().getBlockY() == origin.getY()) {
if (shop.getLocation().getBlockZ() == origin.getZ()) {
this.originShopsInDatabase.remove(origin);
break;
}
}
}
}
}
}
}
@NotNull
public List<ShopDatabaseInfoOrigin> getOriginShopsInDatabase() {
return new ArrayList<>(originShopsInDatabase);