Skip to content

Commit dbd93d7

Browse files
authored
Require empty hand (#14)
* add config option * add logic I also realized I could reuse the 'block' variable again to clean the code up a bit * add to README * Use .isEmpty() * use .getInventory().getItemInMainHand()
1 parent b556038 commit dbd93d7

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ players:
4646
enabled: true
4747
blocks:
4848
enabled: true
49+
require-empty-hand: false # a player's main hand must be empty to sit
4950
right-click: true # allow sitting with right click
5051
left-click: false # allow sitting with left click
5152
blocks:

src/main/java/de/varilx/sit/listener/BlockSitListener.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ public BlockSitListener(VSit plugin) {
2929

3030
@EventHandler(priority = EventPriority.LOWEST)
3131
public void onPlayerInteract(PlayerInteractEvent event) {
32-
if (event.getClickedBlock() == null) return;
32+
Block block = event.getClickedBlock();
33+
if (block == null) return;
3334
VaxConfiguration configuration = BaseAPI.get().getConfiguration();
3435
if (!configuration.getBoolean("blocks.enabled")) return;
3536
if (!configuration.getBoolean("enabled")) return;
36-
37-
Block block = event.getClickedBlock();
3837
if (configuration.getStringList("blocks.blocked-worlds").contains(block.getWorld().getName())) return;
3938
Player player = event.getPlayer();
4039
if (player.isSneaking()) return;
41-
40+
if (configuration.getBoolean("blocks.require-empty-hand") && !player.getInventory().getItemInMainHand().isEmpty()) return;
41+
4242
for (String blockStr : configuration.getStringList("blocks.blocks")) {
4343
if (block.getType().name().toLowerCase().contains(blockStr.toLowerCase())) {
4444
if (!configuration.getBoolean("blocks.right-click") && event.getAction() == Action.RIGHT_CLICK_BLOCK) return;

src/main/resources/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ players:
88

99
blocks:
1010
enabled: true
11+
require-empty-hand: false
1112
right-click: true
1213
left-click: false
1314
blocked-worlds:

0 commit comments

Comments
 (0)