Skip to content

Commit e2c43b1

Browse files
committed
feat: refactor SpawnerStorageUI package structure and optimize title placeholder handling
1 parent d0e3c70 commit e2c43b1

12 files changed

Lines changed: 64 additions & 24 deletions

File tree

core/src/main/java/github/nighter/smartspawner/SmartSpawner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import github.nighter.smartspawner.spawner.gui.storage.filter.FilterConfigUI;
3333
import github.nighter.smartspawner.spawner.gui.synchronization.SpawnerGuiViewManager;
3434
import github.nighter.smartspawner.spawner.gui.stacker.SpawnerStackerUI;
35-
import github.nighter.smartspawner.spawner.gui.storage.ui.SpawnerStorageUI;
35+
import github.nighter.smartspawner.spawner.gui.storage.SpawnerStorageUI;
3636
import github.nighter.smartspawner.spawner.gui.storage.SpawnerStorageAction;
3737
import github.nighter.smartspawner.spawner.gui.sell.SpawnerSellConfirmUI;
3838
import github.nighter.smartspawner.spawner.gui.sell.SpawnerSellConfirmListener;

core/src/main/java/github/nighter/smartspawner/spawner/gui/main/SpawnerMenuAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import github.nighter.smartspawner.language.LanguageManager;
77
import github.nighter.smartspawner.language.MessageService;
88
import github.nighter.smartspawner.spawner.gui.stacker.SpawnerStackerUI;
9-
import github.nighter.smartspawner.spawner.gui.storage.ui.SpawnerStorageUI;
9+
import github.nighter.smartspawner.spawner.gui.storage.SpawnerStorageUI;
1010
import github.nighter.smartspawner.spawner.gui.synchronization.SpawnerGuiViewManager;
1111
import github.nighter.smartspawner.spawner.properties.SpawnerData;
1212
import github.nighter.smartspawner.spawner.sell.SpawnerSellManager;

