diff options
Diffstat (limited to 'common/src/main')
| -rw-r--r-- | common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskType.java | 26 | ||||
| -rw-r--r-- | common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskTypeManager.java | 31 |
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; } /** |
