Allow interacting with chests and trapdoors if doing so would not actually open them

Previously players were not able to use potions on top of these kinds of blocks or place blocks on top of them with shift right click. This change will allow that behaviour.
This commit is contained in:
okx-code
2024-03-16 20:17:58 +00:00
parent 134bd1cca6
commit ae6eaee183

View File

@@ -222,21 +222,30 @@ public class BlockListener implements Listener {
if (rein == null) {
return;
}
Player player = e.getPlayer();
// Logic copied from ServerPlayerGameMode#useItemOn
// This will let the event happen if the player is not going to actually open/interact with the block
boolean flag = player.getInventory().getItemInMainHand().getType() != Material.AIR || player.getInventory().getItemInOffHand().getType() != Material.AIR;
if (player.isSneaking() && flag) {
return;
}
if (e.getClickedBlock().getState() instanceof Container) {
if (!rein.hasPermission(e.getPlayer(), CitadelPermissionHandler.getChests())) {
if (!rein.hasPermission(player, CitadelPermissionHandler.getChests())) {
e.setCancelled(true);
String msg = String.format("%s is locked with %s%s", e.getClickedBlock().getType().name(),
ChatColor.AQUA, rein.getType().getName());
CitadelUtility.sendAndLog(e.getPlayer(), ChatColor.RED, msg, e.getClickedBlock().getLocation());
CitadelUtility.sendAndLog(player, ChatColor.RED, msg, e.getClickedBlock().getLocation());
}
return;
}
if (e.getClickedBlock().getBlockData() instanceof Openable) {
if (!rein.hasPermission(e.getPlayer(), CitadelPermissionHandler.getDoors())) {
if (!rein.hasPermission(player, CitadelPermissionHandler.getDoors())) {
e.setCancelled(true);
String msg = String.format("%s is locked with %s%s", e.getClickedBlock().getType().name(),
ChatColor.AQUA, rein.getType().getName());
CitadelUtility.sendAndLog(e.getPlayer(), ChatColor.RED, msg, e.getClickedBlock().getLocation());
CitadelUtility.sendAndLog(player, ChatColor.RED, msg, e.getClickedBlock().getLocation());
}
}
}