aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2021-07-21 19:48:10 +0100
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2021-07-21 19:48:10 +0100
commit2f2167459e74317d045cd7e3a7628c59439f08d2 (patch)
tree4c035679d2c3a75b4ce560ec13108d9f01874948
parent45f1cf893a79106ab295af33be8067dce3702a6d (diff)
Add task type exclusionsv3.5.2
-rw-r--r--build.gradle2
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java5
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/BukkitTaskTypeManager.java16
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingCertainTaskType.java1
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningCertainTaskType.java1
-rw-r--r--bukkit/src/main/resources/resources/bukkit/config.yml2
-rw-r--r--common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskTypeManager.java53
7 files changed, 61 insertions, 19 deletions
diff --git a/build.gradle b/build.gradle
index b7ddacf7..e17460ed 100644
--- a/build.gradle
+++ b/build.gradle
@@ -10,7 +10,7 @@ allprojects {
apply plugin: 'java'
group = 'com.leonardobishop'
- version = '3.5.1'
+ version = '3.5.2'
sourceCompatibility = 1.8
targetCompatibility = 1.8
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
index 8e3047da..5081c296 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
@@ -185,7 +185,6 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
this.generateConfigurations();
this.questsConfig = new BukkitQuestsConfig(new File(super.getDataFolder() + File.separator + "config.yml"));
this.questManager = new QuestManager(this);
- this.taskTypeManager = new BukkitTaskTypeManager(this);
this.serverScheduler = new BukkitServerSchedulerAdapter(this);
// Load base configuration for use during rest of startup procedure
@@ -243,6 +242,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
questsConfig.setItemGetter(itemGetter);
// Finish module initialisation
+ this.taskTypeManager = new BukkitTaskTypeManager(this, questsConfig.getStringList("options.task-type-exclusions"));
this.qPlayerManager = new QPlayerManager(this, storageProvider, questController);
this.menuController = new MenuController(this);
this.qItemStackRegistry = new QItemStackRegistry();
@@ -357,7 +357,8 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
}
taskTypeManager.closeRegistrations();
- questsLogger.info(taskTypeManager.getTaskTypes().size() + " task types have been registered.");
+ questsLogger.info(taskTypeManager.getTaskTypes().size() + " task types have been registered"
+ + (taskTypeManager.getSkipped() > 0 ? " (" + taskTypeManager.getSkipped() + " skipped due to exclusions or conflicting names)." : "."));
reloadQuests();
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/BukkitTaskTypeManager.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/BukkitTaskTypeManager.java
index c37017ae..91e511c8 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/BukkitTaskTypeManager.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/BukkitTaskTypeManager.java
@@ -5,6 +5,8 @@ import com.leonardobishop.quests.common.tasktype.TaskType;
import com.leonardobishop.quests.common.tasktype.TaskTypeManager;
import org.jetbrains.annotations.NotNull;
+import java.util.List;
+
public class BukkitTaskTypeManager extends TaskTypeManager {
private final BukkitQuestsPlugin plugin;
@@ -13,13 +15,21 @@ public class BukkitTaskTypeManager extends TaskTypeManager {
this.plugin = plugin;
}
+ public BukkitTaskTypeManager(BukkitQuestsPlugin plugin, List<String> exclusions) {
+ super(exclusions);
+ this.plugin = plugin;
+ }
+
@Override
- public void registerTaskType(@NotNull TaskType taskType) {
+ public boolean registerTaskType(@NotNull TaskType taskType) {
if (!(taskType instanceof BukkitTaskType)) throw new RuntimeException("BukkitTaskTypeManager implementation can only accept instances of BukkitTaskType!");
BukkitTaskType bukkitTaskType = (BukkitTaskType) taskType;
- super.registerTaskType(taskType);
- plugin.getServer().getPluginManager().registerEvents(bukkitTaskType, plugin);
+ if (super.registerTaskType(taskType)) {
+ plugin.getServer().getPluginManager().registerEvents(bukkitTaskType, plugin);
+ return true;
+ }
+ return false;
}
}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingCertainTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingCertainTaskType.java
index fc1cb9fd..dce629d0 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingCertainTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingCertainTaskType.java
@@ -34,6 +34,7 @@ public final class FarmingCertainTaskType extends BukkitTaskType {
@Override
public @NotNull List<ConfigProblem> validateConfig(@NotNull String root, @NotNull HashMap<String, Object> config) {
+ //TODO add world validation
ArrayList<ConfigProblem> problems = new ArrayList<>();
if (TaskUtils.configValidateExists(root + ".amount", config.get("amount"), problems, "amount", super.getType()))
TaskUtils.configValidateInt(root + ".amount", config.get("amount"), problems, false, true, "amount");
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningCertainTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningCertainTaskType.java
index 713bd8d2..c0e5c8a2 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningCertainTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningCertainTaskType.java
@@ -62,6 +62,7 @@ public final class MiningCertainTaskType extends BukkitTaskType {
}
}
}
+ //TODO this is wrong
TaskUtils.configValidateBoolean(root + ".reverse-if-broken", config.get("reverse-if-broken"), problems, true,"reverse-if-broken");
TaskUtils.configValidateBoolean(root + ".check-coreprotect", config.get("check-coreprotect"), problems, true,"check-coreprotect");
TaskUtils.configValidateInt(root + ".check-coreprotect-time", config.get("check-coreprotect-time"), problems, true,true, "check-coreprotect-time");
diff --git a/bukkit/src/main/resources/resources/bukkit/config.yml b/bukkit/src/main/resources/resources/bukkit/config.yml
index 95da645e..7bbc5c3c 100644
--- a/bukkit/src/main/resources/resources/bukkit/config.yml
+++ b/bukkit/src/main/resources/resources/bukkit/config.yml
@@ -190,6 +190,8 @@ options:
allow-quest-cancel: true
# Allow players to track a quest (you may want to remove the tracking instructions in the global item lore)
allow-quest-track: true
+ # Task type exclusions - include task IDs in this list which you don't want registering
+ task-type-exclusions: []
# Titles for the GUIs
guinames:
quests-category: "Quests Categories"
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 779670c6..fd9a04f3 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
@@ -6,9 +6,14 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import java.util.Set;
/**
* The task type manager stores all registered task types and registers individual quests to each task type.
@@ -17,11 +22,19 @@ import java.util.Objects;
*/
public abstract class TaskTypeManager {
- private final ArrayList<TaskType> taskTypes = new ArrayList<>();
+ private final Map<String, TaskType> taskTypes = new HashMap<>();
+ private final List<String> exclusions;
+ private int skipped;
private boolean allowRegistrations;
public TaskTypeManager() {
allowRegistrations = true;
+ exclusions = new ArrayList<>();
+ }
+
+ public TaskTypeManager(List<String> exclusions) {
+ allowRegistrations = true;
+ this.exclusions = exclusions;
}
public void closeRegistrations() {
@@ -33,17 +46,17 @@ public abstract class TaskTypeManager {
}
/**
- * @return immutable {@link List} containing all registered {@link TaskType}
+ * @return immutable {@link Set} containing all registered {@link TaskType}
*/
- public @NotNull List<TaskType> getTaskTypes() {
- return Collections.unmodifiableList(taskTypes);
+ public @NotNull Collection<TaskType> getTaskTypes() {
+ return Collections.unmodifiableCollection(taskTypes.values());
}
/**
* Resets all quest to task type registrations. This does not clear the task types registered to the task type manager.
*/
public void resetTaskTypes() {
- for (TaskType taskType : taskTypes) {
+ for (TaskType taskType : taskTypes.values()) {
taskType.unregisterAll();
}
}
@@ -53,13 +66,18 @@ public abstract class TaskTypeManager {
*
* @param taskType the task type to register
*/
- public void registerTaskType(@NotNull TaskType taskType) {
+ public boolean registerTaskType(@NotNull TaskType taskType) {
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)");
}
- taskTypes.add(taskType);
+ if (exclusions.contains(taskType.getType()) || taskTypes.containsKey(taskType.getType())) {
+ skipped++;
+ return false;
+ }
+ taskTypes.put(taskType.getType(), taskType);
+ return true;
}
/**
@@ -90,11 +108,20 @@ public abstract class TaskTypeManager {
public @Nullable TaskType getTaskType(@NotNull String type) {
Objects.requireNonNull(type, "type cannot be null");
- for (TaskType taskType : taskTypes) {
- if (taskType.getType().equalsIgnoreCase(type)) {
- return taskType;
- }
- }
- return null;
+ return taskTypes.get(type);
+ }
+
+ /**
+ * @return immutable {@link List} containing all task type exclusions
+ */
+ public @NotNull List<String> getExclusions() {
+ return Collections.unmodifiableList(exclusions);
+ }
+
+ /**
+ * @return number of task types skipped due to exclusions / name conflicts
+ */
+ public int getSkipped() {
+ return skipped;
}
}