diff options
| author | Krakenied <Krakenied1@gmail.com> | 2023-05-26 16:47:16 +0200 |
|---|---|---|
| committer | Krakenied <Krakenied1@gmail.com> | 2023-05-26 16:47:16 +0200 |
| commit | 8ba64ad354330aa827e807d48e615eba0adcbdb7 (patch) | |
| tree | af05b63df76a2c27926c6e458248ea3ca143af17 /bukkit | |
| parent | c7a5e4e4203322a2bc3862a0f5ba7b3382db8901 (diff) | |
Command task type refactor
More TaskUtils changes
Diffstat (limited to 'bukkit')
3 files changed, 24 insertions, 25 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/CommandTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/CommandTaskType.java index 616d88d2..78f36ef5 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/CommandTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/CommandTaskType.java @@ -37,30 +37,27 @@ public final class CommandTaskType extends BukkitTaskType { return; } + String message = e.getMessage(); + if (message.length() >= 1) { + message = message.substring(1); + } + for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskUtils.TaskConstraint.WORLD)) { Quest quest = pendingTask.quest(); Task task = pendingTask.task(); TaskProgress taskProgress = pendingTask.taskProgress(); - boolean ignoreCasing = TaskUtils.getConfigBoolean(task, "ignore-case"); - List<String> commands = TaskUtils.getConfigStringList(task, "command"); - - String message = e.getMessage(); - if (message.length() >= 1) { - message = message.substring(1); - } - super.debug("Player sent command '/" + message + "'", quest.getId(), task.getId(), player.getUniqueId()); - for (String command : commands) { - super.debug("Checking command against '/" + command + "' (ignore case = " + ignoreCasing + ")", quest.getId(), task.getId(), player.getUniqueId()); - if ((ignoreCasing && command.equalsIgnoreCase(message)) - || (!ignoreCasing && command.equals(message))) { - super.debug("Command '/" + message + "' matches task command '" + command + "'", quest.getId(), task.getId(), player.getUniqueId()); - super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId()); - taskProgress.setCompleted(true); - } + boolean ignoreCase = TaskUtils.getConfigBoolean(task, "ignore-case"); + + if (!TaskUtils.matchString(this, pendingTask, "command", "commands", message, false, ignoreCase, player.getUniqueId())) { + super.debug("Continuing...", quest.getId(), task.getId(), player.getUniqueId()); + continue; } + + super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId()); + taskProgress.setCompleted(true); } } } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingTaskType.java index cf32ed4c..9f0ae2af 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingTaskType.java @@ -85,7 +85,7 @@ public final class MobkillingTaskType extends BukkitTaskType { continue; } - if (!TaskUtils.matchName(this, pendingTask, customName, true, false, player.getUniqueId())) { + if (!TaskUtils.matchString(this, pendingTask, "name", "names", customName, true, false, player.getUniqueId())) { super.debug("Continuing...", quest.getId(), task.getId(), player.getUniqueId()); continue; } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java index 8f0c09ee..650b441d 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java @@ -286,26 +286,28 @@ public class TaskUtils { return false; } - public static boolean matchName(@NotNull BukkitTaskType type, @NotNull PendingTask pendingTask, @Nullable String name, boolean legacyColor, boolean ignoreCase, @NotNull UUID player) { + public static boolean matchString(@NotNull BukkitTaskType type, @NotNull PendingTask pendingTask, final @NotNull String stringKey, final @NotNull String stringListKey, @Nullable String string, boolean legacyColor, boolean ignoreCase, @NotNull UUID player) { Task task = pendingTask.task; - List<String> checkNames = TaskUtils.getConfigStringList(task, task.getConfigValues().containsKey("name") ? "name" : "names"); + List<String> checkNames = TaskUtils.getConfigStringList(task, task.getConfigValues().containsKey(stringKey) ? stringKey : stringListKey); if (checkNames == null) { return true; } else if (checkNames.isEmpty()) { - return name == null; + return string == null; } - if (name == null) { + if (string == null) { return false; } - for (String s : checkNames) { - type.debug("Checking against name " + s, pendingTask.quest.getId(), task.getId(), player); + for (String name : checkNames) { + type.debug("Checking against name " + string, pendingTask.quest.getId(), task.getId(), player); - s = Chat.legacyColor(s); + if (legacyColor) { + string = Chat.legacyColor(string); + } - if (StringUtils.equals(s, name, ignoreCase)) { + if (StringUtils.equals(string, name, ignoreCase)) { type.debug("Name match", pendingTask.quest.getId(), task.getId(), player); return true; } else { |
