aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main
diff options
context:
space:
mode:
authorKrakenied <Krakenied1@gmail.com>2023-09-17 22:16:42 +0200
committerKrakenied <Krakenied1@gmail.com>2023-09-24 15:57:11 +0200
commitb94b596b8a7925b95d62c7c14682870dac4f1128 (patch)
tree4918cca8e1ef1e0264d78485703e3a6d47c09e7d /common/src/main
parent43812ea231b338fd2f92288d204a8f0691cf76db (diff)
Fix up task type manager
Diffstat (limited to 'common/src/main')
-rw-r--r--common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskTypeManager.java39
1 files changed, 23 insertions, 16 deletions
diff --git a/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskTypeManager.java b/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskTypeManager.java
index e3ee82dc..3461ec6f 100644
--- a/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskTypeManager.java
+++ b/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskTypeManager.java
@@ -14,6 +14,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BooleanSupplier;
+import java.util.function.Supplier;
/**
* The task type manager stores all registered task types and registers individual quests to each task type.
@@ -68,28 +69,12 @@ public abstract class TaskTypeManager {
* @param taskType the task type to register
*/
public boolean registerTaskType(@NotNull TaskType taskType) {
- return registerTaskType(taskType, new BooleanSupplier[]{});
- }
-
- /**
- * Register a task type with the task type manager.
- *
- * @param taskType the task type to register
- * @param suppliers suppliers to check for task type compatibility
- */
- public boolean registerTaskType(@NotNull TaskType taskType, @NotNull BooleanSupplier... suppliers) {
Objects.requireNonNull(taskType, "taskType cannot be null");
if (!allowRegistrations) {
throw new IllegalStateException("No longer accepting new task types (must be done before quests are loaded)");
}
- for (BooleanSupplier supplier : suppliers) {
- if (!supplier.getAsBoolean()) {
- return false;
- }
- }
-
if (exclusions.contains(taskType.getType()) || taskTypes.containsKey(taskType.getType())) {
skipped++;
return false;
@@ -104,6 +89,28 @@ public abstract class TaskTypeManager {
}
/**
+ * Register a task type with the task type manager.
+ *
+ * @param taskTypeSupplier supplier of the task type to register
+ * @param compatibilitySuppliers suppliers to check for task type compatibility
+ */
+ public boolean registerTaskType(@NotNull Supplier<TaskType> taskTypeSupplier, @NotNull BooleanSupplier... compatibilitySuppliers) {
+ Objects.requireNonNull(taskTypeSupplier, "taskTypeSupplier cannot be null");
+
+ if (!allowRegistrations) {
+ throw new IllegalStateException("No longer accepting new task types (must be done before quests are loaded)");
+ }
+
+ for (BooleanSupplier supplier : compatibilitySuppliers) {
+ if (!supplier.getAsBoolean()) {
+ return false;
+ }
+ }
+
+ return registerTaskType(taskTypeSupplier.get());
+ }
+
+ /**
* Register a quest with its task types. This will register the quest to each task type it contains.
*
* @param quest the quest to register