|
2 | 2 |
|
3 | 3 | import com.google.common.collect.Lists; |
4 | 4 | import dev.plex.Plex; |
| 5 | +import dev.plex.handlers.CommandHandler; |
5 | 6 | import dev.plex.module.exception.ModuleLoadException; |
6 | 7 | import dev.plex.util.PlexLog; |
7 | 8 |
|
@@ -152,25 +153,49 @@ public void loadModules() |
152 | 153 |
|
153 | 154 | public void enableModules() |
154 | 155 | { |
155 | | - this.modules.forEach(module -> |
| 156 | + CommandHandler handler = plugin.getCommandHandler(); |
| 157 | + boolean previous = handler != null && handler.setSuppressLifecycleWarnings(true); |
| 158 | + try |
156 | 159 | { |
157 | | - PlexLog.log("Enabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); |
158 | | - module.enable(); |
159 | | - }); |
| 160 | + this.modules.forEach(module -> |
| 161 | + { |
| 162 | + PlexLog.log("Enabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); |
| 163 | + module.enable(); |
| 164 | + }); |
| 165 | + } |
| 166 | + finally |
| 167 | + { |
| 168 | + if (handler != null) |
| 169 | + { |
| 170 | + handler.setSuppressLifecycleWarnings(previous); |
| 171 | + } |
| 172 | + } |
160 | 173 | } |
161 | 174 |
|
162 | 175 | public void disableModules() |
163 | 176 | { |
164 | | - this.modules.forEach(module -> |
| 177 | + CommandHandler handler = plugin.getCommandHandler(); |
| 178 | + boolean previous = handler != null && handler.setSuppressLifecycleWarnings(true); |
| 179 | + try |
165 | 180 | { |
166 | | - PlexLog.log("Disabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); |
167 | | - module.getCommands().stream().toList().forEach(plexCommand -> |
| 181 | + this.modules.forEach(module -> |
168 | 182 | { |
169 | | - module.unregisterCommand(plexCommand); |
| 183 | + PlexLog.log("Disabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); |
| 184 | + module.getCommands().stream().toList().forEach(plexCommand -> |
| 185 | + { |
| 186 | + module.unregisterCommand(plexCommand); |
| 187 | + }); |
| 188 | + module.getListeners().stream().toList().forEach(module::unregisterListener); |
| 189 | + module.disable(); |
170 | 190 | }); |
171 | | - module.getListeners().stream().toList().forEach(module::unregisterListener); |
172 | | - module.disable(); |
173 | | - }); |
| 191 | + } |
| 192 | + finally |
| 193 | + { |
| 194 | + if (handler != null) |
| 195 | + { |
| 196 | + handler.setSuppressLifecycleWarnings(previous); |
| 197 | + } |
| 198 | + } |
174 | 199 | } |
175 | 200 |
|
176 | 201 | public void unloadModules() |
|
0 commit comments