Skip to content

Commit c7ff1bc

Browse files
committed
Refactor GUI button handling and update layout configuration for spawner info buttons
1 parent 50ff7d6 commit c7ff1bc

6 files changed

Lines changed: 28 additions & 31 deletions

File tree

core/src/main/java/github/nighter/smartspawner/spawner/gui/layout/GuiButton.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ public class GuiButton {
1414
private final String condition;
1515
private final Map<String, String> actions;
1616

17-
public GuiButton(String buttonType, int slot, Material material, boolean enabled) {
18-
this(buttonType, slot, material, enabled, null, null);
19-
}
20-
2117
public GuiButton(String buttonType, int slot, Material material, boolean enabled, String condition, Map<String, String> actions) {
2218
this.buttonType = buttonType;
2319
this.slot = slot;
@@ -34,16 +30,4 @@ public String getAction(String clickType) {
3430
public boolean hasCondition() {
3531
return condition != null && !condition.isEmpty();
3632
}
37-
38-
@Override
39-
public String toString() {
40-
return "GuiButton{" +
41-
"buttonType='" + buttonType + '\'' +
42-
", slot=" + slot +
43-
", material=" + material +
44-
", enabled=" + enabled +
45-
", condition='" + condition + '\'' +
46-
", actions=" + actions +
47-
'}';
48-
}
4933
}

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public void openSpawnerMenu(Player player, SpawnerData spawner, boolean refresh)
5959
items[storageButton.getSlot()] = createLootStorageItem(spawner);
6060
}
6161

62-
// Add spawner info button if enabled in layout
63-
GuiButton spawnerInfoButton = layout.getButton("spawner_info");
62+
// Add spawner info button if enabled in layout - handle conditional buttons
63+
GuiButton spawnerInfoButton = getSpawnerInfoButton(layout, player);
6464
if (spawnerInfoButton != null) {
6565
items[spawnerInfoButton.getSlot()] = createSpawnerInfoItem(player, spawner);
6666
}
@@ -396,4 +396,25 @@ public ItemStack createExpItem(SpawnerData spawner) {
396396
private int calculatePercentage(long current, long maximum) {
397397
return maximum > 0 ? (int) ((double) current / maximum * 100) : 0;
398398
}
399-
}
399+
400+
private GuiButton getSpawnerInfoButton(GuiLayout layout, Player player) {
401+
// Check for shop integration permission
402+
boolean hasShopPermission = plugin.hasSellIntegration() && player.hasPermission("smartspawner.sellall");
403+
404+
// Try to get the appropriate conditional button first
405+
if (hasShopPermission) {
406+
GuiButton shopButton = layout.getButton("spawner_info_with_shop");
407+
if (shopButton != null) {
408+
return shopButton;
409+
}
410+
} else {
411+
GuiButton noShopButton = layout.getButton("spawner_info_no_shop");
412+
if (noShopButton != null) {
413+
return noShopButton;
414+
}
415+
}
416+
417+
// Fallback to the generic spawner_info button if conditional ones don't exist
418+
return layout.getButton("spawner_info");
419+
}
420+
}

core/src/main/resources/gui_layouts/DonutSMP/main_gui.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# Valid materials can be found at: https://jd.papermc.io/paper/1.21.8/org/bukkit/Material.html
44
# Note: For PLAYER_HEAD material, the texture will be automatically set based on the spawner entity type
55

6-
gui_layout_version: "1.0.0"
7-
86
buttons:
97

108
# Storage access button

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# Slot positions: 1-9 corresponds to inventory slots 46-54 (bottom row)
33
# Valid materials can be found at: https://jd.papermc.io/paper/1.21.6/org/bukkit/Material.html
44

5-
gui_layout_version: "1.0.0"
6-
75
buttons:
86
# Return to main menu button
97
return:

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
# Valid materials can be found at: https://jd.papermc.io/paper/1.21.8/org/bukkit/Material.html
44
# Note: For PLAYER_HEAD material, the texture will be automatically set based on the spawner entity type
55

6-
gui_layout_version: "1.0.0"
7-
86
buttons:
97

108
# Storage access button
119
storage:
12-
slot: 11
10+
slot: 12
1311
material: CHEST
1412
enabled: true
1513
actions:
@@ -19,7 +17,7 @@ buttons:
1917
# Spawner information display with shop integration
2018
# With shop integration: Left click for selling/XP, right click for stacker
2119
spawner_info_with_shop:
22-
slot: 13
20+
slot: 14
2321
material: PLAYER_HEAD
2422
enabled: true
2523
condition: "shop_integration"
@@ -30,7 +28,7 @@ buttons:
3028
# Spawner information display without shop integration
3129
# Without shop integration: Both clicks open stacker GUI
3230
spawner_info_no_shop:
33-
slot: 13
31+
slot: 14
3432
material: PLAYER_HEAD
3533
enabled: true
3634
condition: "no_shop_integration"
@@ -40,7 +38,7 @@ buttons:
4038

4139
# Experience collection button
4240
exp:
43-
slot: 15
41+
slot: 16
4442
material: EXPERIENCE_BOTTLE
4543
enabled: true
4644
actions:

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# Slot positions: 1-9 corresponds to inventory slots 46-54 (bottom row)
33
# Valid materials can be found at: https://jd.papermc.io/paper/1.21.8/org/bukkit/Material.html
44

5-
gui_layout_version: "1.0.0"
6-
75
buttons:
86

97
# Previous page navigation button

0 commit comments

Comments
 (0)