Skip to content

Commit cffc931

Browse files
committed
feat: add sell and experience collection button to GUI and update related messages
1 parent 7b345be commit cffc931

11 files changed

Lines changed: 76 additions & 7 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,25 @@ private void handleControlSlotClick(Player player, int slot, StoragePageHolder h
153153
plugin.getSpawnerSellConfirmUI().openSellConfirmGui(player, spawner, STORAGE, false);
154154
}
155155
break;
156+
case "sell_and_exp":
157+
if (plugin.hasSellIntegration()) {
158+
if (!player.hasPermission("smartspawner.sellall")) {
159+
messageService.sendMessage(player, "no_permission");
160+
return;
161+
}
162+
if (isControlClickTooFrequent(player)) {
163+
return;
164+
}
165+
// Check if there are items to sell
166+
if (spawner.getVirtualInventory().getUsedSlots() == 0) {
167+
messageService.sendMessage(player, "no_items");
168+
return;
169+
}
170+
// Open confirmation GUI - from storage, WITH exp collection
171+
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1.0f, 1.0f);
172+
plugin.getSpawnerSellConfirmUI().openSellConfirmGui(player, spawner, STORAGE, true);
173+
}
174+
break;
156175
case "return":
157176
openMainMenu(player, spawner);
158177
break;

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ private void addNavigationButtons(Map<Integer, ItemStack> updates, SpawnerData s
320320
ItemStack sellIndicator = createSellButton(spawner, sellButton.getMaterial());
321321
updates.put(sellButton.getSlot(), sellIndicator);
322322
}
323+
324+
// Add sell and exp button if shop integration is available and button is enabled
325+
if (layout.hasButton("sell_and_exp")) {
326+
GuiButton sellAndExpButton = layout.getButton("sell_and_exp");
327+
ItemStack sellAndExpIndicator = createSellAndExpButton(spawner, sellAndExpButton.getMaterial());
328+
updates.put(sellAndExpButton.getSlot(), sellAndExpIndicator);
329+
}
323330
}
324331

