Don't allow players without access trust to shoot targets

This commit is contained in:
Teriuihi 2023-01-24 01:58:54 +01:00
parent 06109e617b
commit f5a99cefd3

View File

@ -294,7 +294,7 @@ public class BlockEventHandler implements Listener
//If block is a chest, don't allow a DoubleChest to form across a claim boundary
denyConnectingDoubleChestsAcrossClaimBoundary(claim, block, player);
if (claim != null)
{
playerData.lastClaim = claim;
@ -861,7 +861,7 @@ public class BlockEventHandler implements Listener
Block block = event.getHitBlock();
// Ensure projectile affects block.
if (block == null || block.getType() != Material.CHORUS_FLOWER)
if (block == null || !(block.getType() == Material.CHORUS_FLOWER || block.getType() == Material.TARGET))
return;
Claim claim = dataStore.getClaimAt(block.getLocation(), false, null);
@ -871,8 +871,8 @@ public class BlockEventHandler implements Listener
Player shooter = null;
Projectile projectile = event.getEntity();
if (projectile.getShooter() instanceof Player)
shooter = (Player) projectile.getShooter();
if (projectile.getShooter() instanceof Player player)
shooter = player;
if (shooter == null)
{
@ -880,13 +880,20 @@ public class BlockEventHandler implements Listener
return;
}
Supplier<String> allowContainer = claim.checkPermission(shooter, ClaimPermission.Inventory, event);
Supplier<String> allowAction = claim.checkPermission(
shooter,
switch (block.getType())
{
case CHORUS_FLOWER -> ClaimPermission.Inventory;
case TARGET -> ClaimPermission.Access;
default -> ClaimPermission.Build;
},
event);
if (allowContainer != null)
if (allowAction != null)
{
event.setCancelled(true);
GriefPrevention.sendMessage(shooter, TextMode.Err, allowContainer.get());
return;
GriefPrevention.sendMessage(shooter, TextMode.Err, allowAction.get());
}
}