Skip to content

Commit a83f0f0

Browse files
Fix export command just export the shop before loading issue
1 parent 321cb15 commit a83f0f0

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

src/main/java/org/maxgamer/quickshop/database/DatabaseHelper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ public void onFailed(SQLException e) {
211211
}
212212

213213
public void removeShop(Shop shop) {
214-
plugin.getShopLoader().removeShopFromShopLoader(shop);
215214
plugin.log("[DATABASE HELPER] Removing shop in the database: " + shop.toString());
216215
bakeTraceIfNeeded();
217216
String sqlString = "DELETE FROM "

src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ public void delete(boolean memoryOnly) {
411411
}
412412
plugin.getShopManager().removeShop(this);
413413
plugin.getDatabaseHelper().removeShop(this);
414-
plugin.getShopLoader().removeShopFromShopLoader(this);
415414
}
416415
// Use that copy we saved earlier (which is now deleted) to refresh it's now alone neighbor
417416
if (neighbor != null) {

src/main/java/org/maxgamer/quickshop/shop/ShopLoader.java

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.sql.ResultSet;
4444
import java.sql.SQLException;
4545
import java.util.*;
46-
import java.util.concurrent.CopyOnWriteArrayList;
4746
import java.util.concurrent.atomic.AtomicBoolean;
4847
import java.util.logging.Level;
4948
import java.util.logging.Logger;
@@ -58,8 +57,6 @@ public class ShopLoader {
5857

5958
private final QuickShop plugin;
6059
/* This may contains broken shop, must use null check before load it. */
61-
private final List<Shop> shopsInDatabase = new CopyOnWriteArrayList<>();
62-
private final List<ShopRawDatabaseInfo> shopRawDatabaseInfoList = new CopyOnWriteArrayList<>();
6360
private int errors;
6461
//private final WarningSender warningSender;
6562

@@ -92,11 +89,16 @@ public void loadShops(@Nullable String worldName) {
9289
this.plugin.getLogger().info("Loading shops from the database...");
9390
while (rs.next()) {
9491
ShopRawDatabaseInfo origin = new ShopRawDatabaseInfo(rs);
95-
shopRawDatabaseInfoList.add(origin);
9692
if (worldName != null && !origin.getWorld().equals(worldName)) {
9793
continue;
9894
}
99-
ShopDatabaseInfo data = new ShopDatabaseInfo(origin);
95+
ShopDatabaseInfo data;
96+
try {
97+
data = new ShopDatabaseInfo(origin);
98+
} catch (Exception e) {
99+
exceptionHandler(e, null);
100+
continue;
101+
}
100102
//World unloaded and not found
101103
if (data.getWorld() == null) {
102104
++loadAfterWorldLoaded;
@@ -114,7 +116,6 @@ public void loadShops(@Nullable String worldName) {
114116
if (data.needUpdate.get()) {
115117
shop.setDirty();
116118
}
117-
shopsInDatabase.add(shop);
118119
if (shopNullCheck(shop)) {
119120
if (plugin.getConfig().getBoolean("debug.delete-corrupt-shops", false)) {
120121
plugin.getLogger().warning("Deleting shop " + shop + " caused by corrupted.");
@@ -292,7 +293,6 @@ public synchronized void recoverFromFile(@NotNull String fileContent) {
292293
boolean success = false;
293294
try {
294295
ShopRawDatabaseInfo shopDatabaseInfoOrigin = gson.fromJson(shopStr, ShopRawDatabaseInfo.class);
295-
shopRawDatabaseInfoList.add(shopDatabaseInfoOrigin);
296296
ShopDatabaseInfo data = new ShopDatabaseInfo(shopDatabaseInfoOrigin);
297297
Shop shop =
298298
new ContainerShop(plugin,
@@ -303,7 +303,6 @@ public synchronized void recoverFromFile(@NotNull String fileContent) {
303303
data.isUnlimited(),
304304
data.getType(),
305305
data.getExtra());
306-
shopsInDatabase.add(shop);
307306
if (shopNullCheck(shop)) {
308307
continue;
309308
}
@@ -323,29 +322,43 @@ public synchronized void recoverFromFile(@NotNull String fileContent) {
323322

324323
@NotNull
325324
public List<Shop> getShopsInDatabase() {
326-
return new ArrayList<>(shopsInDatabase);
327-
}
328-
329-
public void removeShopFromShopLoader(Shop shop) {
330-
if (this.shopsInDatabase.remove(shop)) {
331-
for (ShopRawDatabaseInfo rawDatabaseInfo : this.shopRawDatabaseInfoList) {
332-
if (Objects.equals(shop.getLocation().getWorld().getName(), rawDatabaseInfo.getWorld())) {
333-
if (shop.getLocation().getBlockX() == rawDatabaseInfo.getX()) {
334-
if (shop.getLocation().getBlockY() == rawDatabaseInfo.getY()) {
335-
if (shop.getLocation().getBlockZ() == rawDatabaseInfo.getZ()) {
336-
this.shopRawDatabaseInfoList.remove(rawDatabaseInfo);
337-
break;
338-
}
339-
}
340-
}
341-
}
325+
errors = 0;
326+
List<Shop> shopsInDatabaseList = new ArrayList<>();
327+
this.plugin.getLogger().info("Loading shops from the database...");
328+
for (ShopRawDatabaseInfo shopRawDatabaseInfo : getOriginShopsInDatabase()) {
329+
try {
330+
ShopDatabaseInfo databaseInfo = new ShopDatabaseInfo(shopRawDatabaseInfo);
331+
Shop shop = new ContainerShop(plugin,
332+
databaseInfo.getLocation(),
333+
databaseInfo.getPrice(),
334+
databaseInfo.getItem(),
335+
databaseInfo.getModerators(),
336+
databaseInfo.isUnlimited(),
337+
databaseInfo.getType(),
338+
databaseInfo.getExtra());
339+
shopsInDatabaseList.add(shop);
340+
} catch (Exception e) {
341+
exceptionHandler(e, null);
342342
}
343343
}
344+
return shopsInDatabaseList;
344345
}
345346

346347
@NotNull
347348
public List<ShopRawDatabaseInfo> getOriginShopsInDatabase() {
348-
return new ArrayList<>(shopRawDatabaseInfoList);
349+
errors = 0;
350+
List<ShopRawDatabaseInfo> shopRawDatabaseInfoList = new ArrayList<>();
351+
try (WarpedResultSet warpRS = plugin.getDatabaseHelper().selectAllShops(); ResultSet rs = warpRS.getResultSet()) {
352+
this.plugin.getLogger().info("Getting shops from the database...");
353+
while (rs.next()) {
354+
ShopRawDatabaseInfo origin = new ShopRawDatabaseInfo(rs);
355+
shopRawDatabaseInfoList.add(origin);
356+
}
357+
} catch (SQLException e) {
358+
exceptionHandler(e, null);
359+
return Collections.emptyList();
360+
}
361+
return shopRawDatabaseInfoList;
349362
}
350363

351364
@Getter

0 commit comments

Comments
 (0)