Skip to content

Commit

Permalink
v4.0.5 b29
Browse files Browse the repository at this point in the history
* small code tweaks
  • Loading branch information
stumper66 committed Jun 21, 2024
1 parent 305b34b commit 5b2a915
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 300 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 4.0.5 b28
version = 4.0.5 b29
description = The Ultimate RPG Mob Levelling Solution

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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")}"
)
}
}
Expand Down Expand Up @@ -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")}"
)
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
}

Expand Down Expand Up @@ -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()}")
}
}

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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}"
)
}

Expand Down Expand Up @@ -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
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)) {
Expand Down Expand Up @@ -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."
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object MiscUtils {
return ""
}

@Suppress("UNCHECKED_CAST")
fun getPDCKeys(
livingEntity: LivingEntity
): MutableMap<String, String> {
Expand Down Expand Up @@ -67,33 +68,33 @@ 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<String, Any>
val tagsField = compoundTagClazz.getDeclaredField(methodName)
val tagsMap = tagsField.get(compoundTag) as MutableMap<String, Any>

// NBTTagCompound.java
val bukkitValues = test2["BukkitValues"]
val bukkitValues = tagsMap["BukkitValues"]

// private final Map<String, NBTBase> tags; (again)
val bukkitValuesMap = tags.get(bukkitValues) as MutableMap<String, Any>
val bukkitValuesMap = tagsField.get(bukkitValues) as MutableMap<String, Any>

for (nbtBase in bukkitValuesMap.entries){
// @Override
// public NBTTagType<NBTTagCompound> getType()
// 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
}
}
Expand Down
Loading

0 comments on commit 5b2a915

Please sign in to comment.