Skip to content

Commit

Permalink
improve(stick): limit container type by InventoryType
Browse files Browse the repository at this point in the history
  • Loading branch information
Siroshun09 committed Apr 15, 2024
1 parent 74787bb commit 15f46c1
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemBreakEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
Expand All @@ -38,8 +39,12 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.EnumSet;

public class StickListener implements Listener {

private static final EnumSet<InventoryType> CONTAINERS = EnumSet.of(InventoryType.BARREL, InventoryType.CHEST, InventoryType.DISPENSER, InventoryType.DROPPER, InventoryType.HOPPER, InventoryType.SHULKER_BOX);

private final BoxStickItem boxStickItem;

public StickListener(@NotNull BoxStickItem boxStickItem) {
Expand Down Expand Up @@ -164,7 +169,13 @@ private void clickContainer(@NotNull PlayerInteractEvent event, @NotNull BoxPlay
var inventory = container.getInventory();
ContainerOperation<?> operation;

if (inventory instanceof FurnaceInventory furnaceInventory) { // BlastFurnace, Furnace, and Smoker
if (CONTAINERS.contains(inventory.getType())) {
operation = new ContainerOperation<>(
ContainerOperation.createContext(boxPlayer, operationType, inventory, clickedBlockLocation),
ContainerOperator::process,
"container"
);
} else if (inventory instanceof FurnaceInventory furnaceInventory) { // BlastFurnace, Furnace, and Smoker
operation = new ContainerOperation<>(
ContainerOperation.createContext(boxPlayer, operationType, furnaceInventory, clickedBlockLocation),
FurnaceOperator::process,
Expand All @@ -176,12 +187,8 @@ private void clickContainer(@NotNull PlayerInteractEvent event, @NotNull BoxPlay
BrewerOperator::process,
"brewer"
);
} else { // other containers (Barrel, Chest, Dispenser, Dropper, Hopper, and ShulkerBox)
operation = new ContainerOperation<>(
ContainerOperation.createContext(boxPlayer, operationType, inventory, clickedBlockLocation),
ContainerOperator::process,
"container"
);
} else {
return;
}

if (!player.hasPermission("box.stick." + operation.permissionSuffix()) ||
Expand Down

0 comments on commit 15f46c1

Please sign in to comment.