1- package github .nighter .smartspawner .spawner .gui .storage . ui ;
1+ package github .nighter .smartspawner .spawner .gui .storage ;
22
33import github .nighter .smartspawner .SmartSpawner ;
44import github .nighter .smartspawner .language .LanguageManager ;
55import github .nighter .smartspawner .spawner .gui .layout .GuiButton ;
66import github .nighter .smartspawner .spawner .gui .layout .GuiLayout ;
77import github .nighter .smartspawner .spawner .gui .layout .GuiLayoutConfig ;
8- import github .nighter .smartspawner .spawner .gui .storage .StoragePageHolder ;
98import github .nighter .smartspawner .spawner .properties .VirtualInventory ;
109import github .nighter .smartspawner .spawner .properties .SpawnerData ;
1110import github .nighter .smartspawner .Scheduler ;
@@ -150,22 +149,47 @@ private String getAnyActionFromButton(GuiButton button) {
150149 /**
151150 * Gets the formatted title for storage GUI with page information.
152151 * Uses cached title format pattern for performance.
153- *
152+ * Optimized to only compute entity placeholders if they're used in the title.
153+ *
154+ * @param spawner The spawner data
154155 * @param page Current page number
155156 * @param totalPages Total number of pages
156157 * @return Formatted title with page information
157158 */
158- private String getStorageTitle (int page , int totalPages ) {
159+ private String getStorageTitle (SpawnerData spawner , int page , int totalPages ) {
159160 // Cache the title format pattern (not the filled title)
160161 if (cachedStorageTitleFormat == null ) {
161162 cachedStorageTitleFormat = languageManager .getGuiTitle ("gui_title_storage" );
162163 }
163164
164- // Use placeholder replacement pattern similar to PricesGUI
165- return languageManager .getGuiTitle ("gui_title_storage" , Map .of (
166- "current_page" , String .valueOf (page ),
167- "total_pages" , String .valueOf (totalPages )
168- ));
165+ // Build base placeholders (always present)
166+ Map <String , String > placeholders = new HashMap <>(4 );
167+ placeholders .put ("current_page" , String .valueOf (page ));
168+ placeholders .put ("total_pages" , String .valueOf (totalPages ));
169+
170+ // OPTIMIZATION: Only compute entity placeholders if they exist in the title format
171+ if (cachedStorageTitleFormat .contains ("{entity}" ) || cachedStorageTitleFormat .contains ("{ᴇɴᴛɪᴛʏ}" )) {
172+ String entityName ;
173+ if (spawner .isItemSpawner ()) {
174+ entityName = languageManager .getVanillaItemName (spawner .getSpawnedItemMaterial ());
175+ } else {
176+ entityName = languageManager .getFormattedMobName (spawner .getEntityType ());
177+ }
178+
179+ if (cachedStorageTitleFormat .contains ("{entity}" )) {
180+ placeholders .put ("entity" , entityName );
181+ }
182+ if (cachedStorageTitleFormat .contains ("{ᴇɴᴛɪᴛʏ}" )) {
183+ placeholders .put ("ᴇɴᴛɪᴛʏ" , languageManager .getSmallCaps (entityName ));
184+ }
185+ }
186+
187+ // OPTIMIZATION: Only compute amount if it exists in the title format
188+ if (cachedStorageTitleFormat .contains ("{amount}" )) {
189+ placeholders .put ("amount" , String .valueOf (spawner .getStackSize ()));
190+ }
191+
192+ return languageManager .getGuiTitle ("gui_title_storage" , placeholders );
169193 }
170194
171195 public Inventory createStorageInventory (SpawnerData spawner , int page , int totalPages ) {
@@ -181,7 +205,7 @@ public Inventory createStorageInventory(SpawnerData spawner, int page, int total
181205 Inventory pageInv = Bukkit .createInventory (
182206 new StoragePageHolder (spawner , page , totalPages ),
183207 INVENTORY_SIZE ,
184- getStorageTitle (page , totalPages )
208+ getStorageTitle (spawner , page , totalPages )
185209 );
186210
187211 // Populate the inventory
0 commit comments