2525import lombok .Getter ;
2626import lombok .Setter ;
2727import org .apache .commons .lang .StringUtils ;
28- import org .bukkit .Bukkit ;
2928import org .bukkit .Location ;
3029import org .bukkit .Material ;
3130import org .bukkit .World ;
4039import org .maxgamer .quickshop .api .shop .ShopModerator ;
4140import org .maxgamer .quickshop .api .shop .ShopType ;
4241import org .maxgamer .quickshop .util .JsonUtil ;
42+ import org .maxgamer .quickshop .util .Timer ;
4343import org .maxgamer .quickshop .util .Util ;
4444
4545import java .sql .ResultSet ;
@@ -89,10 +89,16 @@ public void loadShops(@Nullable String worldName) {
8989 this .plugin .getLogger ().info ("Fetching shops from the database...If plugin stuck there, check your database connection." );
9090 int loadAfterChunkLoaded = 0 ;
9191 int loadAfterWorldLoaded = 0 ;
92- List <Shop > pendingLoadShops = new ArrayList <>();
92+ int loaded = 0 ;
93+ int total = 0 ;
94+ int valid = 0 ;
9395 try (WarpedResultSet warpRS = plugin .getDatabaseHelper ().selectAllShops (); ResultSet rs = warpRS .getResultSet ()) {
96+ Timer timer = new Timer ();
97+ timer .start ();
98+ boolean deleteCorruptShops = plugin .getConfiguration ().getOrDefault ("debug.delete-corrupt-shops" , false );
9499 this .plugin .getLogger ().info ("Loading shops from the database..." );
95100 while (rs .next ()) {
101+ ++total ;
96102 ShopRawDatabaseInfo origin = new ShopRawDatabaseInfo (rs );
97103 if (worldName != null && !origin .getWorld ().equals (worldName )) {
98104 continue ;
@@ -125,7 +131,7 @@ public void loadShops(@Nullable String worldName) {
125131 shop .setDirty ();
126132 }
127133 if (shopNullCheck (shop )) {
128- if (plugin . getConfiguration (). getOrDefault ( "debug.delete-corrupt-shops" , false ) ) {
134+ if (deleteCorruptShops ) {
129135 plugin .getLogger ().warning ("Deleting shop " + shop + " caused by corrupted." );
130136 plugin .getDatabaseHelper ().removeShop (origin .getWorld (), origin .getX (), origin .getY (), origin .getZ ());
131137 } else {
@@ -134,13 +140,15 @@ public void loadShops(@Nullable String worldName) {
134140 }
135141 continue ;
136142 }
143+ ++valid ;
137144 //World unloaded but found
138145 if (!shop .getLocation ().isWorldLoaded ()) {
139146 ++loadAfterWorldLoaded ;
140147 continue ;
141148 }
142149 // Load to RAM
143150 plugin .getShopManager ().loadShop (data .getWorld ().getName (), shop );
151+
144152 if (Util .isLoaded (shop .getLocation ())) {
145153 // Load to World
146154 if (!Util .canBeShop (shop .getLocation ().getBlock ())) {
@@ -150,31 +158,21 @@ public void loadShops(@Nullable String worldName) {
150158 //TODO: Only remove from memory, so if it actually is a bug, user won't lost all shops.
151159 //TODO: Old shop will be deleted when in same location creating new shop.
152160 } else {
153- pendingLoadShops .add (shop );
161+ shop .onLoad ();
162+ shop .update ();
163+ ++loaded ;
154164 }
155165 } else {
156166 loadAfterChunkLoaded ++;
157167 }
158168 }
159-
160- Bukkit .getScheduler ().runTaskLater (plugin , () -> {
161- this .plugin .getLogger ().info ("Loading the shops in worlds..." );
162- for (Shop shop : pendingLoadShops ) {
163- plugin .getShopManager ().loadShop (shop .getLocation ().getWorld ().getName (), shop );
164- shop .onLoad ();
165- shop .update ();
166- }
167- this .plugin
168- .getLogger ()
169- .info (
170- "Successfully loaded "
171- + pendingLoadShops .size ()
172- + " shops!" );
173- }, 1 );
174- this .plugin .getLogger ().info ("Scheduled " + pendingLoadShops .size () + " shops to load in next tick, " + loadAfterChunkLoaded
175- + " shops will load after chunk have loaded, "
176- + loadAfterWorldLoaded
177- + " shops will load after the world has loaded." );
169+ this .plugin .getLogger ().info (">> Shop Loader Information" );
170+ this .plugin .getLogger ().info ("Total shops: " + total );
171+ this .plugin .getLogger ().info ("Valid shops: " + valid );
172+ this .plugin .getLogger ().info ("Loaded shops: " + loaded );
173+ this .plugin .getLogger ().info ("Waiting worlds loaded: " + loadAfterWorldLoaded );
174+ this .plugin .getLogger ().info ("Waiting chunks loaded: " + loadAfterChunkLoaded );
175+ this .plugin .getLogger ().info ("Done! Used " + timer .stopAndGetTimePassed () + "ms to loaded shops in database." );
178176 } catch (Exception e ) {
179177 exceptionHandler (e , null );
180178 }
0 commit comments