From 406ff65a6dd5e7c36780d6bf5a14f9351a9035c5 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 10 Aug 2023 15:36:13 +0100 Subject: [PATCH] Cleanup more --- .../kotlin/com/willfp/ecoquests/quests/Quest.kt | 16 +++------------- .../com/willfp/ecoquests/tasks/TaskTemplate.kt | 4 ++++ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoquests/quests/Quest.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoquests/quests/Quest.kt index 01d4d2e..0d299cc 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoquests/quests/Quest.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoquests/quests/Quest.kt @@ -69,13 +69,8 @@ class Quest( // The pool of available tasks to pick from private val availableTasks = config.getSubsections("tasks") .mapNotNull { - Task( - plugin, - // Could probably clean - Tasks[it.getString("task")] ?: return@mapNotNull null, - this, - it.getString("xp") - ) + Tasks[it.getString("task")] + ?.create(this, it.getString("xp")) } // The amount of tasks to use from the pool @@ -309,12 +304,7 @@ class Quest( val template = Tasks[taskId] ?: continue - savedTasks += Task( - plugin, - template, - this, - xpExpr - ) + savedTasks += template.create(this, xpExpr) } return savedTasks diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoquests/tasks/TaskTemplate.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoquests/tasks/TaskTemplate.kt index aeb0231..6e7e77f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoquests/tasks/TaskTemplate.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoquests/tasks/TaskTemplate.kt @@ -3,6 +3,7 @@ package com.willfp.ecoquests.tasks import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.config.interfaces.Config import com.willfp.eco.core.registry.KRegistrable +import com.willfp.ecoquests.quests.Quest import com.willfp.libreforge.ViolationContext import com.willfp.libreforge.counters.Counters @@ -14,4 +15,7 @@ class TaskTemplate( val xpGainMethods = config.getSubsections("xp-gain-methods").mapNotNull { Counters.compile(it, ViolationContext(plugin, "task $id tasks")) } + + fun create(quest: Quest, xpExpr: String) = + Task(plugin, this, quest, xpExpr) }