Skip to content

Commit 9c31545

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 9e6c50a + c841510 commit 9c31545

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,20 @@ public synchronized void recoverFromFile(@NotNull String fileContent) {
279279
plugin.getLogger().info("Recovering shops...");
280280
Gson gson = JsonUtil.getGson();
281281
int total = shopsPlain.length;
282-
for (int i = 0; i < total; i++) {
283-
String shopStr = shopsPlain[i].trim();
284-
boolean success = false;
282+
List<ShopRawDatabaseInfo> list = new ArrayList<>(total);
283+
for (String s : shopsPlain) {
284+
String shopStr = s.trim();
285285
try {
286-
ShopRawDatabaseInfo shopDatabaseInfoOrigin = gson.fromJson(shopStr, ShopRawDatabaseInfo.class);
287-
ShopDatabaseInfo data = new ShopDatabaseInfo(shopDatabaseInfoOrigin);
286+
list.add(gson.fromJson(shopStr, ShopRawDatabaseInfo.class));
287+
} catch (JsonSyntaxException ignore) {
288+
}
289+
}
290+
plugin.getLogger().info("Processed " + total + "/" + total + " - [ Valid " + list.size() + "]");
291+
// Load to RAM
292+
Util.mainThreadRun(() -> {
293+
plugin.getLogger().info("Loading recovered shops...");
294+
for (ShopRawDatabaseInfo rawDatabaseInfo : list) {
295+
ShopDatabaseInfo data = new ShopDatabaseInfo(rawDatabaseInfo);
288296
Shop shop =
289297
new ContainerShop(plugin,
290298
data.getLocation(),
@@ -300,18 +308,13 @@ public synchronized void recoverFromFile(@NotNull String fileContent) {
300308
if (shopNullCheck(shop)) {
301309
continue;
302310
}
303-
// Load to RAM
304-
Util.mainThreadRun(() -> {
305-
plugin.getDatabaseHelper().createShop(shop, null, null);
306-
plugin.getShopManager().loadShop(data.getWorld().getName(), shop);
307-
shop.update();
308-
});
309-
310-
success = true;
311-
} catch (JsonSyntaxException ignore) {
311+
plugin.getDatabaseHelper().createShop(shop, null, null);
312+
plugin.getShopManager().loadShop(data.getWorld().getName(), shop);
313+
shop.update();
312314
}
313-
plugin.getLogger().info("Processed " + i + "/" + total + " - [" + success + "]");
314-
}
315+
plugin.getLogger().info("Finished!");
316+
});
317+
315318
}
316319

317320
// @NotNull

0 commit comments

Comments
 (0)