|
10 | 10 | import org.bukkit.Location; |
11 | 11 | import org.bukkit.Material; |
12 | 12 | import org.bukkit.World; |
| 13 | +import org.bukkit.block.Block; |
13 | 14 | import org.bukkit.block.BlockState; |
14 | 15 | import org.bukkit.block.DoubleChest; |
15 | 16 | import org.bukkit.entity.Player; |
16 | 17 | import org.bukkit.event.EventHandler; |
17 | 18 | import org.bukkit.event.EventPriority; |
18 | 19 | import org.bukkit.event.Listener; |
19 | | -import org.bukkit.event.inventory.InventoryAction; |
20 | | -import org.bukkit.event.inventory.InventoryClickEvent; |
21 | | -import org.bukkit.event.inventory.InventoryDragEvent; |
22 | | -import org.bukkit.event.inventory.InventoryMoveItemEvent; |
23 | | -import org.bukkit.event.inventory.InventoryType; |
24 | | -import org.bukkit.inventory.BlockInventoryHolder; |
25 | | -import org.bukkit.inventory.Inventory; |
26 | | -import org.bukkit.inventory.InventoryHolder; |
27 | | -import org.bukkit.inventory.ItemStack; |
| 20 | +import org.bukkit.event.inventory.*; |
| 21 | +import org.bukkit.inventory.*; |
28 | 22 |
|
29 | 23 | import net.coreprotect.CoreProtect; |
30 | 24 | import net.coreprotect.config.Config; |
@@ -342,9 +336,57 @@ private boolean checkAnvilOperation(InventoryClickEvent event) { |
342 | 336 | return true; |
343 | 337 | } |
344 | 338 |
|
| 339 | + private boolean checkCrafterSlotChange(InventoryClickEvent event) { |
| 340 | + // Check if the clicked inventory is a crafter |
| 341 | + if (event.getInventory().getType() != InventoryType.CRAFTER) { |
| 342 | + return false; |
| 343 | + } |
| 344 | + |
| 345 | + // Check that the Action is NOTHING |
| 346 | + if (event.getAction() != InventoryAction.NOTHING) { |
| 347 | + return false; |
| 348 | + } |
| 349 | + |
| 350 | + // Check if the clicked slot is one of the crafter slots |
| 351 | + if (event.getRawSlot() < 0 || event.getRawSlot() > 8) { |
| 352 | + return false; |
| 353 | + } |
| 354 | + |
| 355 | + // Check that the click type is not a middle click |
| 356 | + if (!(event.getClick() == ClickType.LEFT || event.getClick() == ClickType.RIGHT)) { |
| 357 | + return false; |
| 358 | + } |
| 359 | + |
| 360 | + // Gather other necessary information |
| 361 | + Player player = (Player) event.getWhoClicked(); |
| 362 | + Inventory inventory = event.getInventory(); |
| 363 | + |
| 364 | + Location location = null; |
| 365 | + try { |
| 366 | + location = inventory.getLocation(); |
| 367 | + } catch (Exception e) { |
| 368 | + return false; |
| 369 | + } |
| 370 | + |
| 371 | + if (location == null) { |
| 372 | + return false; |
| 373 | + } |
| 374 | + |
| 375 | + Block block = location.getBlock(); |
| 376 | + BlockState blockState = block.getState(); |
| 377 | + |
| 378 | + Queue.queueBlockPlace(player.getName(), blockState, block.getType(), blockState, block.getType(), -1, 0, blockState.getBlockData().getAsString()); |
| 379 | + return true; |
| 380 | + } |
| 381 | + |
345 | 382 | @EventHandler(priority = EventPriority.LOWEST) |
346 | 383 | protected void onInventoryClick(InventoryClickEvent event) { |
347 | 384 | InventoryAction inventoryAction = event.getAction(); |
| 385 | + |
| 386 | + if (checkCrafterSlotChange(event)) { |
| 387 | + return; |
| 388 | + } |
| 389 | + |
348 | 390 | if (inventoryAction == InventoryAction.NOTHING) { |
349 | 391 | return; |
350 | 392 | } |
|
0 commit comments