Skip to content

Commit

Permalink
Fixed flag bypasses when actions done in adjacent claims affect anoth…
Browse files Browse the repository at this point in the history
…er (#102)

This issue is present in flags such as pistons or sculk spread, where if
someone places the source block in one claim, it can have an effect in
the other claim. The existing checks only take into account changes done
outside of any claim affecting areas inside of a claim, not changes that
could be done using an adjacent claim.
  • Loading branch information
mizarc authored Oct 22, 2024
2 parents bf4cd78 + b85388e commit c794363
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 51 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
## [0.3.4]

### Fixed
- No visible inner border visualisation when set to view mode on claims that are donut shaped.
- No visible inner border visualisation when set to view mode on claims that aren't completely filled in.
- Using bell while holding an item causing the item to be used, resulting in major issues like trident duplication.
- Claim flags bypassed when an action is being done in one claim that would have an effect in another.

## [0.3.3]

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "dev.mizarc"
version = "0.3.3"
version = "0.3.4"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dev.mizarc.bellclaims.api.FlagService
import dev.mizarc.bellclaims.api.PartitionService
import dev.mizarc.bellclaims.domain.claims.Claim
import dev.mizarc.bellclaims.domain.flags.Flag
import dev.mizarc.bellclaims.domain.partitions.Position2D
import org.bukkit.Location
import org.bukkit.block.BlockState
import org.bukkit.block.data.Directional
Expand Down Expand Up @@ -432,9 +433,10 @@ class RuleBehaviour {
private fun getPistonClaims(pistonBlock: Block, blocks: List<Block>, direction: BlockFace, claimService: ClaimService,
partitionService: PartitionService): List<Claim> {
val claimList = ArrayList<Claim>()
val checks: ArrayList<Block> = ArrayList()
for (c in blocks) {
checks.add(c.getRelative(direction))
val checks = mutableSetOf<Block>()
for (block in blocks) {
checks.add(block)
checks.add(block.getRelative(direction))
}

// Check the piston head position
Expand All @@ -457,8 +459,11 @@ class RuleBehaviour {
private fun cancelFluidFlow(event: Event, claimService: ClaimService,
partitionService: PartitionService, flagService: FlagService): Boolean {
if (event !is BlockFromToEvent) return false
if (partitionService.getByLocation(event.block.location) != null) return false
if (partitionService.getByLocation(event.toBlock.location) == null) return false
val sourceClaim = partitionService.getByLocation(event.block.location)?.
let { claimService.getById(it.claimId) }
val moveClaim = partitionService.getByLocation(event.toBlock.location)?.
let { claimService.getById(it.claimId) }
if (sourceClaim == moveClaim) return false
event.isCancelled = true
return true
}
Expand All @@ -474,64 +479,62 @@ class RuleBehaviour {
private fun cancelPistonRetract(event: Event, claimService: ClaimService,
partitionService: PartitionService, flagService: FlagService): Boolean {
if (event !is BlockPistonRetractEvent) return false
if (partitionService.getByLocation(event.block.location) != null) return false
var blockInClaim = false
val pistonClaim = partitionService.getByLocation(event.block.location)?.
let { claimService.getById(it.claimId)}

// Perform checks to see if in claim, and if the claim has piston flag
for (block in event.blocks) {
if (partitionService.getByLocation(block.location) != null) blockInClaim = true
val blockClaim = partitionService.getByLocation(block.location)?.let { claimService.getById(it.claimId)}
if (blockClaim == pistonClaim) continue
if (blockClaim != null && !flagService.doesClaimHaveFlag(blockClaim, Flag.Pistons)) {
event.isCancelled = true
return true
}
}
if (!blockInClaim) return false
event.isCancelled = true
return true
return false
}

private fun cancelPistonExtend(event: Event, claimService: ClaimService,
partitionService: PartitionService, flagService: FlagService): Boolean {
if (event !is BlockPistonExtendEvent) return false
if (partitionService.getByLocation(event.block.location) != null) return false
val affectedLocations = mutableSetOf<Location>()
val direction = event.direction.direction
val pistonClaim = partitionService.getByLocation(event.block.location)?.
let { claimService.getById(it.claimId)}

// Check the position of the piston head
if (partitionService.getByLocation(event.block.location.add(direction)) != null) {
event.isCancelled = true
return true
}
// Get position of the piston head
affectedLocations.add(event.block.location.add(direction))

// Check the blocks that the piston is pushinga
var blockInClaim = false
// Get locations of all the blocks the piston will affect
for (block in event.blocks) {
val newBlockPosition = block.location.clone()
newBlockPosition.add(direction)
if (partitionService.getByLocation(block.location) != null ||
partitionService.getByLocation(newBlockPosition) != null) blockInClaim = true
affectedLocations.add(newBlockPosition)
}

if (!blockInClaim) return false
event.isCancelled = true
return true
// Perform checks to see if in claim, and if the claim has piston flag
for (location in affectedLocations) {
val blockClaim = partitionService.getByLocation(location)?.let { claimService.getById(it.claimId)}
if (blockClaim == pistonClaim) continue
if (blockClaim != null && !flagService.doesClaimHaveFlag(blockClaim, Flag.Pistons)) {
event.isCancelled = true
return true
}
}
return false
}

private fun cancelTreeGrowth(event: Event, claimService: ClaimService,
partitionService: PartitionService, flagService: FlagService): Boolean {
if (event !is StructureGrowEvent) return false
if (partitionService.getByLocation(event.location) != null) {
val partition = partitionService.getByLocation(event.location) ?: return false
val claim = claimService.getById(partition.claimId) ?: return false
for (block in event.blocks) {
if (partitionService.getByLocation(block.location) != null) {
val otherPartition = partitionService.getByLocation(block.location) ?: continue
val otherClaim = claimService.getById(otherPartition.claimId) ?: continue
if (claim.id != otherClaim.id) {
partitionService.getByLocation(block.location) ?: continue
event.isCancelled = true
return true
}
}
}
return false
}
val sourceClaim = partitionService.getByLocation(event.location) ?.
let { claimService.getById(it.claimId) }

for (block in event.blocks) {
if (partitionService.getByLocation(block.location) != null) {
val growthClaim = partitionService.getByLocation(block.location) ?.
let { claimService.getById(it.claimId) }
if (sourceClaim == growthClaim) continue
if (growthClaim != null && !flagService.doesClaimHaveFlag(growthClaim, Flag.Trees)) {
event.isCancelled = true
return true
}
Expand All @@ -558,11 +561,7 @@ class RuleBehaviour {
val partition = partitionService.getByLocation(event.block.location)
val sourcePartition = partitionService.getByLocation(event.source.location)

if (sourcePartition == partition) {
return false
}

if (sourcePartition == null) {
if (sourcePartition != partition) {
event.isCancelled = true
return true
}
Expand Down Expand Up @@ -603,12 +602,13 @@ class RuleBehaviour {
private fun cancelSpongeAbsorbEvent(event: Event, claimService: ClaimService,
partitionService: PartitionService, flagService: FlagService): Boolean {
if (event !is SpongeAbsorbEvent) return false
if (partitionService.getByLocation(event.block.location) != null) return false
val spongeClaim = partitionService.getByLocation(event.block.location)?.let { claimService.getById(it.claimId) }
val cancelledBlocks: MutableList<BlockState> = mutableListOf()
for (block in event.blocks) {
val partition = partitionService.getByLocation(block.location) ?: continue
val claim = claimService.getById(partition.claimId) ?: continue
if (!flagService.doesClaimHaveFlag(claim, Flag.Explosions)) {
if (spongeClaim == claim) continue
if (!flagService.doesClaimHaveFlag(claim, Flag.Sponge)) {
cancelledBlocks.add(block)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: BellClaims
version: 0.3.3
version: 0.3.4
api-version: '1.21'
main: dev.mizarc.bellclaims.BellClaims
softdepend: [Vault]

0 comments on commit c794363

Please # to comment.