Skip to content

Commit 89868b5

Browse files
committed
feat: add allow-backpack-inception config option to enable placing backpacks in backpacks
1 parent 17d9e6b commit 89868b5

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/main/java/com/shweit/expendablebackpacks/ExpendableBackpacks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void onEnable() {
4848
getServer().getPluginManager().registerEvents(
4949
new BackpackInteractionListener(backpackManager), this);
5050
getServer().getPluginManager().registerEvents(
51-
new BackpackProtectionListener(), this);
51+
new BackpackProtectionListener(this), this);
5252
getServer().getPluginManager().registerEvents(
5353
new BackpackBlockListener(), this);
5454
getServer().getPluginManager().registerEvents(

src/main/java/com/shweit/expendablebackpacks/listeners/BackpackProtectionListener.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,37 @@
88
import org.bukkit.event.inventory.InventoryDragEvent;
99
import org.bukkit.inventory.Inventory;
1010
import org.bukkit.inventory.ItemStack;
11+
import org.bukkit.plugin.Plugin;
1112

1213
/**
1314
* Prevents backpacks from being placed inside other backpacks (inception protection).
15+
* Can be disabled via the {@code allow-backpack-inception} config option.
1416
*/
1517
public class BackpackProtectionListener implements Listener {
1618

19+
private final Plugin plugin;
20+
21+
/**
22+
* Creates a new backpack protection listener.
23+
*
24+
* @param plugin the plugin instance used to read configuration
25+
*/
26+
@SuppressWarnings("EI_EXPOSE_REP2")
27+
public BackpackProtectionListener(Plugin plugin) {
28+
this.plugin = plugin;
29+
}
30+
1731
/**
1832
* Handles inventory click events to prevent backpack inception.
1933
*
2034
* @param event the inventory click event
2135
*/
2236
@EventHandler
2337
public void onInventoryClick(InventoryClickEvent event) {
38+
if (plugin.getConfig().getBoolean("allow-backpack-inception", false)) {
39+
return;
40+
}
41+
2442
Inventory clickedInventory = event.getClickedInventory();
2543
if (clickedInventory == null) {
2644
return;
@@ -64,6 +82,10 @@ public void onInventoryClick(InventoryClickEvent event) {
6482
*/
6583
@EventHandler
6684
public void onInventoryDrag(InventoryDragEvent event) {
85+
if (plugin.getConfig().getBoolean("allow-backpack-inception", false)) {
86+
return;
87+
}
88+
6789
// Check if dragging into a backpack inventory by title
6890
String title = event.getView().getTitle();
6991
if (!isBackpackTitle(title)) {

src/main/resources/config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
# Starter Backpack Settings
88
# ---------------------------
99

10+
# ---------------------------
11+
# Inception Settings
12+
# ---------------------------
13+
14+
# Allow players to place backpacks inside other backpacks
15+
# Set to 'true' to enable the "Inception" mode, 'false' to disable
16+
# Default: false
17+
allow-backpack-inception: false
18+
19+
# ---------------------------
20+
# Starter Backpack Settings
21+
# ---------------------------
22+
1023
# Give a Leather Backpack to players when they first join the server
1124
# Set to 'true' to enable, 'false' to disable
1225
# Default: false

0 commit comments

Comments
 (0)