Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more protection options for RedProtectProtectionModule #112

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Container;
import org.bukkit.block.data.Openable;
import org.bukkit.block.data.Powerable;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

Expand Down Expand Up @@ -46,7 +49,15 @@ public boolean hasPermission(OfflinePlayer p, Location l, Interaction action) {
Player player = (Player) p;
switch (action) {
case INTERACT_BLOCK:
return region.canChest(player);
if (l.getBlock() instanceof Container){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container is an extension of BlockState, only the block's state can therefore be an instance of Container.

return region.canChest(player);
}
if (l.getBlock().getBlockData() instanceof Powerable){
return region.canButton(player) || region.canLever(player);
}
if (l.getBlock().getBlockData() instanceof Openable){
return region.canDoor(player);
}
Comment on lines +55 to +60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block#getBlockData() is a rather expensive check, Block#getState() is even worse.
A material check would yield significantly better performance here

Also, you are potentially calling Block#getBlockData() twice per run here too which is redundant.

case ATTACK_ENTITY:
case INTERACT_ENTITY:
return region.canInteractPassives(player);
Expand Down