Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MfFactionPermissions(private val plugin: MedievalFactions) {
wrapSimplePermission("CHAT_HISTORY", plugin.language["FactionPermissionChatHistory"], true),
wrapSimplePermission("CLAIM", plugin.language["FactionPermissionClaim"], false),
wrapSimplePermission("UNCLAIM", plugin.language["FactionPermissionUnclaim"], false),
wrapSimplePermission("BYPASS_LOCKS", plugin.language["FactionPermissionBypassLocks"], false),
wrapSimplePermission("DECLARE_INDEPENDENCE", plugin.language["FactionPermissionDeclareIndependence"], false),
wrapSimplePermission("SWEAR_FEALTY", plugin.language["FactionPermissionSwearFealty"], false),
wrapSimplePermission("GRANT_INDEPENDENCE", plugin.language["FactionPermissionGrantIndependence"], false),
Expand Down Expand Up @@ -90,6 +91,7 @@ class MfFactionPermissions(private val plugin: MedievalFactions) {
val chatHistory = parse("CHAT_HISTORY")!!
val claim = parse("CLAIM")!!
val unclaim = parse("UNCLAIM")!!
val bypassLocks = parse("BYPASS_LOCKS")!!
val declareIndependence = parse("DECLARE_INDEPENDENCE")!!
val swearFealty = parse("SWEAR_FEALTY")!!
val grantIndependence = parse("GRANT_INDEPENDENCE")!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ class PlayerInteractListener(private val plugin: MedievalFactions) : Listener {
}
}

/**
* Checks if a player has the faction permission to bypass locks.
* * @param mfPlayer The player to check
* @return true if the player's faction role has the BYPASS_LOCKS permission, false otherwise
* (including when the player has no faction or no role)
*/
private fun hasLockBypassPermission(mfPlayer: MfPlayer): Boolean {
val factionService = plugin.services.factionService
val playerFaction = factionService.getFaction(mfPlayer.id) ?: return false
val role = playerFaction.getRole(mfPlayer.id) ?: return false
return role.hasPermission(playerFaction, plugin.factionPermissions.bypassLocks)
}

private fun applyProtections(event: PlayerInteractEvent) {
val clickedBlock = event.clickedBlock ?: return
val playerService = plugin.services.playerService
Expand Down Expand Up @@ -124,7 +137,8 @@ class PlayerInteractListener(private val plugin: MedievalFactions) : Listener {
val lockedBlock = lockedBlocks.firstOrNull()
if (lockedBlock != null) {
if (event.player.uniqueId.toString() !in (lockedBlock.accessors + lockedBlock.playerId).map(MfPlayerId::value)) {
if (mfPlayer.isBypassEnabled && event.player.hasPermission("mf.bypass")) {
// Check if player has bypass permission from mf.bypass or faction permission
if ((mfPlayer.isBypassEnabled && event.player.hasPermission("mf.bypass")) || hasLockBypassPermission(mfPlayer)) {
plugin.server.scheduler.runTaskAsynchronously(
plugin,
Runnable {
Expand Down Expand Up @@ -252,12 +266,14 @@ class PlayerInteractListener(private val plugin: MedievalFactions) : Listener {
} else {
lockOwner.toBukkit().name ?: plugin.language["UnknownPlayer"]
}
if (!player.hasPermission("mf.force.unlock")) {

// Check if player has bypass permission from mf.force.unlock or faction permission
val canBypass = player.hasPermission("mf.force.unlock") || hasLockBypassPermission(mfPlayer)
if (!canBypass) {
player.sendMessage("$RED${plugin.language["BlockUnlockOwnedByOtherPlayer", ownerName]}")
return
} else {
player.sendMessage("$RED${plugin.language["BlockUnlockProtectionBypassed", ownerName]}")
}
player.sendMessage("$RED${plugin.language["BlockUnlockProtectionBypassed", ownerName]}")
}
lockService.unlock(block) { result ->
when (result) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/lang_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ FactionPermissionChat=Chat in {0}
FactionPermissionChatHistory=View chat history
FactionPermissionClaim=Claim
FactionPermissionUnclaim=Unclaim
FactionPermissionBypassLocks=Bypass locks
FactionPermissionDeclareIndependence=Declare independence
FactionPermissionSwearFealty=Swear fealty
FactionPermissionGrantIndependence=Grant independence
Expand Down
Loading