core/src/main/java/github/nighter/smartspawner/spawner/gui/main/SpawnerMenuFormUI.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ private Map<String, String> createPlaceholders(SpawnerData spawner) {
317317
placeholders.put("ᴇɴᴛɪᴛʏ", entityNameSmallCaps);
318318
placeholders.put("entity", entityName);
319319
placeholders.put("amount", String.valueOf(spawner.getStackSize()));
320-
placeholders.put("entity_type", spawner.getEntityType().toString());
321320

322321
// Stack information
323322
placeholders.put("stack_size", String.valueOf(spawner.getStackSize()));

core/src/main/java/github/nighter/smartspawner/spawner/gui/main/SpawnerMenuUI.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ public ItemStack createSpawnerInfoItem(Player player, SpawnerData spawner) {
404404

405405
// Define all available placeholders
406406
Set<String> availablePlaceholders = Set.of(
407-
"entity", "ᴇɴᴛɪᴛʏ", "entity_type", "stack_size", "range", "delay", "min_mobs", "max_mobs",
407+
"entity", "ᴇɴᴛɪᴛʏ", "stack_size", "range", "delay", "min_mobs", "max_mobs",
408408
"current_items", "max_items", "percent_storage_decimal", "percent_storage_rounded",
409409
"current_exp", "max_exp", "raw_current_exp", "raw_max_exp", "percent_exp_decimal", "percent_exp_rounded",
410410
"total_sell_price", "time"
@@ -434,9 +434,6 @@ public ItemStack createSpawnerInfoItem(Player player, SpawnerData spawner) {
434434
placeholders.put("ᴇɴᴛɪᴛʏ", languageManager.getSmallCaps(entityName));
435435
}
436436
}
437-
if (usedPlaceholders.contains("entity_type")) {
438-
placeholders.put("entity_type", entityType.toString());
439-
}
440437

441438
// Stack information
442439
if (usedPlaceholders.contains("stack_size")) {

core/src/main/java/github/nighter/smartspawner/spawner/gui/storage/SpawnerStorageAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import github.nighter.smartspawner.language.MessageService;
55
import github.nighter.smartspawner.spawner.gui.layout.GuiLayoutConfig;
66
import github.nighter.smartspawner.spawner.gui.storage.filter.FilterConfigUI;
7-
import github.nighter.smartspawner.spawner.gui.storage.ui.SpawnerStorageUI;
87
import github.nighter.smartspawner.spawner.gui.main.SpawnerMenuUI;
98
import github.nighter.smartspawner.spawner.gui.synchronization.SpawnerGuiViewManager;
109
import github.nighter.smartspawner.spawner.gui.layout.GuiLayout;

core/src/main/java/github/nighter/smartspawner/spawner/gui/storage/ui/SpawnerStorageUI.java renamed to core/src/main/java/github/nighter/smartspawner/spawner/gui/storage/SpawnerStorageUI.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package github.nighter.smartspawner.spawner.gui.storage.ui;
1+
package github.nighter.smartspawner.spawner.gui.storage;
22

33
import github.nighter.smartspawner.SmartSpawner;
44
import github.nighter.smartspawner.language.LanguageManager;
55
import github.nighter.smartspawner.spawner.gui.layout.GuiButton;
66
import github.nighter.smartspawner.spawner.gui.layout.GuiLayout;
77
import github.nighter.smartspawner.spawner.gui.layout.GuiLayoutConfig;
8-
import github.nighter.smartspawner.spawner.gui.storage.StoragePageHolder;
98
import github.nighter.smartspawner.spawner.properties.VirtualInventory;
109
import github.nighter.smartspawner.spawner.properties.SpawnerData;
1110
import 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

core/src/main/java/github/nighter/smartspawner/spawner/gui/storage/filter/FilterConfigUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import github.nighter.smartspawner.SmartSpawner;
44
import github.nighter.smartspawner.language.LanguageManager;
5-
import github.nighter.smartspawner.spawner.gui.storage.ui.SpawnerStorageUI;
5+
import github.nighter.smartspawner.spawner.gui.storage.SpawnerStorageUI;
66
import github.nighter.smartspawner.spawner.lootgen.loot.LootItem;
77
import github.nighter.smartspawner.spawner.properties.SpawnerData;
88
import org.bukkit.Bukkit;

core/src/main/java/github/nighter/smartspawner/spawner/gui/synchronization/services/StorageUpdateService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import github.nighter.smartspawner.SmartSpawner;
44
import github.nighter.smartspawner.Scheduler;
55
import github.nighter.smartspawner.language.LanguageManager;
6-
import github.nighter.smartspawner.spawner.gui.storage.ui.SpawnerStorageUI;
6+
import github.nighter.smartspawner.spawner.gui.storage.SpawnerStorageUI;
77
import github.nighter.smartspawner.spawner.gui.storage.StoragePageHolder;
88
import github.nighter.smartspawner.spawner.properties.SpawnerData;
99
import org.bukkit.Location;

core/src/main/resources/language/DonutSMP/gui.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ button_sell_info:
145145
# ---------------------------------------------------
146146
# Spawner Storage GUI
147147
# ---------------------------------------------------
148+
# Available placeholders for gui_title_storage:
149+
# {current_page} - Current page number
150+
# {total_pages} - Total number of pages
151+
# {entity} - Formatted entity name (e.g., "Zombie")
152+
# {ᴇɴᴛɪᴛʏ} - Entity name in small caps (e.g., "ᴢᴏᴍʙɪᴇ")
153+
# {amount} - Number of spawners stacked
148154
gui_title_storage: "&#545454ꜱᴘᴀᴡɴᴇʀ ꜱᴛᴏʀᴀɢᴇ - [{current_page}/{total_pages}]"
149155

150156
navigation_button_previous:

core/src/main/resources/language/de_DE/gui.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ spawner_storage_item:
6464
# Entity Information:
6565
# {entity} - Formatted entity name (e.g., "Zombie")
6666
# {ᴇɴᴛɪᴛʏ} - Entity name in small caps (e.g., "ᴢᴏᴍʙɪᴇ")
67-
# {entity_type} - Raw entity type (e.g., "ZOMBIE")
6867
#
6968
# Stack Information:
7069
# {stack_size} - Number of spawners stacked at this location
@@ -226,6 +225,12 @@ button_sell_info:
226225
# ---------------------------------------------------
227226
# Spawner Storage GUI
228227
# ---------------------------------------------------
228+
# Available placeholders for gui_title_storage:
229+
# {current_page} - Current page number
230+
# {total_pages} - Total number of pages
231+
# {entity} - Formatted entity name (e.g., "Zombie")
232+
# {ᴇɴᴛɪᴛʏ} - Entity name in small caps (e.g., "ᴢᴏᴍʙɪᴇ")
233+
# {amount} - Number of spawners stacked
229234
gui_title_storage: '&#545454ꜱᴘᴀᴡɴᴇʀ ʟᴀɢᴇʀ - [{current_page}/{total_pages}]'
230235

231236
navigation_button_previous:

0 commit comments

Comments
 (0)