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 physical interaction protection flag #28

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Allows players to bypass any restriction
protect.bypass.build
protect.bypass.break
protect.bypass.interact
protect.bypass.physical-interact
protect.bypass.entity-interact
protect.bypass.trample
protect.bypass.enter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ public interface ProtectionService {
*/
boolean canInteract(Player player, Entity entity);

/**
* Determines whether a player can physically interact with an object at a given location.
*
* @param player the player who wants to interact
* @param location the location of the object the player intends to interact with
* @return true if the player can physically interact with the object at the location, false otherwise
*/
boolean canInteractPhysical(Player player, Location location);

/**
* Determines whether a player can shear an entity.
*
Expand Down
1 change: 1 addition & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ paper {
"protect.bypass.break",
"protect.bypass.interact",
"protect.bypass.entity-interact",
"protect.bypass.physical-interact",
"protect.bypass.trample",
"protect.bypass.enter",
"protect.bypass.leave",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public class Flags {
public final Flag<@NotNull Boolean> leavesDecay = flagRegistry().register(ProtectPlugin.this, Boolean.class, "leaves_decay", true);
public final Flag<@NotNull Boolean> naturalCauldronFill = flagRegistry().register(ProtectPlugin.this, Boolean.class, "natural_cauldron_fill", true);
public final Flag<@NotNull Boolean> naturalEntitySpawn = flagRegistry().register(ProtectPlugin.this, Boolean.class, "natural_entity_spawn", true);
public final Flag<@NotNull Boolean> physicalInteract = flagRegistry().register(ProtectPlugin.this, Boolean.class, "physical_interact", true);
public final Flag<@NotNull Boolean> physics = flagRegistry().register(ProtectPlugin.this, Boolean.class, "physics", true);
public final Flag<@NotNull Boolean> playerAttackEntity = flagRegistry().register(ProtectPlugin.this, Boolean.class, "player_attack_entity", true);
public final Flag<@NotNull Boolean> playerAttackPlayer = flagRegistry().register(ProtectPlugin.this, Boolean.class, "player_attack_player", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void onBlockPlace(BlockPlaceEvent event) {
public void onCropTrample(PlayerInteractEvent event) {
if (!event.getAction().equals(Action.PHYSICAL)) return;
if (event.getClickedBlock() == null) return;
if (!event.getClickedBlock().getType().equals(Material.FARMLAND)) return;
event.setCancelled(!plugin.protectionService().canTrample(
event.getPlayer(), event.getClickedBlock().getLocation()
));
var location = event.getClickedBlock().getLocation();
event.setCancelled(event.getClickedBlock().getType().equals(Material.FARMLAND)
? !plugin.protectionService().canTrample(event.getPlayer(), location)
: !plugin.protectionService().canInteractPhysical(event.getPlayer(), location));
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public boolean canInteract(Player player, Entity entity) {
plugin.flags.entityInteract, "protect.bypass.entity-interact");
}

@Override
public boolean canInteractPhysical(Player player, Location location) {
return canPerformAction(player, plugin.areaProvider().getArea(location),
plugin.flags.physicalInteract, "protect.bypass.physical-interact");
}

@Override
public boolean canShear(Player player, Entity entity) {
return canPerformAction(player, plugin.areaProvider().getArea(entity),
Expand Down
Loading