Попробуй отрефакторить данный класс. Даю полный кард-бланш на использование…
- User
Попробуй отрефакторить данный класс. Даю полный кард-бланш на использование синтаксического сахара, можешь даже попытаться сократить функцию настолько, насколько это получится, используя магию котлина.
private fun buildQuest(questType: QuestType, villager: Villager, questItem: ItemStack): VillagerQuest.Builder? { val quest = VillagerQuest.Builder().setQuestType(questType).setQuestItem(questItem) plugin.debug("Generating a quest reward...") val questReward = when (questType) { QuestType.DISC, QuestType.PROFESSION_ITEM_GATHERING, QuestType.OMINOUS_BANNER -> { val itemPrice = when (questType) { QuestType.OMINOUS_BANNER -> plugin.configurationClip.promptsConfig.getInt("ominous-banner.reward-points") else -> this.calculateItemPrice(questItem) } val villagerItems = villager.quillInventory.filterNotNull().filter { item -> this.calculateItemPrice(item) > 0 && !this.isProfessionItem(villager.profession, item) } val inventoryPrice = this.calculateItemListPrice(villagerItems) plugin.debug("Item price: $itemPrice.") plugin.debug("Inventory price: $inventoryPrice.") if (itemPrice > inventoryPrice) { plugin.debug("Item price is bigger than inventory price. Cancelling quest generation.") return null } // Если наград больше одной, используется мешочек val barterItems = this.gatherBarterItems(questType, questItem, inventoryPrice, villagerItems) if (barterItems.size > 1) this.bundle(barterItems) else { // Если нет предметов, которые житель мог бы отдать в качестве награды за квест if (barterItems.isEmpty()) { plugin.debug("Villager have no items to use them as a reward. Cancelling quest generation.") return null } else barterItems[0] } } else -> ItemStack(Material.AIR) } plugin.debug("Quest item is: [${questReward.type}, amount is ${questReward.amount}]!") return quest.setRewardItem(questReward) } - Assistant