aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2022-07-06 18:42:03 +0100
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2022-07-06 18:42:03 +0100
commit12ebaa52428f0b26c55736f67986d07494c75420 (patch)
tree5a7d5f57d458630f8b8fd64615d078d61caf0ac6 /common
parent6551b698274aaabb5b3b613cb076b55b2aa1d7ae (diff)
Merge task type certain types with regular types
Diffstat (limited to 'common')
-rw-r--r--common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskType.java26
-rw-r--r--common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskTypeManager.java31
2 files changed, 45 insertions, 12 deletions
diff --git a/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskType.java b/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskType.java
index 781d78f2..023a2074 100644
--- a/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskType.java
+++ b/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskType.java
@@ -17,6 +17,7 @@ import java.util.*;
public abstract class TaskType {
private final List<Quest> quests = new ArrayList<>();
+ private final List<String> aliases = new ArrayList<>();
private final List<ConfigValidator> configValidators = new ArrayList<>();
private final String type;
private String author;
@@ -27,6 +28,16 @@ public abstract class TaskType {
* @param author the name of the person (or people) who wrote it
* @param description a short, simple description of the task type
*/
+ public TaskType(@NotNull String type, String author, String description, String... aliases) {
+ this(type, author, description);
+ this.aliases.addAll(Arrays.asList(aliases));
+ }
+
+ /**
+ * @param type the name of the task type, should not contain spaces
+ * @param author the name of the person (or people) who wrote it
+ * @param description a short, simple description of the task type
+ */
public TaskType(@NotNull String type, String author, String description) {
this(type);
this.author = author;
@@ -82,6 +93,10 @@ public abstract class TaskType {
return description;
}
+ public @NotNull List<String> getAliases() {
+ return Collections.unmodifiableList(aliases);
+ }
+
/**
* Called when Quests has finished registering all quests to the task type.
* May be called several times if an operator uses /quests admin reload.
@@ -101,17 +116,6 @@ public abstract class TaskType {
// not implemented here
}
- /**
- * Called when Quests reloads the configuration - used to detect errors in the configuration of your task type.
- *
- * @param root the root path for the config
- * @param config the config itself
- */
- public @NotNull List<ConfigProblem> validateConfig(@NotNull String root, @NotNull HashMap<String, Object> config) {
- // not implemented here
- return Collections.emptyList();
- }
-
public void addConfigValidator(@NotNull ConfigValidator validator) {
Objects.requireNonNull(validator, "validator cannot be null");
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 167571b6..d804418d 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
@@ -15,6 +15,7 @@ import java.util.*;
public abstract class TaskTypeManager {
private final Map<String, TaskType> taskTypes = new HashMap<>();
+ private final Map<String, String> aliases = new HashMap<>();
private final List<String> exclusions;
private int skipped;
private boolean allowRegistrations;
@@ -69,6 +70,9 @@ public abstract class TaskTypeManager {
return false;
}
taskTypes.put(taskType.getType(), taskType);
+ for (String alias : taskType.getAliases()) {
+ aliases.put(alias, taskType.getType());
+ }
return true;
}
@@ -86,6 +90,7 @@ public abstract class TaskTypeManager {
for (Task task : quest.getTasks()) {
TaskType t;
if ((t = getTaskType(task.getType())) != null) {
+
t.registerQuest(quest);
}
}
@@ -100,7 +105,31 @@ public abstract class TaskTypeManager {
public @Nullable TaskType getTaskType(@NotNull String type) {
Objects.requireNonNull(type, "type cannot be null");
- return taskTypes.get(type);
+ TaskType taskType = taskTypes.get(type);
+ if (taskType == null) {
+ if (aliases.get(type) != null) {
+ return taskTypes.get(aliases.get(type));
+ }
+ }
+ return taskType;
+ }
+
+ /**
+ * Get the actual name of a task type, following aliases
+ *
+ * @param taskType name of task type
+ * @return actual name
+ */
+ public @Nullable String resolveTaskTypeName(@NotNull String taskType) {
+ Objects.requireNonNull(taskType, "taskType cannot be null");
+
+ if (taskTypes.containsKey(taskType)) {
+ return taskType;
+ }
+ if (aliases.containsKey(taskType)) {
+ return aliases.get(taskType);
+ }
+ return null;
}
/**