|
8 | 8 | import org.bukkit.event.inventory.InventoryDragEvent; |
9 | 9 | import org.bukkit.inventory.Inventory; |
10 | 10 | import org.bukkit.inventory.ItemStack; |
| 11 | +import org.bukkit.plugin.Plugin; |
11 | 12 |
|
12 | 13 | /** |
13 | 14 | * Prevents backpacks from being placed inside other backpacks (inception protection). |
| 15 | + * Can be disabled via the {@code allow-backpack-inception} config option. |
14 | 16 | */ |
15 | 17 | public class BackpackProtectionListener implements Listener { |
16 | 18 |
|
| 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 | + |
17 | 31 | /** |
18 | 32 | * Handles inventory click events to prevent backpack inception. |
19 | 33 | * |
20 | 34 | * @param event the inventory click event |
21 | 35 | */ |
22 | 36 | @EventHandler |
23 | 37 | public void onInventoryClick(InventoryClickEvent event) { |
| 38 | + if (plugin.getConfig().getBoolean("allow-backpack-inception", false)) { |
| 39 | + return; |
| 40 | + } |
| 41 | + |
24 | 42 | Inventory clickedInventory = event.getClickedInventory(); |
25 | 43 | if (clickedInventory == null) { |
26 | 44 | return; |
@@ -64,6 +82,10 @@ public void onInventoryClick(InventoryClickEvent event) { |
64 | 82 | */ |
65 | 83 | @EventHandler |
66 | 84 | public void onInventoryDrag(InventoryDragEvent event) { |
| 85 | + if (plugin.getConfig().getBoolean("allow-backpack-inception", false)) { |
| 86 | + return; |
| 87 | + } |
| 88 | + |
67 | 89 | // Check if dragging into a backpack inventory by title |
68 | 90 | String title = event.getView().getTitle(); |
69 | 91 | if (!isBackpackTitle(title)) { |
|
0 commit comments