325332
private int calculateTotalPages(SpawnerData spawner) {
@@ -380,6 +387,21 @@ private ItemStack createSellButton(SpawnerData spawner, Material material) {
380387
return createButton(material, name, lore);
381388
}
382389

390+
private ItemStack createSellAndExpButton(SpawnerData spawner, Material material) {
391+
// Create placeholders for total sell price
392+
Map<String, String> placeholders = new HashMap<>();
393+
// Check if sell value needs recalculation before displaying
394+
if (spawner.isSellValueDirty()) {
395+
spawner.recalculateSellValue();
396+
}
397+
double totalSellPrice = spawner.getAccumulatedSellValue();
398+
placeholders.put("total_sell_price", languageManager.formatNumber(totalSellPrice));
399+
400+
String name = languageManager.getGuiItemName("sell_and_exp_button.name", placeholders);
401+
List<String> lore = languageManager.getGuiItemLoreAsList("sell_and_exp_button.lore");
402+
return createButton(material, name, lore);
403+
}
404+
383405
private ItemStack createSortButton(SpawnerData spawner, Material material) {
384406
Map<String, String> placeholders = new HashMap<>();
385407

core/src/main/resources/gui_layouts/default/storage_gui.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ buttons:
2222
material: HOPPER
2323
enabled: true
2424

25-
# Sell or Return button (handled by legacy button type logic)
25+
# Sell button (only sell items, no XP collection)
2626
sell_all:
2727
slot: 5
2828
material: GOLD_INGOT
2929
enabled: true
3030
condition: "shop_integration"
3131

32-
# Return to main menu button (fallback for slot 5 when no shop integration)
32+
# Sell and collect XP button (sell items + collect XP)
33+
# Note: Can only be enabled if sell_all is disabled, as they occupy the same slot
34+
sell_and_exp:
35+
slot: 5
36+
material: GOLD_INGOT
37+
enabled: false
38+
condition: "shop_integration"
39+
40+
# Return to main menu button (fallback when no shop integration)
3341
return:
3442
slot: 5
3543
material: RED_STAINED_GLASS_PANE

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ sell_button:
162162
lore:
163163
- '&fClick to sell all mob drops'
164164

165+
sell_and_exp_button:
166+
name: '&aꜱᴇʟʟ & ᴇxᴘ: +${total_sell_price}'
167+
lore:
168+
- '&fClick to sell items and collect experience'
169+
165170
return_button:
166171
name: '&#FC0000ʀᴇᴛᴜʀɴ'
167172
lore:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ exp_collected_with_mending:
6161
# Spawner - Storage GUI Interactions
6262
# ------------------------------------------------------
6363
click_too_fast:
64-
action_bar: "&#ff5252ʏᴏᴜ ᴀʀᴇ ᴄʟɪᴄᴋɪɴɢ ᴛᴏᴏ ꜰᴀꜱᴛ! ᴘʟᴇᴀꜱᴇ ꜱʟᴏᴡ ᴅᴏᴡɴ."
64+
message: "&#ff5252ʏᴏᴜ ᴀʀᴇ ᴄʟɪᴄᴋɪɴɢ ᴛᴏᴏ ꜰᴀꜱᴛ! ᴘʟᴇᴀꜱᴇ ꜱʟᴏᴡ ᴅᴏᴡɴ."
6565
sound: block.note_block.bass
6666

6767
inventory_full:

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ sell_button:
243243
lore:
244244
- '&a⊳ &#f8f8ffᴋʟɪᴄᴋᴇɴ ᴜᴍ ᴀʟʟᴇ ɪᴛᴇᴍꜱ ᴢᴜ ᴠᴇʀᴋᴀᴜꜰᴇɴ'
245245

246+
sell_and_exp_button:
247+
name: '&aᴠᴇʀᴋᴀᴜꜰᴇɴ & ᴇxᴘ: +${total_sell_price}'
248+
lore:
249+
- '&a⊳ &#f8f8ffᴋʟɪᴄᴋᴇɴ ᴜᴍ ɪᴛᴇᴍꜱ ᴢᴜ ᴠᴇʀᴋᴀᴜꜰᴇɴ ᴜɴᴅ ᴇxᴘ ᴢᴜ ꜱᴀᴍᴍᴇʟɴ'
250+
246251
return_button:
247252
name: '&#ff5252ᴢᴜʀᴜᴇᴄᴋ ᴢᴜᴍ ʜᴀᴜᴘᴛᴍᴇɴᴜᴇ'
248253
lore:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ exp_collected_with_mending:
6161
# Spawner - Storage GUI Interactions
6262
# ------------------------------------------------------
6363
click_too_fast:
64-
action_bar: "&#ff5252ᴅᴜ ᴋʟɪᴄᴋꜱᴛ ᴢᴜ ꜱᴄʜɴᴇʟʟ! ʙɪᴛᴛᴇ ʟᴀɴɢꜱᴀᴍᴇʀ."
64+
message: "&#ff5252ᴅᴜ ᴋʟɪᴄᴋꜱᴛ ᴢᴜ ꜱᴄʜɴᴇʟʟ! ʙɪᴛᴛᴇ ʟᴀɴɢꜱᴀᴍᴇʀ."
6565
sound: block.note_block.bass
6666

6767
inventory_full:

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ sell_button:
243243
lore:
244244
- '&a⊳ &#f8f8ffᴄʟɪᴄᴋ ᴛᴏ ꜱᴇʟʟ ᴀʟʟ ɪᴛᴇᴍꜱ'
245245

246+
sell_and_exp_button:
247+
name: '&aꜱᴇʟʟ & ᴄᴏʟʟᴇᴄᴛ ᴇxᴘ: +${total_sell_price}'
248+
lore:
249+
- '&a⊳ &#f8f8ffᴄʟɪᴄᴋ ᴛᴏ ꜱᴇʟʟ ɪᴛᴇᴍꜱ ᴀɴᴅ ᴄᴏʟʟᴇᴄᴛ ᴇxᴘ'
250+
246251
return_button:
247252
name: '&#ff5252ʀᴇᴛᴜʀɴ ᴛᴏ ᴍᴀɪɴ ᴍᴇɴᴜ'
248253
lore:

core/src/main/resources/language/en_US/messages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ exp_collected_with_mending:
6161
# Spawner - Storage GUI Interactions
6262
# ------------------------------------------------------
6363
click_too_fast:
64-
action_bar: "&#ff5252ʏᴏᴜ ᴀʀᴇ ᴄʟɪᴄᴋɪɴɢ ᴛᴏᴏ ꜰᴀꜱᴛ! ᴘʟᴇᴀꜱᴇ ꜱʟᴏᴡ ᴅᴏᴡɴ."
64+
message: "&#ff5252ʏᴏᴜ ᴀʀᴇ ᴄʟɪᴄᴋɪɴɢ ᴛᴏᴏ ꜰᴀꜱᴛ! ᴘʟᴇᴀꜱᴇ ꜱʟᴏᴡ ᴅᴏᴡɴ."
6565
sound: block.note_block.bass
6666

6767
inventory_full:

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,15 @@ navigation_button_next:
239239
- '&#2cc483⊳ &#f8f8ffɴʜấᴘ để đếɴ ᴛʀᴀɴɢ &#37eb9a{target_page}'
240240

241241
sell_button:
242-
name: '&aʙáɴ ᴠậᴛ ᴘʜẩᴍ: +${total_sell_price}'
242+
name: '&aʙáɴ ᴠậᴛ ᴘʜẩᴍ: +{total_sell_price}$'
243243
lore:
244244
- '&a⊳ &#f8f8ffɴʜấᴘ để ʙáɴ ᴛấᴛ ᴄả ᴠậᴛ ᴘʜẩᴍ'
245245

246+
sell_and_exp_button:
247+
name: '&aʙáɴ & ɴʜậɴ ᴇxᴘ: +{total_sell_price}đ'
248+
lore:
249+
- '&a⊳ &#f8f8ffɴʜấᴘ để ʙáɴ ᴠậᴛ ᴘʜẩᴍ ᴠà ɴʜậɴ ᴋɪɴʜ ɴɢʜɪệᴍ'
250+
246251
return_button:
247252
name: '&#ff5252ᴛʀở ᴠề ᴍᴇɴᴜ ᴄʜíɴʜ'
248253
lore:

0 commit comments

Comments
 (0)