Kotlin cleanup

This commit is contained in:
Auxilor
2021-08-06 19:43:48 +01:00
parent 6b1dde7540
commit d45e66d71e
13 changed files with 95 additions and 100 deletions

View File

@@ -45,7 +45,7 @@
-->
<property name="severity" value="error"/>
<property name="fileExtensions" value="java, properties, xml"/>
<property name="fileExtensions" value="java, properties, xml, kt"/>
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
@@ -66,6 +66,7 @@
<module name="FileLength"/>
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="fileExtensions" value="kt"/>
<property name="max" value="200"/>
</module>

View File

@@ -57,7 +57,8 @@ abstract class EcoSpigotPlugin: EcoPlugin(
}
override fun loadIntegrationLoaders(): List<IntegrationLoader> {
return listOf( // AntiGrief
return listOf(
// AntiGrief
IntegrationLoader("WorldGuard") { AntigriefManager.register(AntigriefWorldGuard()) },
IntegrationLoader("GriefPrevention") { AntigriefManager.register(AntigriefGriefPrevention()) },
IntegrationLoader("FactionsUUID") { AntigriefManager.register(AntigriefFactionsUUID()) },
@@ -74,13 +75,19 @@ abstract class EcoSpigotPlugin: EcoPlugin(
if (pluginVersion.startsWith("11")) {
AntigriefManager.register(AntigriefCombatLogXV11())
}
}, // Anticheat
},
// Anticheat
IntegrationLoader("AAC5") { AnticheatManager.register(this, AnticheatAAC()) },
IntegrationLoader("Matrix") { AnticheatManager.register(this, AnticheatMatrix()) },
IntegrationLoader("NoCheatPlus") { AnticheatManager.register(this, AnticheatNCP()) },
IntegrationLoader("Spartan") { AnticheatManager.register(this, AnticheatSpartan()) },
IntegrationLoader("Vulcan") { AnticheatManager.register(this, AnticheatVulcan()) }, // Custom Items
IntegrationLoader("Oraxen") { CustomItemsManager.register(CustomItemsOraxen()) }, // Misc
IntegrationLoader("Vulcan") { AnticheatManager.register(this, AnticheatVulcan()) },
// Custom Items
IntegrationLoader("Oraxen") { CustomItemsManager.register(CustomItemsOraxen()) },
// Misc
IntegrationLoader("mcMMO") { McmmoManager.register(McmmoIntegrationImpl()) }
)
}

View File

@@ -13,18 +13,18 @@ import java.util.concurrent.atomic.AtomicReference
class EntityDeathByEntityListeners(
plugin: EcoPlugin
) : PluginDependent<EcoPlugin>(plugin), Listener {
private val events = HashSet<EntityDeathByEntityBuilder>();
private val events = HashSet<EntityDeathByEntityBuilder>()
@EventHandler(priority = EventPriority.HIGH)
fun onEntityDamage(event: EntityDamageByEntityEvent) {
if ((event.entity !is LivingEntity)) {
return;
return
}
val victim = event.entity as LivingEntity
if (victim.health > event.finalDamage) {
return;
return
}
val builtEvent = EntityDeathByEntityBuilder()
@@ -51,15 +51,15 @@ class EntityDeathByEntityListeners(
}
if (atomicBuiltEvent.get() == null) {
return;
return
}
val builtEvent = atomicBuiltEvent.get();
events.remove(builtEvent);
val builtEvent = atomicBuiltEvent.get()
events.remove(builtEvent)
builtEvent.drops = drops
builtEvent.xp = xp
builtEvent.deathEvent = event
builtEvent.push();
builtEvent.push()
}
}

View File

