Skip to content

Commit

Permalink
Merge pull request #120 from ToberoCat/zone-messages
Browse files Browse the repository at this point in the history
Zone messages
  • Loading branch information
ToberoCat authored May 17, 2024
2 parents 2afeafe + 5430763 commit 8ef9534
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package io.github.toberocat.improvedfactions.listeners.claim
import org.bukkit.event.EventHandler
import org.bukkit.event.player.PlayerInteractEvent

class ClaimBlockInteractListener(zoneType: String) : ProtectionListener(zoneType) {
class ClaimBlockInteractListener(zoneType: String) : ProtectionListener(
zoneType,
sendMessage = false
) {
override fun namespace(): String = "block-interaction"

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package io.github.toberocat.improvedfactions.listeners.claim
import org.bukkit.event.EventHandler
import org.bukkit.event.player.PlayerInteractEntityEvent

class ClaimEntityInteractionListener(zoneType: String) : ProtectionListener(zoneType) {
class ClaimEntityInteractionListener(zoneType: String) : ProtectionListener(
zoneType,
sendMessage = false
) {
override fun namespace(): String = "entity-interaction"

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import org.bukkit.event.Cancellable
import org.bukkit.event.Listener
import org.jetbrains.exposed.sql.transactions.transaction

abstract class ProtectionListener(protected val zoneType: String) : Listener {
abstract class ProtectionListener(protected val zoneType: String,
private val sendMessage: Boolean = true) : Listener {
private val claimClusters = ImprovedFactionsPlugin.instance.claimChunkClusters
abstract fun namespace(): String

Expand All @@ -30,7 +31,8 @@ abstract class ProtectionListener(protected val zoneType: String) : Listener {

private fun protectChunk(event: Cancellable, chunk: Chunk?, player: Player) = transaction {
val claim = chunk?.getFactionClaim()
if (claim?.zoneType != zoneType || (claim.zone()?.protectAlways == false && claim.factionId == noFactionId))
val claimZone = claim?.zone()
if (claim?.zoneType != zoneType || (claimZone?.protectAlways == false && claim.factionId == noFactionId))
return@transaction

val claimedFaction = claim.factionId
Expand All @@ -44,6 +46,13 @@ abstract class ProtectionListener(protected val zoneType: String) : Listener {
return@transaction

event.isCancelled = true
player.sendLocalized("base.claim.protected")
if (!sendMessage) {
return@transaction
}

when (claimZone?.protectAlways) {
true -> player.sendLocalized("base.zone.protected")
else -> player.sendLocalized("base.claim.protected")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,5 @@ base.command.inviteaccept.joined={prefix} <green>You've successfully joined the
base.exceptions.arg-is-no-player={prefix} <red>Error: The provided argument is not a player</red>
base.commands.bypass.remove-bypass={prefix} <green>You've successfully removed the bypass for this player</green>
base.commands.bypass.add-bypass={prefix} <green>You've successfully added the bypass for this player</green>
base.commands.bypass.description=Add or remove a bypass for a player. A bypass only stays until the next server restart
base.commands.bypass.description=Add or remove a bypass for a player. A bypass only stays until the next server restart
base.zone.protected={prefix} <red>This chunk is protected by a zone</red>

0 comments on commit 8ef9534

Please sign in to comment.