From 5b2a9158d677cc0d89d902f3a1e96e33ac528774 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Fri, 21 Jun 2024 16:21:28 -0500 Subject: [PATCH] v4.0.5 b29 * small code tweaks --- gradle.properties | 2 +- .../customdrops/CustomDropsHandler.kt | 156 ++++++------------ .../customdrops/CustomDropsParser.kt | 67 ++------ .../levelledmobs/customdrops/GroupLimits.kt | 5 +- .../levelledmobs/customdrops/LMItemsParser.kt | 5 +- .../listeners/EntityDeathListener.kt | 6 +- .../listeners/EntitySpawnListener.kt | 7 +- .../listeners/PlayerPortalEventListener.kt | 6 +- .../levelledmobs/managers/LevelManager.kt | 45 +---- .../levelledmobs/managers/MobDataManager.kt | 10 +- .../levelledmobs/misc/FileMigrator.kt | 5 +- .../levelledmobs/nametag/MiscUtils.kt | 19 ++- .../levelledmobs/nametag/ServerVersionInfo.kt | 5 +- .../levelledmobs/rules/LevelTierMatching.kt | 18 +- .../levelledmobs/rules/RulesParser.kt | 5 +- .../strategies/PlayerLevellingStrategy.kt | 31 +--- .../wrappers/LivingEntityWrapper.kt | 11 +- 17 files changed, 103 insertions(+), 300 deletions(-) diff --git a/gradle.properties b/gradle.properties index 796d68f03..d7676ef55 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 4.0.5 b28 +version = 4.0.5 b29 description = The Ultimate RPG Mob Levelling Solution \ No newline at end of file diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsHandler.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsHandler.kt index 66d192ea9..6f2a39860 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsHandler.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsHandler.kt @@ -226,13 +226,10 @@ class CustomDropsHandler { "&7${lmEntity.typeName} (${lmEntity.getMobLevel}) - didn't make overall chance" ) } else { + val mobKiller = if (processingInfo.mobKiller == null) "(null)" else processingInfo.mobKiller!!.name processingInfo.addDebugMessage( - DebugType.CUSTOM_DROPS, String.format( - "lvl: %s, didn't make overall chance permission for player: &b%s &r", - lmEntity.getMobLevel, - if (processingInfo.mobKiller == null) "(null)" - else processingInfo.mobKiller!!.name - ) + DebugType.CUSTOM_DROPS, + "lvl: ${lmEntity.getMobLevel}, didn't make overall chance permission for player: &b$mobKiller&r" ) } processingInfo.writeAnyDebugMessages() @@ -541,20 +538,14 @@ class CustomDropsHandler { else dropBase.itemStack!! info.addDebugMessage( - String.format( - "&8- &7level: &b%s&7, fromSpawner: &b%s&7, item: &b%s&7, minL: &b%s&7, maxL: &b%s&7, nospawner: &b%s&7, dropped: &bfalse", - info.lmEntity?.getMobLevel, info.isSpawner, itemStack.type.name, - dropBase.minLevel, dropBase.maxLevel, dropBase.noSpawner - ) + "&8- &7level: &b${info.lmEntity?.getMobLevel}&7, fromSpawner: &b${info.isSpawner}&7, item: &b${itemStack.type.name}&7, " + + "minL: &b${dropBase.minLevel}&7, maxL: &b${dropBase.maxLevel}}&7, nospawner: &b${dropBase.noSpawner}&7, dropped: &bfalse" ) } } else if (dropBase is CustomCommand) { info.addDebugMessage( - DebugType.CUSTOM_DROPS, String.format( - "&8- custom-cmd: &7level: &b%s&7, fromSpawner: &b%s&7, minL: &b%s&7, maxL: &b%s&7, nospawner: &b%s&7, executed: &bfalse", - info.lmEntity?.getMobLevel, info.isSpawner, dropBase.minLevel, - dropBase.maxLevel, dropBase.noSpawner - ) + "&8- custom-cmd: &7level: &b${info.lmEntity?.getMobLevel}&7, fromSpawner: &b${info.isSpawner}&7, minL: &b${dropBase.minLevel}&7, " + + "maxL: &b${dropBase.maxLevel}&7, nospawner: &b${dropBase.noSpawner}&7, executed: &bfalse" ) } return @@ -589,18 +580,14 @@ class CustomDropsHandler { ) { if (dropBase is CustomDropItem) { info.addDebugMessage( - DebugType.CUSTOM_DROPS, String.format( - "&8- &7level: &b%s&7, item: &b%s&7, gId: &b%s&7, chunk kill count reached", - info.lmEntity?.getMobLevel, - dropBase.material.name, dropBase.groupId - ) + DebugType.CUSTOM_DROPS, + "&8- &7level: &b${info.lmEntity?.getMobLevel}&7, item: &b${dropBase.material.name}&7, " + + "gId: &b${dropBase.groupId}&7, chunk kill count reached" ) } else { info.addDebugMessage( - DebugType.CUSTOM_DROPS, String.format( - "&8- &7level: &b%s&7, item: custom command, gId: &b%s&7, chunk kill count reached", - info.lmEntity?.getMobLevel, dropBase.groupId - ) + DebugType.CUSTOM_DROPS, + "&8- &7level: &b${info.lmEntity?.getMobLevel}&7, item: custom command, gId: &b${dropBase.groupId}&7, chunk kill count reached" ) } @@ -624,18 +611,15 @@ class CustomDropsHandler { else dropBase.itemStack!! info.addDebugMessage( - DebugType.CUSTOM_DROPS, String.format( - "&8 - &7item: &b%s&7, amount: &b%s&7, chance: &b%s&7, chanceRole: &b%s&7, dropped: &bfalse&7.", - itemStack.type.name, dropBase.amountAsString, dropBase.chance?.showMatchedChance(), - Utils.round(chanceRole.toDouble(), 4) - ) + DebugType.CUSTOM_DROPS, + "&8 - &7item: &b${itemStack.type.name}&7, amount: &b${dropBase.amountAsString}&7, chance: &b${dropBase.chance?.showMatchedChance()}&7, " + + "chanceRole: &b${Utils.round(chanceRole.toDouble(), 4)}&7, dropped: &bfalse&7." ) } else { info.addDebugMessage( - DebugType.CUSTOM_DROPS, String.format( - "&8 - &7Custom command&7, chance: &b%s&7, chanceRole: &b%s&7, executed: &bfalse&7.", - dropBase.chance?.showMatchedChance(), Utils.round(chanceRole.toDouble(), 4) - ) + DebugType.CUSTOM_DROPS, + "&8 - &7Custom command&7, chance: &b${dropBase.chance?.showMatchedChance()}&7, chanceRole:" + + " &b${Utils.round(chanceRole.toDouble(), 4)}&7, executed: &bfalse&7." ) } } @@ -661,22 +645,13 @@ class CustomDropsHandler { if (main.debugManager.isDebugTypeEnabled(DebugType.CUSTOM_DROPS)) { if (dropBase is CustomDropItem) { info.addDebugMessage( - String.format( - "&8- &7level: &b%s&7, item: &b%s&7, gId: &b%s&7, maxDropGroup: &b%s&7, groupDropCount: &b%s&7, dropped: &bfalse", - info.lmEntity?.getMobLevel, - dropBase.material.name, dropBase.groupId, - info.getItemsDropsByGroup(dropBase), groupDroppedCount - ) + "&8- &7level: &b${info.lmEntity?.getMobLevel}&7, item: &b${dropBase.material.name}&7, gId: &b${dropBase.groupId}&7, " + + "maxDropGroup: &b${info.getItemsDropsByGroup(dropBase)}&7, groupDropCount: &b$groupDroppedCount&7, dropped: &bfalse" ) } else { info.addDebugMessage( - String.format( - "&8- &7level: &b%s&7, item: custom command, gId: &b%s&7, maxDropGroup: &b%s&7, groupDropCount: &b%s&7, executed: &bfalse", - info.lmEntity?.getMobLevel, - info.getItemsDropsByGroup(dropBase), - dropBase.maxDropGroup, - groupDroppedCount - ) + "&8- &7level: &b${info.lmEntity?.getMobLevel}&7, item: custom command, gId: &b${info.getItemsDropsByGroup(dropBase)}&7, " + + "maxDropGroup: &b${dropBase.maxDropGroup}&7, groupDropCount: &b$groupDroppedCount&7, executed: &bfalse" ) } } @@ -691,20 +666,16 @@ class CustomDropsHandler { if (dropBase.hasGroupId) { if (main.debugManager.isDebugTypeEnabled(DebugType.CUSTOM_DROPS)) { val count = info.getItemsDropsByGroup(dropBase) - var msg = String.format( - "&8- &7level: &b%s&7, item: command, gId: &b%s&7, maxDropGroup: &b%s&7, groupDropCount: &b%s&7, executed: &btrue", - info.lmEntity?.getMobLevel, dropBase.groupId, dropBase.maxDropGroup, count - ) + var msg = "&8- &7level: &b${info.lmEntity?.getMobLevel}&7, item: command, gId: &b${dropBase.groupId}&7, maxDropGroup: &b${dropBase.maxDropGroup}&7, " + + "groupDropCount: &b$count&7, executed: &btrue" if (info.retryNumber > 0) { msg += ", retry: ${info.retryNumber}" } info.addDebugMessage(msg) } } else if (main.debugManager.isDebugTypeEnabled(DebugType.CUSTOM_DROPS)) { - var msg = String.format( - "&8- &7level: &b%s&7, item: custom command, gId: &b%s&7, maxDropGroup: &b%s&7, executed: &btrue", - info.lmEntity?.getMobLevel, dropBase.groupId, dropBase.maxDropGroup - ) + var msg = + "&8- &7level: &b${info.lmEntity?.getMobLevel}&7, item: custom command, gId: &b${dropBase.groupId}&7, maxDropGroup: &b${dropBase.maxDropGroup}&7, executed: &btrue" if (info.retryNumber > 0) { msg += ", retry: ${info.retryNumber}" @@ -785,21 +756,16 @@ class CustomDropsHandler { val equippedChance = if (dropBase.equippedChance != null) dropBase.equippedChance!!.showMatchedChance() else "0.0" info.addDebugMessage( - String.format( - "&8 - &7item: &b%s&7, equipChance: &b%s&7, chanceRole: &b%s&7, equipped: &btrue&7.", - newItem.type.name, equippedChance, - Utils.round(info.equippedChanceRole.toDouble(), 4) - ) + "&8 - &7item: &b${newItem.type.name}&7, equipChance: &b$equippedChance&7, chanceRole: " + + "&b${Utils.round(info.equippedChanceRole.toDouble(), 4)}&7, equipped: &btrue&7." ) } else if (!info.equippedOnly && main.debugManager.isDebugTypeEnabled(DebugType.CUSTOM_DROPS)) { val retryMsg = if (info.retryNumber > 0) ", retry: " + info.retryNumber else "" info.addDebugMessage( - String.format( - "&8 - &7item: &b%s&7, amount: &b%s&7, newAmount: &b%s&7, chance: &b%s&7, chanceRole: &b%s&7, dropped: &btrue&7%s.", - newItem.type.name, dropBase.amountAsString, newDropAmount, - dropBase.chance?.showMatchedChance(), Utils.round(chanceRole.toDouble(), 4), retryMsg - ) + "&8 - &7item: &b${newItem.type.name}&7, amount: &b${dropBase.amountAsString}&7, newAmount: &b$newDropAmount&7, " + + "chance: &b{dropBase.chance?.showMatchedChance()}&7, chanceRole: " + + "&b${Utils.round(chanceRole.toDouble(), 4)}&7, dropped: &btrue&7$retryMsg." ) } @@ -890,12 +856,9 @@ class CustomDropsHandler { if (equippedChance <= 0.0f || 1.0f - info.equippedChanceRole >= equippedChance) { if (LevelledMobs.instance.debugManager.isDebugTypeEnabled(DebugType.CUSTOM_EQUIPS)) { info.addDebugMessage( - String.format( - "&7level: &b%s&7, item: &b%s&7, equipchance: &b%s&7, chancerole: &b%s&7, did not make equipped chance", - info.lmEntity?.getMobLevel, - dropItem.material.name, dropItem.equippedChance?.showMatchedChance(), - Utils.round(info.equippedChanceRole.toDouble(), 4) - ) + "&7level: &b${info.lmEntity?.getMobLevel}&7, item: &b${dropItem.material.name}&7, equipchance: " + + "&b${dropItem.equippedChance?.showMatchedChance()}&7, chancerole: " + + "&b${Utils.round(info.equippedChanceRole.toDouble(), 4)}&7, did not make equipped chance" ) } return false @@ -1048,10 +1011,8 @@ class CustomDropsHandler { if (LevelledMobs.instance.debugManager.isDebugTypeEnabled(DebugType.CUSTOM_DROPS)) { val itemName = if (dropBase is CustomDropItem) dropBase.material.name else "(command)" info.addDebugMessage( - String.format( - "&8 - &7item: &b%s&7, death-cause: &b%s&7, death-cause-req: &b%s&7, dropped: &bfalse&7.", - itemName, info.deathCause, dropBase.causeOfDeathReqs - ) + "&8 - &7item: &b$itemName&7, death-cause: &b${info.deathCause}&7, death-cause-req: " + + "&b${dropBase.causeOfDeathReqs}&7, dropped: &bfalse&7." ) } @@ -1092,13 +1053,10 @@ class CustomDropsHandler { if (!hadPermission) { if (main.debugManager.isDebugTypeEnabled(DebugType.CUSTOM_DROPS)) { + val msg = if ((dropBase is CustomDropItem)) dropBase.itemStack?.type?.name + else "custom command" info.addDebugMessage( - String.format( - "&8 - &7item: &b%s&7, player: &b%s&7 didn't have permission: &b%s&7", - if ((dropBase is CustomDropItem)) dropBase.itemStack?.type?.name - else "custom command", - info.mobKiller?.name, dropBase.permissions - ) + "&8 - &7item: &b$msg&7, player: &b${info.mobKiller?.name}&7 didn't have permission: &b${dropBase.permissions}&7" ) } return false @@ -1185,18 +1143,11 @@ class CustomDropsHandler { if (main.debugManager.isDebugTypeEnabled(DebugType.CUSTOM_DROPS)) { if (dropBase is CustomDropItem) { info.addDebugMessage( - String.format( - "&8 - &7Mob: &b%s&7, item: %s, PAPI val: %s, matched: %s", - info.lmEntity?.typeName, dropBase.material, - papiResult, resultStr - ) + "&8 - &7Mob: &b${info.lmEntity?.typeName}&7, item: ${dropBase.material}, PAPI val: $papiResult, matched: $resultStr" ) } else { info.addDebugMessage( - String.format( - "&8 - &7Mob: &b%s&7, (customCommand), PAPI val: %s, matched: %s", - info.lmEntity?.typeName, papiResult, resultStr - ) + "&8 - &7Mob: &b${info.lmEntity?.typeName}&7, (customCommand), PAPI val: $, matched: $resultStr" ) } } @@ -1208,18 +1159,11 @@ class CustomDropsHandler { if (main.debugManager.isDebugTypeEnabled(DebugType.CUSTOM_DROPS)) { if (dropBase is CustomDropItem) { info.addDebugMessage( - String.format( - "&8 - &7Mob: &b%s&7, item: %s, PAPI val: %s, no matches found", - info.lmEntity?.typeName, dropBase.material, - papiResult - ) + "&8 - &7Mob: &b${info.lmEntity?.typeName}&7, item: ${dropBase.material}, PAPI val: $papiResult, no matches found" ) } else { info.addDebugMessage( - String.format( - "&8 - &7Mob: &b%s&7, (customCommand), PAPI val: %s, no matches found", - info.lmEntity?.typeName, papiResult - ) + "&8 - &7Mob: &b${info.lmEntity?.typeName}&7, (customCommand), PAPI val: $papiResult, no matches found", ) } } @@ -1249,19 +1193,13 @@ class CustomDropsHandler { if (main.debugManager.isDebugTypeEnabled(DebugType.CUSTOM_DROPS)) { if (dropBase is CustomDropItem) { info.addDebugMessage( - String.format( - "&8 - &7Mob: &b%s&7, item: %s, lvl-src: %s, minlvl: %s, maxlvl: %s player level criteria not met", - info.lmEntity?.typeName, dropBase.material, - levelToUse, dropBase.minPlayerLevel, dropBase.maxPlayerLevel - ) + "&8 - &7Mob: &b${info.lmEntity?.typeName}&7, item: ${dropBase.material}, lvl-src: $levelToUse, " + + "minlvl: ${dropBase.minPlayerLevel}, maxlvl: ${dropBase.maxPlayerLevel} player level criteria not met", ) } else { info.addDebugMessage( - String.format( - "&8 - &7Mob: &b%s&7, (customCommand), lvl-src: %s, minlvl: %s, maxlvl: %s player level criteria not met", - info.lmEntity?.typeName, levelToUse, dropBase.minPlayerLevel, - dropBase.maxPlayerLevel - ) + "&8 - &7Mob: &b${info.lmEntity?.typeName}&7, (customCommand), lvl-src: $levelToUse, minlvl: ${dropBase.minPlayerLevel}, " + + "maxlvl: ${dropBase.maxPlayerLevel} player level criteria not met" ) } } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsParser.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsParser.kt index b0722b9e1..eff791ee4 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsParser.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsParser.kt @@ -446,10 +446,8 @@ class CustomDropsParser( if (!ymlHelper.getString( "amount").isNullOrEmpty()) { if (!dropBase.setAmountRangeFromString(ymlHelper.getString( "amount"))) { hadError( - String.format( - "Invalid number or number range for amount on %s, %s", - dropInstance!!.getMobOrGroupName(), ymlHelper.getString( "amount") - ) + "Invalid number or number range for amount on " + + "${dropInstance!!.getMobOrGroupName()}, ${ymlHelper.getString( "amount")}" ) } } @@ -570,10 +568,7 @@ class CustomDropsParser( if (!ymlHelper.getString("damage").isNullOrEmpty()) { if (!item.setDamageRangeFromString(ymlHelper.getString( "damage"))) { hadError( - String.format( - "Invalid number range for damage on %s, %s", - dropInstance!!.getMobOrGroupName(), ymlHelper.getString("damage") - ) + "Invalid number range for damage on ${dropInstance!!.getMobOrGroupName()}, ${ymlHelper.getString("damage")}" ) } } @@ -594,11 +589,7 @@ class CustomDropsParser( if (ExternalCompatibilityManager.hasNbtApiInstalled) { val result: NBTApplyResult = NBTManager.applyNBTDataItem(item, item.nbtData!!) if (result.hadException) { - String.format( - "custom drop %s for %s has invalid NBT data: %s", - item.material, dropInstance!!.getMobOrGroupName(), - result.exceptionMessage - ) + "custom drop ${item.material} for ${dropInstance!!.getMobOrGroupName()} has invalid NBT data: ${result.exceptionMessage}" } else if (result.itemStack != null) { item.itemStack = result.itemStack this.dropsUtilizeNBTAPI = true @@ -800,12 +791,7 @@ class CustomDropsParser( if (!isDefault) { if (!Utils.isInteger(key.toString())) { - hadError( - String.format( - "Enchantment: %s, invalid enchantment level %s", - enchantment, key - ) - ) + hadError("Enchantment: $enchantment, invalid enchantment level $key") continue } enchantmentLevel = key.toString().toInt() @@ -815,12 +801,7 @@ class CustomDropsParser( try { chanceValue = value.toString().toDouble() } catch (ignored: Exception) { - hadError( - String.format( - "Enchantment: %s, invalid chance specified: %s", - enchantment, value - ) - ) + hadError("Enchantment: $enchantment, invalid chance specified: $value") continue } @@ -922,12 +903,7 @@ class CustomDropsParser( val newFlag = ItemFlag.valueOf(flag.trim { it <= ' ' }.uppercase(Locale.getDefault())) results.add(newFlag) } catch (e: Exception) { - hadError( - String.format( - "Invalid itemflag: %s, item: %s, mobOrGroup: %s", - flag, item.material.name, dropInstance!!.getMobOrGroupName() - ) - ) + hadError("Invalid itemflag: $flag, item: ${item.material.name}, mobOrGroup: ${dropInstance!!.getMobOrGroupName()}") } } @@ -979,12 +955,7 @@ class CustomDropsParser( else -> { val currentPath = if (cs.currentPath.isNullOrEmpty()) path else cs.currentPath + "." + path - hadError( - String.format( - "%s: couldn't parse Config of type: %s, value: %s", - currentPath, obj.javaClass.simpleName, obj - ) - ) + hadError("$currentPath: couldn't parse Config of type: ${obj.javaClass.simpleName}, value: $obj") return null } } @@ -1048,12 +1019,7 @@ class CustomDropsParser( try { material = Material.valueOf(useMaterialName.uppercase(Locale.getDefault())) } catch (e: Exception) { - hadError( - String.format( - "Invalid material type specified in customdrops.yml for: %s, %s", - dropInstance!!.getMobOrGroupName(), useMaterialName - ) - ) + hadError("Invalid material type specified in customdrops.yml for: ${dropInstance!!.getMobOrGroupName()}, $useMaterialName") return false } @@ -1183,17 +1149,11 @@ class CustomDropsParser( if (item != null) { val itemMaterial = item.material.toString() sb.append( - String.format( - " &b%s&r, amount: &b%s&r, chance: &b%s&r", itemMaterial, - item.amountAsString, baseItem.chance - ) + " &b$itemMaterial&r, amount: &b${item.amountAsString}&r, chance: &b${baseItem.chance}&r" ) } else if (baseItem is CustomCommand) { sb.append( - String.format( - " COMMAND, chance: &b%s&r, run-on-spawn: %s, run-on-death: %s", - baseItem.chance, baseItem.runOnSpawn, baseItem.runOnDeath - ) + " COMMAND, chance: &b${baseItem.chance}&r, run-on-spawn: ${baseItem.runOnSpawn}, run-on-death: ${baseItem.runOnDeath}" ) } @@ -1345,10 +1305,7 @@ class CustomDropsParser( if (sb2.isNotEmpty()) sb2.append(", ") sb2.append( - String.format( - "&b%s&r (%s)", enchant.key.key, - item.itemStack!!.itemMeta.enchants[enchant] - ) + "&b${enchant.key.key}&r (${item.itemStack!!.itemMeta.enchants[enchant]})", enchant.key.key ) } } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/GroupLimits.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/GroupLimits.kt index d31860c5f..c0d2380dd 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/GroupLimits.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/GroupLimits.kt @@ -49,9 +49,6 @@ class GroupLimits { } override fun toString(): String { - return String.format( - "capTotal: %s, capEquip: %s, capPerItem: %s, capSelect: %s, retries: %s", - capTotal, capEquipped, capPerItem, capSelect, retries - ) + return "capTotal: $capTotal, capEquip: $capEquipped, capPerItem: $capPerItem, capSelect: $capSelect, retries: $retries" } } \ No newline at end of file diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/LMItemsParser.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/LMItemsParser.kt index 1f4ee0f4f..c25169958 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/LMItemsParser.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/LMItemsParser.kt @@ -124,10 +124,7 @@ class LMItemsParser { ) } else { Log.war( - String.format( - "custom item '%s:%s' doesn't support type %s", - item.externalPluginName, item.externalItemId, item.externalType - ) + "custom item '${item.externalPluginName}:${item.externalItemId}' doesn't support type ${item.externalType}" ) } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityDeathListener.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityDeathListener.kt index 37aaeb650..8d7dd8966 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityDeathListener.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityDeathListener.kt @@ -183,11 +183,7 @@ class EntityDeathListener : Listener { } DebugManager.log(DebugType.CHUNK_KILL_COUNT, lmEntity) { - String.format( - "%s: player: %s, reached chunk kill limit, max: %s", - Utils.displayChunkLocation(lmEntity.location), player.name, - maximumDeathInChunkThreshold - ) + "${Utils.displayChunkLocation(lmEntity.location)}: player: ${player.name}, reached chunk kill limit, max: $maximumDeathInChunkThreshold" } val prefix = main.configUtils.prefix diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntitySpawnListener.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntitySpawnListener.kt index 073911db3..bbd708311 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntitySpawnListener.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntitySpawnListener.kt @@ -163,11 +163,8 @@ class EntitySpawnListener : Listener{ val customDropIdFinal = customDropId DebugManager.log(DebugType.LM_MOB_SPAWNER, lmEntity) { - String.format( - "Spawned mob from LM spawner: minLevel:&b %s&7, maxLevel: &b%s&7, generatedLevel: &b%s&b%s", - useMinLevel, useMaxLevel, generatedLevel, - (if (customDropIdFinal == null) "" else ", dropid: $customDropIdFinal") - ) + val msg = (if (customDropIdFinal == null) "" else ", dropid: $customDropIdFinal") + "Spawned mob from LM spawner: minLevel:&b $useMinLevel&7, maxLevel: &b$useMaxLevel&7, generatedLevel: &b$generatedLevel&b$msg" } main.levelInterface.applyLevelToMob( diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/PlayerPortalEventListener.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/PlayerPortalEventListener.kt index 82b0c69a6..c3d1de2dd 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/PlayerPortalEventListener.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/PlayerPortalEventListener.kt @@ -36,11 +36,7 @@ class PlayerPortalEventListener : Listener { // store the player's portal coords in the nether. only used for player levelling main.mainCompanion.setPlayerNetherPortalLocation(player, event.to) - val locationStr = String.format( - "%s,%s,%s,%s", - event.to.world.name, event.to.blockX, - event.to.blockY, event.to.blockZ - ) + val locationStr = "${event.to.world.name},${event.to.blockX},${event.to.blockY},${event.to.blockZ}" val runnable: BukkitRunnable = object : BukkitRunnable() { override fun run() { diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt index 0a99439b4..204182321 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt @@ -351,11 +351,7 @@ class LevelManager : LevelInterface2 { if (papiResult.isEmpty()) { val l = player.location DebugManager.log(DebugType.PLAYER_LEVELLING, lmEntity) { - String.format( - "Got blank result for '%s' from PAPI. Player %s at %s,%s,%s in %s", - variableToUse, player.name, l.blockX, l.blockY, - l.blockZ, player.world.name - ) + "Got blank result for '$variableToUse' from PAPI. Player ${player.name} at ${l.blockX},${l.blockY},${l.blockZ} in ${player.world.name}" } usePlayerLevel = true } @@ -373,11 +369,7 @@ class LevelManager : LevelInterface2 { if (papiResult.isNullOrEmpty()) { origLevelSource = player.level.toFloat() DebugManager.log(DebugType.PLAYER_LEVELLING, lmEntity) { - String.format( - "Got blank result for '%s' from PAPI. Player %s at %s,%s,%s in %s", - variableToUse, player.name, l.blockX, l.blockY, - l.blockZ, player.world.name - ) + "Got blank result for '$variableToUse' from PAPI. Player ${player.name} at ${l.blockX},${l.blockY},${l.blockZ} in ${player.world.name}" } } else { if (Utils.isDouble(papiResult)) { @@ -528,11 +520,7 @@ class LevelManager : LevelInterface2 { val nameWithOverride = if (hasOverride) " (override), " else "" val additionUsedFinal = additionUsed DebugManager.log(DebugType.SET_LEVELLED_ITEM_DROPS, lmEntity) { - String.format( - "%smob-lvl: &b%s&7, vanilla drops: &b%s&7, all drops: &b%s&7, addition: &b%s&7.", - nameWithOverride, lmEntity.getMobLevel, vanillaDrops, currentDrops.size, - additionUsedFinal - ) + "${nameWithOverride}mob-lvl: &b${lmEntity.getMobLevel}&7, vanilla drops: &b$vanillaDrops&7, all drops: &b${currentDrops.size}&7, addition: &b$additionUsedFinal&7." } } @@ -1566,10 +1554,7 @@ class LevelManager : LevelInterface2 { val blastRadiusFinal = blastRadius DebugManager.log(DebugType.CREEPER_BLAST_RADIUS, lmEntity) { - String.format( - "lvl: %s, mulp: %s, max: %s, result: %s", - lmEntity.getMobLevel, Utils.round(damage.toDouble(), 3), maxRadius, blastRadiusFinal - ) + "lvl: ${lmEntity.getMobLevel}, mulp: ${Utils.round(damage.toDouble(), 3)}, max: $maxRadius, result: $blastRadiusFinal" } if (blastRadius < 0) { @@ -1665,10 +1650,7 @@ class LevelManager : LevelInterface2 { if (groupLimits!!.hasReachedCapEquipped(equippedSoFar)) { DebugManager.log(DebugType.GROUP_LIMITS, lmEntity) { - String.format( - "Reached equip limit of %s, item: %s, group: %s", - groupLimits.capEquipped, material, item.groupId - ) + "Reached equip limit of ${groupLimits.capEquipped}, item: $material, group: ${item.groupId}" } continue } @@ -1971,17 +1953,11 @@ class LevelManager : LevelInterface2 { Bukkit.getPluginManager() .callEvent(MobPostLevelEvent(lmEntity, levelCause, additionalLevelInformation)) - val sb = StringBuilder() - sb.append(", world: ") - sb.append(lmEntity.worldName) - sb.append(", level: ") - sb.append(useLevel) - if (isSummoned) { + val sb = StringBuilder().append("world: ").append(lmEntity.worldName).append(", level: ").append(useLevel) + if (isSummoned) sb.append(" (summoned)") - } - if (bypassLimits) { + if (bypassLimits) sb.append(" (limit bypass)") - } DebugManager.log(DebugType.APPLY_LEVEL_RESULT, lmEntity, true, sb::toString) } @@ -2072,10 +2048,7 @@ class LevelManager : LevelInterface2 { if (result.hadException) { if (lmEntity.summonedSender == null) { Log.war( - String.format( - "Error applying NBT data '%s' to %s. Exception message: %s", - nbtData, lmEntity.nameIfBaby, result.exceptionMessage - ) + "Error applying NBT data '$nbtData' to ${lmEntity.nameIfBaby}. Exception message: ${result.exceptionMessage}" ) } else { lmEntity.summonedSender!!.sendMessage( diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/MobDataManager.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/MobDataManager.kt index c0e377be5..6645e6239 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/MobDataManager.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/MobDataManager.kt @@ -268,14 +268,8 @@ class MobDataManager { if (!existingMod.name.startsWith("GENERIC_")) { DebugManager.log(DebugType.REMOVED_MULTIPLIERS, lmEntity) { - String.format( - "Removing %s from (lvl %s) at %s,%s,%s", - existingMod.name, - lmEntity.getMobLevel, - lmEntity.location.blockX, - lmEntity.location.blockY, - lmEntity.location.blockZ - ) + val locationStr = "${lmEntity.location.blockX},${lmEntity.location.blockY},${lmEntity.location.blockZ}" + "Removing ${existingMod.name} from (lvl ${lmEntity.getMobLevel}) at $locationStr" } } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/FileMigrator.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/FileMigrator.kt index af65ade84..abe62fc03 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/FileMigrator.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/FileMigrator.kt @@ -585,10 +585,7 @@ object FileMigrator { "&fFile Loader: &8(Migration) &7Migrated &b${to.name}&7 successfully." ) Log.inf( - String.format( - "&fFile Loader: &8(Migration) &7Keys matched: &b%s&7, values matched: &b%s&7, values updated: &b%s&7.", - keysMatched, valuesMatched, valuesUpdated - ) + "&fFile Loader: &8(Migration) &7Keys matched: &b$keysMatched&7, values matched: &b$valuesMatched&7, values updated: &b$valuesUpdated&7." ) } catch (e: Exception) { Log.sev( diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/MiscUtils.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/MiscUtils.kt index 245f62a4f..5fb3d0316 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/MiscUtils.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/MiscUtils.kt @@ -38,6 +38,7 @@ object MiscUtils { return "" } + @Suppress("UNCHECKED_CAST") fun getPDCKeys( livingEntity: LivingEntity ): MutableMap { @@ -67,14 +68,14 @@ object MiscUtils { val ver = LevelledMobs.instance.ver var methodName = if (ver.majorVersion >= 21) "tags" else "x" - val tags = compoundTagClazz.getDeclaredField(methodName) - val test2 = tags.get(compoundTag) as MutableMap + val tagsField = compoundTagClazz.getDeclaredField(methodName) + val tagsMap = tagsField.get(compoundTag) as MutableMap // NBTTagCompound.java - val bukkitValues = test2["BukkitValues"] + val bukkitValues = tagsMap["BukkitValues"] // private final Map tags; (again) - val bukkitValuesMap = tags.get(bukkitValues) as MutableMap + val bukkitValuesMap = tagsField.get(bukkitValues) as MutableMap for (nbtBase in bukkitValuesMap.entries){ // @Override @@ -82,18 +83,18 @@ object MiscUtils { // net.minecraft.nbt.CompoundTag -> // net.minecraft.nbt.TagType getType() -> methodName = if (ver.majorVersion >= 21) "getType" else "c" - val getType = nbtBase.value::javaClass.get().getMethod(methodName) - val type = getType.invoke(nbtBase.value) + val getTypeMethod = nbtBase.value::javaClass.get().getMethod(methodName) + val type = getTypeMethod.invoke(nbtBase.value) // @Override // public String getName() // net.minecraft.nbt.TagType -> // java.lang.String getName() -> methodName = if (ver.majorVersion >= 21) "getName" else "a" - val getName = type::class.java.getDeclaredMethod(methodName) + val getNameMethod = type::class.java.getDeclaredMethod(methodName) // all classes are public but for some reason acts like it is private - getName.trySetAccessible() + getNameMethod.trySetAccessible() - val valueType = getName.invoke(type).toString().lowercase() + val valueType = getNameMethod.invoke(type).toString().lowercase() if ("byte[]" == valueType) { // NBTTagByteArray.java: public int size() val methodSize = nbtBase.value.javaClass.getDeclaredMethod("size") diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/ServerVersionInfo.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/ServerVersionInfo.kt index 6cc44bb0c..f1312cccb 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/ServerVersionInfo.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/ServerVersionInfo.kt @@ -106,10 +106,7 @@ class ServerVersionInfo { this.minecraftVersion = versionStr.toDouble() } catch (e: Exception) { LevelledMobs.instance.logger.warning( - String.format( - "LevelledMobs: Could not extract the minecraft version from '%s'. %s", - Bukkit.getServer().javaClass.canonicalName, e.message - ) + "LevelledMobs: Could not extract the minecraft version from '${Bukkit.getServer().javaClass.canonicalName}'. ${e.message}" ) } } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/LevelTierMatching.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/LevelTierMatching.kt index c9a443754..0dd887789 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/LevelTierMatching.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/LevelTierMatching.kt @@ -65,21 +65,15 @@ class LevelTierMatching { } if (minLevel != null && maxLevel != null) { - return String.format( - "%s-%s %s", minLevel, maxLevel, - if (names == null) valueRanges.toString() else names - ) + val msg = if (names == null) valueRanges.toString() else names.toString() + return "$minLevel-$maxLevel $msg" } return if (minLevel != null) { - String.format( - "%s- %s", minLevel, - if (names == null) valueRanges.toString() else names - ) + val msg = if (names == null) valueRanges.toString() else names.toString() + "$minLevel- $msg" } else { - String.format( - "-%s %s", maxLevel, - if (names == null) valueRanges.toString() else names - ) + val msg = if (names == null) valueRanges.toString() else names.toString() + "-$maxLevel $msg" } } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt index 22eba2b05..834809c17 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt @@ -1240,10 +1240,7 @@ class RulesParser { for (i in 0..1) { if (!isInteger(split[i])) { Log.war( - String.format( - "Invalid value for %s: '%s' in rule %s", configName, split[i], - parsingInfo.ruleName - ) + "Invalid value for $configName: '${split[i]}' in rule ${parsingInfo.ruleName}" ) hadInvalidValue = true break diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/strategies/PlayerLevellingStrategy.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/strategies/PlayerLevellingStrategy.kt index 0637e8db2..346284976 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/strategies/PlayerLevellingStrategy.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/strategies/PlayerLevellingStrategy.kt @@ -110,19 +110,11 @@ class PlayerLevellingStrategy : LevellingStrategy, Cloneable { if (!foundMatch) { if (playerLevelSourceResult.isNumericResult) { DebugManager.log(DebugType.PLAYER_LEVELLING, lmEntity) { - String.format( - "player: %s, input: %s, scale: %s, %sno tiers matched", - player.name, origLevelSource, levelSource, - capDisplay - ) + "player: ${player.name}, input: $origLevelSource, scale: $levelSource,${capDisplay}sno tiers matched" } } else { DebugManager.log(DebugType.PLAYER_LEVELLING, lmEntity) { - String.format( - "player: %s, input: '%s', %sno tiers matched", - player.name, - playerLevelSourceResult.stringResult, capDisplay - ) + "player: ${player.name}, input: '${playerLevelSourceResult.stringResult}', ${capDisplay}no tiers matched" } } if (options.outputCap != null) { @@ -158,30 +150,17 @@ class PlayerLevellingStrategy : LevellingStrategy, Cloneable { if (tierMatched == null) { DebugManager.log(DebugType.PLAYER_LEVELLING, lmEntity) { - String.format( - "player: %s, input: %s%s%s, scale: %s, %sresult: %s", - player.name, origLevelSource, homeName, - varianceDebug, levelSource, capDisplay, results - ) + "player: ${player.name}, input: ${origLevelSource}${homeName}${varianceDebug}, scale: ${levelSource}, ${capDisplay}result: $results" } } else { val tierMatchedFinal: String = tierMatched if (playerLevelSourceResult.isNumericResult) { DebugManager.log(DebugType.PLAYER_LEVELLING, lmEntity) { - String.format( - "player: %s, input: %s%s%s, scale: %s, tier: %s, %sresult: %s", - player.name, origLevelSource, homeName, - varianceDebug, levelSource, tierMatchedFinal, capDisplay, results - ) + "player: ${player.name}, input: ${origLevelSource}${homeName}$varianceDebug, scale: $levelSource, tier: $tierMatchedFinal, ${capDisplay}result: $results" } } else { DebugManager.log(DebugType.PLAYER_LEVELLING, lmEntity) { - String.format( - "player: %s, input: '%s'%s, tier: %s, %sresult: %s", - player.name, - playerLevelSourceResult.stringResult, varianceDebug, tierMatchedFinal, - capDisplay, results - ) + "player: ${player.name}, input: '${playerLevelSourceResult.stringResult}'$varianceDebug, tier: $tierMatchedFinal, ${capDisplay}result: $results" } } } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/wrappers/LivingEntityWrapper.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/wrappers/LivingEntityWrapper.kt index 9d1e639e9..776d8b8bf 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/wrappers/LivingEntityWrapper.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/wrappers/LivingEntityWrapper.kt @@ -286,21 +286,14 @@ class LivingEntityWrapper private constructor() : LivingEntityWrapperBase(), Liv retryCount++ if (retryCount > LOCKMAXRETRYTIMES) { DebugManager.log(DebugType.THREAD_LOCKS) { - String.format( - "getPDCLock could not lock thread - %s:%s", - callingFunction.fileName, callingFunction.lineNumber - ) + "getPDCLock could not lock thread - ${callingFunction.fileName}:${callingFunction.lineNumber}" } return false } val retryCountFinal = retryCount DebugManager.log(DebugType.THREAD_LOCKS) { - String.format( - "getPDCLock retry %s - %s:%s", - retryCountFinal, callingFunction.fileName, - callingFunction.lineNumber - ) + "getPDCLock retry $retryCountFinal - ${callingFunction.fileName}:${callingFunction.lineNumber}" } } } catch (e: InterruptedException) {