|
9 | 9 |
|
10 | 10 | import com.dumptruckman.minecraft.util.Logging; |
11 | 11 | import org.mvplugins.multiverse.core.MultiverseCoreApi; |
12 | | -import org.mvplugins.multiverse.core.MultiversePlugin; |
13 | 12 | import org.mvplugins.multiverse.core.config.CoreConfig; |
14 | 13 | import org.mvplugins.multiverse.core.inject.PluginServiceLocator; |
15 | | -import org.mvplugins.multiverse.core.inject.PluginServiceLocatorFactory; |
| 14 | +import org.mvplugins.multiverse.core.module.MultiverseModule; |
16 | 15 | import org.mvplugins.multiverse.core.utils.StringFormatter; |
17 | 16 | import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; |
18 | | -import org.mvplugins.multiverse.external.vavr.control.Option; |
19 | | -import org.mvplugins.multiverse.external.vavr.control.Try; |
20 | 17 | import org.mvplugins.multiverse.signportals.listeners.SignPortalsListener; |
21 | 18 |
|
22 | 19 | import java.util.logging.Level; |
23 | 20 |
|
24 | 21 | @Service |
25 | | -public class MultiverseSignPortals extends MultiversePlugin { |
| 22 | +public class MultiverseSignPortals extends MultiverseModule { |
26 | 23 |
|
27 | 24 | private static final double TARGET_CORE_API_VERSION = 5.0; |
28 | 25 |
|
29 | | - private MultiverseCoreApi core; |
30 | | - private PluginServiceLocator serviceLocator; |
31 | | - |
32 | 26 | /** This fires before I get Enabled. */ |
| 27 | + @Override |
33 | 28 | public void onLoad() { |
34 | 29 | Logging.init(this); |
35 | 30 | this.getDataFolder().mkdirs(); |
36 | 31 | } |
37 | 32 |
|
| 33 | + @Override |
38 | 34 | public void onEnable() { |
39 | 35 | Logging.init(this); |
40 | 36 |
|
41 | | - this.core = MultiverseCoreApi.get(); |
42 | | - |
43 | | - initializeDependencyInjection(); |
44 | | - registerEvents(); |
| 37 | + initializeDependencyInjection(new MultiverseSignPortalsPluginBinder(this)); |
| 38 | + registerEvents(SignPortalsListener.class); |
45 | 39 | Logging.setDebugLevel(serviceLocator.getActiveService(CoreConfig.class).getGlobalDebug()); |
46 | 40 |
|
47 | 41 | Logging.log(true, Level.INFO, " Enabled - By %s", StringFormatter.joinAnd(getDescription().getAuthors())); |
48 | 42 | } |
49 | 43 |
|
| 44 | + @Override |
50 | 45 | public void onDisable() { |
51 | | - // The Usual |
52 | 46 | shutdownDependencyInjection(); |
53 | 47 | Logging.info("- Disabled"); |
54 | 48 | } |
55 | 49 |
|
56 | | - private void initializeDependencyInjection() { |
57 | | - serviceLocator = PluginServiceLocatorFactory.get() |
58 | | - .registerPlugin(new MultiverseSignPortalsPluginBinder(this), core.getServiceLocator()) |
59 | | - .flatMap(PluginServiceLocator::enable) |
60 | | - .getOrElseThrow(exception -> { |
61 | | - Logging.severe("Failed to initialize dependency injection!"); |
62 | | - getServer().getPluginManager().disablePlugin(this); |
63 | | - return new RuntimeException(exception); |
64 | | - }); |
65 | | - } |
66 | | - |
67 | | - private void shutdownDependencyInjection() { |
68 | | - Option.of(serviceLocator) |
69 | | - .peek(PluginServiceLocator::disable) |
70 | | - .peek(ignore -> serviceLocator = null); |
71 | | - } |
72 | | - |
73 | | - /** |
74 | | - * Function to Register all the Events needed. |
75 | | - */ |
76 | | - private void registerEvents() { |
77 | | - var pluginManager = getServer().getPluginManager(); |
78 | | - |
79 | | - Try.run(() -> serviceLocator.getAllServices(SignPortalsListener.class).forEach( |
80 | | - listener -> { |
81 | | - Logging.info(listener.toString()); |
82 | | - pluginManager.registerEvents(listener, this); |
83 | | - })) |
84 | | - .onFailure(e -> { |
85 | | - throw new RuntimeException("Failed to register listeners. Terminating...", e); |
86 | | - }); |
87 | | - } |
88 | | - |
89 | 50 | @Override |
90 | 51 | public PluginServiceLocator getServiceLocator() { |
91 | 52 | return serviceLocator; |
|
0 commit comments