Skip to content

Commit

Permalink
Fixed code quality issue and added code quality badge
Browse files Browse the repository at this point in the history
  • Loading branch information
ToberoCat committed May 18, 2024
1 parent 3fa2d6b commit 85bd761
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![GitHub release](https://img.shields.io/github/release/ToberoCat/ImprovedFactions_new?include_prereleases=&sort=semver&color=%23FEDD58)](https://github.com/ToberoCat/ImprovedFactions_new/releases/)
[![issues - ImprovedFactions](https://img.shields.io/github/issues/ToberoCat/ImprovedFactions_new)](https://github.com/ToberoCat/ImprovedFactions_new/issues)
[![SpigotMain - ImprovedFactions](https://img.shields.io/badge/Spigot-ImprovedFactions-orange)](https://www.spigotmc.org/resources/improved-factions.95617 "Spigot ImprovedFactions page")
[![CodeFactor](https://www.codefactor.io/repository/github/toberocat/improvedfactions/badge)](https://www.codefactor.io/repository/github/toberocat/improvedfactions)
<a href="https://www.paypal.com/donate/?hosted_button_id=BGB6QWR886Q6Y">
<img src="https://img.shields.io/badge/Donate-PayPal-green.svg?logo=paypal&style=flat-square" height="20" alt="Donate">
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CommandActionMapper(private val label: String, private val command: Player
override fun run(player: Player) {
async {
val arguments = command.args.map {
(Promise { resolve ->
Promise { resolve ->
player.sendLocalized(
"base.action.required-argument", mapOf(
"usage" to it.usage(),
Expand Down Expand Up @@ -49,7 +49,7 @@ class CommandActionMapper(private val label: String, private val command: Player
resolve.accept(text)
return@Function ChatInput.Action.SUCCESS
})
}).result()
}.result()
}.toMutableList()

arguments.add(0, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class FactionMap(private val plugin: ImprovedFactionsPlugin) : PlayerSubCommand(
}
}

private fun getCombined(x: Int, z: Int) = (x.toLong() shl 32) or (z.toLong() and 0xFFFFFFFFL)
private fun getCombined(x: Int, z: Int) = x.toLong() shl 32 or (z.toLong() and 0xFFFFFFFFL)

companion object {
var MAP_WIDTH = 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class ClaimEntityBreakHangingListener(zoneType: String) : ProtectionListener(zon

@EventHandler
fun hangingBreak(event: HangingBreakByEntityEvent) {
protectChunk(event, event.entity, (event.remover as? Player) ?: return)
protectChunk(event, event.entity, event.remover as? Player ?: return)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class ClaimEntityDamagePlayerListener<T : Entity>(private val name: String, priv
@EventHandler
fun entityDamage(event: EntityDamageByEntityEvent) {
if (!clazz.isInstance(event.damager)) return
protectChunk(event, event.entity, (event.entity as? Player) ?: return)
protectChunk(event, event.entity, event.entity as? Player ?: return)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class ClaimPlayerDamageEntityListener<T : Entity>(private val name: String, priv
@EventHandler
fun entityDamage(event: EntityDamageByEntityEvent) {
if (!clazz.isInstance(event.entity)) return
protectChunk(event, event.entity, (event.damager as? Player) ?: return)
protectChunk(event, event.entity, event.damager as? Player ?: return)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class ClaimVehicleBreakListener(zoneType: String) : ProtectionListener(zoneType)
fun vehicleBreak(event: VehicleDamageEvent) {
if (event.vehicle !is Minecart)
return
protectChunk(event, event.vehicle, (event.attacker as? Player) ?: return)
protectChunk(event, event.vehicle, event.attacker as? Player ?: return)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class ProtectionListener(protected val zoneType: String,
private fun protectChunk(event: Cancellable, chunk: Chunk?, player: Player) = loggedTransaction {
val claim = chunk?.getFactionClaim()
val claimZone = claim?.zone()
if (claim?.zoneType != zoneType || (claimZone?.protectAlways == false && claim.factionId == noFactionId))
if (claim?.zoneType != zoneType || claimZone?.protectAlways == false && claim.factionId == noFactionId)
return@loggedTransaction

val claimedFaction = claim.factionId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class TerritoryTitle(private val pluginConfig: ImprovedFactionsConfig) : Listene
val toFaction = toClaim?.faction()
val fromFaction = fromClaim?.factionId ?: noFactionId

val fromZoneType = fromClaim?.zoneType
(toFaction?.id?.value ?: noFactionId) == fromFaction && (toZone?.type
?: ZoneHandler.FACTION_ZONE_TYPE) == (fromZoneType ?: ZoneHandler.FACTION_ZONE_TYPE)
val fromZoneType = fromClaim?.zoneType ?: ZoneHandler.FACTION_ZONE_TYPE
val toZoneType = toZone?.type ?: ZoneHandler.FACTION_ZONE_TYPE
return (toFaction?.id?.value ?: noFactionId) == fromFaction && toZoneType == fromZoneType

Check warning on line 50 in improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/listeners/move/TerritoryTitle.kt

View check run for this annotation

codefactor.io / CodeFactor

improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/listeners/move/TerritoryTitle.kt#L50

Parentheses in (toFaction?.id?.value ?: noFactionId) are unnecessary and can be replaced with: toFaction?.id?.value ?: noFactionId (detekt.UnnecessaryParentheses)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DynmapModule : BaseModule {
companion object {
const val MODULE_NAME = "dynmap"
fun dynmapModule() =
(ImprovedFactionsPlugin.modules[MODULE_NAME] as? DynmapModule) ?: throw IllegalStateException()
ImprovedFactionsPlugin.modules[MODULE_NAME] as? DynmapModule ?: throw IllegalStateException()

fun dynmapPair() = MODULE_NAME to DynmapModule()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object HomeModule : BaseModule {
const val MODULE_NAME = "home"
override val moduleName = MODULE_NAME

var homeModuleHandle: HomeModuleHandle = DummyHomeModuleHandle()
private var homeModuleHandle: HomeModuleHandle = DummyHomeModuleHandle()

override fun onEnable(plugin: ImprovedFactionsPlugin) {
homeModuleHandle = HomeModuleHandleImpl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PowerRaidsModule : BaseModule {
companion object {
const val MODULE_NAME = "power-raids"
fun powerRaidModule() =
(ImprovedFactionsPlugin.modules[MODULE_NAME] as? PowerRaidsModule) ?: throw IllegalStateException()
ImprovedFactionsPlugin.modules[MODULE_NAME] as? PowerRaidsModule ?: throw IllegalStateException()
fun powerRaidsPair() = MODULE_NAME to PowerRaidsModule()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class WildernessModule : BaseModule {

companion object {
const val MODULE_NAME = "wilderness"
fun wildernessModule() =
(ImprovedFactionsPlugin.modules[MODULE_NAME] as? WildernessModule) ?: throw IllegalStateException()

fun wildernessPair() = MODULE_NAME to WildernessModule()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PlayerTeleporter(

override fun run() {
val current = System.currentTimeMillis()
if ((current - startTime) >= standStillMs) {
if (current - startTime >= standStillMs) {
onTeleport()
cancel()
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IsFactionOwnerOption : PlayerOption {
}

override fun show(sender: CommandSender, args: Array<out String>): Boolean {
val player = (sender as? Player) ?: return false
val player = sender as? Player ?: return false
return player.uniqueId == loggedTransaction { player.factionUser().faction()?.owner }
}
}

0 comments on commit 85bd761

Please sign in to comment.