diff options
| author | Krakenied <Krakenied1@gmail.com> | 2024-05-30 08:44:41 +0200 |
|---|---|---|
| committer | Leonardo Bishop <13875753+LMBishop@users.noreply.github.com> | 2024-06-03 18:48:22 +0100 |
| commit | 5c62483c10291cb874149bc23c0418978720655a (patch) | |
| tree | dba81e942697dc39a8be9d68724c8bf990338f0d | |
| parent | 40394f82c0ae003d6c54cf435e3c6f0c519d5069 (diff) | |
Extract method getting registration message
| -rw-r--r-- | bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java | 46 | ||||
| -rw-r--r-- | common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskTypeManager.java | 11 |
2 files changed, 44 insertions, 13 deletions
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 5a21038b..1eb02c77 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java @@ -493,7 +493,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { }); // Register task types with even more weird requirements - if (Bukkit.getPluginManager().isPluginEnabled("BentoBox")) { + if (CompatUtils.isPluginEnabled("BentoBox")) { BentoBoxLevelTaskType.register(this, taskTypeManager); } @@ -501,18 +501,8 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { taskTypeManager.closeRegistrations(); // Inform about registered task types - String registrationMessage = taskTypeManager.getTaskTypes().size() + " task types have been registered"; - int skipped = taskTypeManager.getSkipped(); - int unsupported = taskTypeManager.getUnsupported(); - if (skipped + unsupported > 0) { - registrationMessage += " ("; - if (skipped > 0) registrationMessage += skipped + " skipped due to exclusions or conflicting names"; - if (skipped * unsupported > 0) registrationMessage += ", "; - if (unsupported > 0) registrationMessage += unsupported + " not supported"; - registrationMessage += ")"; - } - registrationMessage += "."; - questsLogger.info(registrationMessage); + final String registrationMessage = this.getRegistrationMessage(); + this.questsLogger.info(registrationMessage); if (playerBlockTrackerHook != null) { this.playerBlockTrackerHook.fixPlayerBlockTracker(); @@ -531,6 +521,36 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { }); } + private @NotNull String getRegistrationMessage() { + final int registered = this.taskTypeManager.getRegistered(); + final int skipped = taskTypeManager.getSkipped(); + final int unsupported = taskTypeManager.getUnsupported(); + + final StringBuilder sb = new StringBuilder(); + sb.append(registered).append(" task types have been registered"); + + if (skipped + unsupported > 0) { + sb.append(' ').append(')'); + + if (skipped > 0) { + sb.append(skipped).append(" skipped due to exclusions or conflicting names"); + } + + if (skipped * unsupported > 0) { + sb.append(',').append(' '); + } + + if (unsupported > 0) { + sb.append(unsupported).append(" not supported"); + } + + sb.append(')'); + } + + sb.append('.'); + return sb.toString(); + } + @Override public void onDisable() { if (!validConfiguration) return; 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 84cf5367..d5ee9687 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 @@ -25,6 +25,7 @@ public abstract class TaskTypeManager { private final Map<String, TaskType> taskTypes = new HashMap<>(); private final Map<String, String> aliases = new HashMap<>(); private final Set<String> exclusions; + private int registered; private int skipped; private int unsupported; private boolean registrationsOpen; @@ -102,6 +103,7 @@ public abstract class TaskTypeManager { this.aliases.put(alias, type); } + this.registered++; return true; } @@ -196,6 +198,15 @@ public abstract class TaskTypeManager { } /** + * Returns the number of task types registered. + * + * @return number of task types registered + */ + public int getRegistered() { + return this.registered; + } + + /** * Returns the number of task types skipped due to exclusions or name conflicts. * * @return number of task types skipped |
