Skip to content

Commit

Permalink
Use WorldGuard flag "chest-access" for a better check (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
utarwyn committed Jun 9, 2022
1 parent 132e085 commit 7ee638b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

/**
* Interacts with the WorldGuard V6+ plugin.
* Prevent to open chests in zones protected with the flag USE.
* Prevent to open chests in zones protected with the flag "chest-access".
*
* @author Utarwyn
* @since 2.1.0
Expand Down Expand Up @@ -42,8 +42,7 @@ public void validateBlockChestOpening(Block block, Player player)
RegionQuery query = wgPlugin.getRegionContainer().createQuery();

// Check for denied flags at the chest's location!
if (!query.testBuild(block.getLocation(), localPlayer,
DefaultFlag.INTERACT, DefaultFlag.USE)) {
if (!query.testBuild(block.getLocation(), localPlayer, DefaultFlag.CHEST_ACCESS)) {
throw new BlockChestOpeningException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/**
* Interacts with the WorldGuard V7+ plugin.
* Prevent to open chests in zones protected with the flag USE.
* Prevent to open chests in zones protected with the flag "chest-access".
*
* @author Utarwyn
* @since 2.2.0
Expand Down Expand Up @@ -46,7 +46,7 @@ public void validateBlockChestOpening(Block block, Player player)
Location location = BukkitAdapter.adapt(block.getLocation());

// Check for denied flags at the chest's location!
if (!query.testBuild(location, localPlayer, Flags.INTERACT, Flags.USE)) {
if (!query.testBuild(location, localPlayer, Flags.CHEST_ACCESS)) {
throw new BlockChestOpeningException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
Expand Down Expand Up @@ -56,9 +57,12 @@ public class EnderChestListener implements Listener {
*
* @param event The interact event
*/
@EventHandler
@EventHandler(ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) return;
if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.useInteractedBlock() == Event.Result.DENY) {
return;
}

Player player = event.getPlayer();
Block block = event.getClickedBlock();

Expand Down

0 comments on commit 7ee638b

Please sign in to comment.