@@ -7,7 +7,7 @@ import org.bukkit.Location
import org.bukkit.event.player.PlayerExpChangeEvent
internal class NaturalExpGainBuilder(var reason: BuildReason) {
var cancelled = false
private var cancelled = false
var event: PlayerExpChangeEvent? = null
var location: Location? = null

View File

@@ -27,7 +27,7 @@ class PlayerJumpListeners : Listener {
jumpVelocity = FORMAT.format(jumpVelocity.toDouble()).replace(',', '.').toFloat()
if (event.player.location.block.type != Material.LADDER && PREVIOUS_PLAYERS_ON_GROUND.contains(player.uniqueId)
&& !player.isOnGround
&& java.lang.Float.compare(player.velocity.y.toFloat(), jumpVelocity) == 0
&& player.velocity.y.toFloat().compareTo(jumpVelocity) == 0
) {
Bukkit.getPluginManager().callEvent(PlayerJumpEvent(event))
}

View File

@@ -6,15 +6,10 @@ import me.konsolas.aac.api.AACExemption
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.event.Listener
import java.util.*
class AnticheatAAC : AnticheatWrapper, Listener {
private val ecoExemption = AACExemption("eco")
private val api = Objects.requireNonNull(
Bukkit.getServicesManager().load(
AACAPI::class.java
)
)!!
private val api = Bukkit.getServicesManager().load(AACAPI::class.java)!!
override fun getPluginName(): String {
return "AAC"

View File

@@ -12,7 +12,8 @@ import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
class AntigriefCombatLogXV10 : AntigriefWrapper {
private val instance: ICombatLogX?
private val instance: ICombatLogX = Bukkit.getPluginManager().getPlugin("CombatLogX") as ICombatLogX
override fun canBreakBlock(
player: Player,
block: Block
@@ -43,12 +44,12 @@ class AntigriefCombatLogXV10 : AntigriefWrapper {
}
// Only run checks if the NewbieHelper expansion is installed on the server.
val expansionManager = instance!!.expansionManager
val expansionManager = instance.expansionManager
val optionalExpansion = expansionManager.getExpansionByName<Expansion>("NewbieHelper")
if (optionalExpansion.isPresent) {
val expansion = optionalExpansion.get()
val newbieHelper: NewbieHelper = expansion as NewbieHelper
val pvpListener: ListenerPVP = newbieHelper.getPVPListener()
val pvpListener: ListenerPVP = newbieHelper.pvpListener
return pvpListener.isPVPEnabled(player) && pvpListener.isPVPEnabled(victim)
}
return true
@@ -58,7 +59,4 @@ class AntigriefCombatLogXV10 : AntigriefWrapper {
return "CombatLogX"
}
init {
instance = Bukkit.getPluginManager().getPlugin("CombatLogX") as ICombatLogX?
}
}

View File

@@ -12,7 +12,7 @@ import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
class AntigriefCombatLogXV11 : AntigriefWrapper {
private val instance: ICombatLogX?
private val instance: ICombatLogX = Bukkit.getPluginManager().getPlugin("CombatLogX") as ICombatLogX
override fun canBreakBlock(
player: Player,
block: Block
@@ -43,16 +43,15 @@ class AntigriefCombatLogXV11 : AntigriefWrapper {
}
// Only run checks if the NewbieHelper expansion is installed on the server.
val expansionManager = instance!!.expansionManager
val expansionManager = instance.expansionManager
val optionalExpansion = expansionManager.getExpansion("NewbieHelper")
if (optionalExpansion.isPresent) {
val expansion = optionalExpansion.get()
val newbieHelperExpansion: NewbieHelperExpansion = expansion as NewbieHelperExpansion
val protectionManager: ProtectionManager = newbieHelperExpansion.getProtectionManager()
val pvpManager: PVPManager = newbieHelperExpansion.getPVPManager()
val victimPlayer = victim
val victimProtected: Boolean = protectionManager.isProtected(victimPlayer)
val victimDisabledPvP: Boolean = pvpManager.isDisabled(victimPlayer)
val protectionManager: ProtectionManager = newbieHelperExpansion.protectionManager
val pvpManager: PVPManager = newbieHelperExpansion.pvpManager
val victimProtected: Boolean = protectionManager.isProtected(victim)
val victimDisabledPvP: Boolean = pvpManager.isDisabled(victim)
val playerDisabledPvp: Boolean = pvpManager.isDisabled(player)
return !victimProtected && !victimDisabledPvP && !playerDisabledPvp
}
@@ -63,7 +62,4 @@ class AntigriefCombatLogXV11 : AntigriefWrapper {
return "CombatLogX"
}
init {
instance = Bukkit.getPluginManager().getPlugin("CombatLogX") as ICombatLogX?
}
}

View File

@@ -17,7 +17,7 @@ class AntigriefFactionsUUID : AntigriefWrapper {
val flocation = FLocation(block.location)
val faction: Faction = Board.getInstance().getFactionAt(flocation)
return if (!faction.hasAccess(fplayer, PermissibleAction.DESTROY)) {
fplayer.isAdminBypassing()
fplayer.isAdminBypassing
} else true
}
@@ -38,7 +38,7 @@ class AntigriefFactionsUUID : AntigriefWrapper {
val flocation = FLocation(block.location)
val faction: Faction = Board.getInstance().getFactionAt(flocation)
return if (!faction.hasAccess(fplayer, PermissibleAction.BUILD)) {
fplayer.isAdminBypassing()
fplayer.isAdminBypassing
} else true
}
@@ -50,12 +50,12 @@ class AntigriefFactionsUUID : AntigriefWrapper {
val flocation = FLocation(victim.location)
val faction: Faction = Board.getInstance().getFactionAt(flocation)
if (victim is Player) {
if (faction.isPeaceful()) {
return fplayer.isAdminBypassing()
if (faction.isPeaceful) {
return fplayer.isAdminBypassing
}
} else {
if (faction.hasAccess(fplayer, PermissibleAction.DESTROY)) {
return fplayer.isAdminBypassing()
return fplayer.isAdminBypassing
}
}
return true

View File

@@ -13,7 +13,7 @@ class AntigriefGriefPrevention : AntigriefWrapper {
player: Player,
block: Block
): Boolean {
val claim: Claim = GriefPrevention.instance.dataStore.getClaimAt(block.location, false, null)
val claim: Claim? = GriefPrevention.instance.dataStore.getClaimAt(block.location, false, null)
return if (claim != null) {
claim.allowBreak(player, block.type) == null
} else true
@@ -23,17 +23,15 @@ class AntigriefGriefPrevention : AntigriefWrapper {
player: Player,
location: Location
): Boolean {
val claim: Claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null)
return if (claim != null) {
claim.areExplosivesAllowed
} else true
val claim: Claim? = GriefPrevention.instance.dataStore.getClaimAt(location, false, null)
return claim?.areExplosivesAllowed ?: true
}
override fun canPlaceBlock(
player: Player,
block: Block
): Boolean {
val claim: Claim = GriefPrevention.instance.dataStore.getClaimAt(block.location, false, null)
val claim: Claim? = GriefPrevention.instance.dataStore.getClaimAt(block.location, false, null)
return if (claim != null) {
claim.allowBuild(player, block.type) == null
} else true
@@ -43,11 +41,11 @@ class AntigriefGriefPrevention : AntigriefWrapper {
player: Player,
victim: LivingEntity
): Boolean {
val claim: Claim = GriefPrevention.instance.dataStore.getClaimAt(victim.location, false, null)
val claim: Claim? = GriefPrevention.instance.dataStore.getClaimAt(victim.location, false, null)
return if (victim is Player) {
claim == null
} else {
if (claim != null && claim.ownerID != null) {
if (claim?.ownerID != null) {
claim.ownerID == player.uniqueId
} else true
}

View File

@@ -18,10 +18,10 @@ class AntigriefKingdoms : AntigriefWrapper {
block: Block
): Boolean {
val kp: KingdomPlayer = KingdomPlayer.getKingdomPlayer(player)
if (kp.isAdmin()) {
if (kp.isAdmin) {
return true
}
val kingdom: Kingdom = kp.getKingdom() ?: return false
val kingdom: Kingdom = kp.kingdom ?: return false
val land = Land.getLand(block) ?: return true
val permission: DefaultKingdomPermission =
if (land.isNexusLand) DefaultKingdomPermission.NEXUS_BUILD else DefaultKingdomPermission.BUILD

View File

@@ -18,7 +18,7 @@ class AntigriefTowny : AntigriefWrapper {
player: Player,
block: Block
): Boolean {
val world = TownyUniverse.getInstance().worldMap[block.location.world!!.name] ?: return true
TownyUniverse.getInstance().worldMap[block.location.world!!.name] ?: return true
return if (TownyAPI.getInstance().isWilderness(block)) {
true
} else PlayerCacheUtil.getCachePermission(
@@ -39,7 +39,7 @@ class AntigriefTowny : AntigriefWrapper {
player: Player,
location: Location
): Boolean {
val world = TownyUniverse.getInstance().worldMap[location.world!!.name] ?: return true
TownyUniverse.getInstance().worldMap[location.world?.name] ?: return true
return if (TownyAPI.getInstance().isWilderness(location)) {
true
} else PlayerCacheUtil.getCachePermission(player, location, Material.TNT, TownyPermission.ActionType.ITEM_USE)
@@ -49,7 +49,7 @@ class AntigriefTowny : AntigriefWrapper {
player: Player,
block: Block
): Boolean {
val world = TownyUniverse.getInstance().worldMap[block.location.world!!.name] ?: return true
TownyUniverse.getInstance().worldMap[block.location.world?.name] ?: return true
return if (TownyAPI.getInstance().isWilderness(block)) {
true
} else PlayerCacheUtil.getCachePermission(player, block.location, block.type, TownyPermission.ActionType.BUILD)
@@ -59,7 +59,7 @@ class AntigriefTowny : AntigriefWrapper {
player: Player,
victim: LivingEntity
): Boolean {
val world = TownyUniverse.getInstance().worldMap[victim.location.world!!.name] ?: return true
val world = TownyUniverse.getInstance().worldMap[victim.location.world?.name] ?: return true
if (TownyAPI.getInstance().isWilderness(victim.location)) {
return if (victim is Player) {
world.isPVP
@@ -69,14 +69,14 @@ class AntigriefTowny : AntigriefWrapper {
}
if (victim is Player) {
try {
val town: Town = WorldCoord.parseWorldCoord(victim.getLocation()).getTownBlock().getTown()
return town.isPVP()
val town: Town = WorldCoord.parseWorldCoord(victim.getLocation()).townBlock.town
return town.isPVP
} catch (ignored: Exception) {
// If exception, no town was found, thus return true.
}
} else {
try {
val town: Town = WorldCoord.parseWorldCoord(victim.location).getTownBlock().getTown()
val town: Town = WorldCoord.parseWorldCoord(victim.location).townBlock.town
return town.hasMobs()
} catch (ignored: Exception) {
// If exception, no town was found, thus return true.

View File

@@ -13,9 +13,9 @@ class CustomItemsOraxen : CustomItemsWrapper {
for (item in OraxenItems.getItems()) {
val stack = item.build()
val id: String = OraxenItems.getIdByItem(item)
val key: NamespacedKey = NamespacedKeyUtils.create("oraxen", id.toLowerCase())
val key: NamespacedKey = NamespacedKeyUtils.create("oraxen", id.lowercase())
CustomItem(
key, Predicate { test: ItemStack? ->
key, Predicate { test: ItemStack ->
val oraxenId: String = OraxenItems.getIdByItem(test) ?: return@Predicate false
oraxenId.equals(id, ignoreCase = true)
},