Skip to content

Commit

Permalink
Fix door, trapdoor and gate permissions not checked
Browse files Browse the repository at this point in the history
  • Loading branch information
Swanty committed Jul 21, 2024
1 parent 507ed6c commit 02af1b3
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.md_5.bungee.api.chat.hover.content.Text;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.data.type.Lectern;
import org.bukkit.block.data.type.*;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -64,14 +64,15 @@ public void playerInteract(PlayerInteractEvent event) {
sendMessage(player, Translator.get(TranslationKey.MESSAGES__NO_PERMISSION));
} else {
BlockNBTHandler handler = new BlockNBTHandler(event.getClickedBlock());
final var blockData = event.getClickedBlock().getBlockData();
if (!(handler.canAccess(player.getUniqueId().toString()) || player.hasPermission(Permissions.BYPASS.key()))) {
event.setCancelled(true);
sendMessage(player, Translator.get(TranslationKey.MESSAGES__NO_PERMISSION));
} else if (event.getClickedBlock().getType() == Material.LECTERN && !handler.isOwner(player.getUniqueId())) {
// With Lecterns you place the books by interacting with the block. canAccess will return true because the
// player has the READ permission, but this should not be allowed in this case. In the case that the player
// wants to take the book from the lectern (hasBook returns true) we already listen for PlayerTakeLecternBookEvent.
final var lectern = (Lectern)event.getClickedBlock().getBlockData();
final var lectern = (Lectern)blockData;
if (!lectern.hasBook()) {
final var friend = handler.getFriend(player.getUniqueId().toString());
if (friend.isEmpty() || !friend.get().canWrite()) {
Expand All @@ -80,6 +81,13 @@ public void playerInteract(PlayerInteractEvent event) {
sendMessage(player, Translator.get(TranslationKey.MESSAGES__NO_PERMISSION));
}
}
} else if ((blockData instanceof Door || blockData instanceof TrapDoor || blockData instanceof Gate) && !handler.isOwner(player.getUniqueId())) {
final var friend = handler.getFriend(player.getUniqueId().toString());
if (friend.isEmpty() || !friend.get().canWrite()) {
// The player cannot write and therefore is not allowed to change the door open state.
event.setCancelled(true);
sendMessage(player, Translator.get(TranslationKey.MESSAGES__NO_PERMISSION));
}
} else if (!(new PlayerSettingsHandler(player).hasPlayerInteractedWithMenu())) {
Long timestamp = LockHintMessageCooldown.getTimestamp(player);
if (timestamp == null || timestamp < System.currentTimeMillis() - (BlockProt.getDefaultConfig().getLockHintCooldown() * 1000)) { // 10 seconds in milliseconds
Expand Down

0 comments on commit 02af1b3

Please sign in to comment.