Skip to content

Commit e02af3f

Browse files
committed
Update to support core api changes
1 parent 02debe3 commit e02af3f

File tree

2 files changed

+9
-47
lines changed

2 files changed

+9
-47
lines changed

src/main/java/org/mvplugins/multiverse/signportals/MultiverseSignPortals.java

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,83 +9,44 @@
99

1010
import com.dumptruckman.minecraft.util.Logging;
1111
import org.mvplugins.multiverse.core.MultiverseCoreApi;
12-
import org.mvplugins.multiverse.core.MultiversePlugin;
1312
import org.mvplugins.multiverse.core.config.CoreConfig;
1413
import org.mvplugins.multiverse.core.inject.PluginServiceLocator;
15-
import org.mvplugins.multiverse.core.inject.PluginServiceLocatorFactory;
14+
import org.mvplugins.multiverse.core.module.MultiverseModule;
1615
import org.mvplugins.multiverse.core.utils.StringFormatter;
1716
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;
2017
import org.mvplugins.multiverse.signportals.listeners.SignPortalsListener;
2118

2219
import java.util.logging.Level;
2320

2421
@Service
25-
public class MultiverseSignPortals extends MultiversePlugin {
22+
public class MultiverseSignPortals extends MultiverseModule {
2623

2724
private static final double TARGET_CORE_API_VERSION = 5.0;
2825

29-
private MultiverseCoreApi core;
30-
private PluginServiceLocator serviceLocator;
31-
3226
/** This fires before I get Enabled. */
27+
@Override
3328
public void onLoad() {
3429
Logging.init(this);
3530
this.getDataFolder().mkdirs();
3631
}
3732

33+
@Override
3834
public void onEnable() {
3935
Logging.init(this);
4036

41-
this.core = MultiverseCoreApi.get();
42-
43-
initializeDependencyInjection();
44-
registerEvents();
37+
initializeDependencyInjection(new MultiverseSignPortalsPluginBinder(this));
38+
registerEvents(SignPortalsListener.class);
4539
Logging.setDebugLevel(serviceLocator.getActiveService(CoreConfig.class).getGlobalDebug());
4640

4741
Logging.log(true, Level.INFO, " Enabled - By %s", StringFormatter.joinAnd(getDescription().getAuthors()));
4842
}
4943

44+
@Override
5045
public void onDisable() {
51-
// The Usual
5246
shutdownDependencyInjection();
5347
Logging.info("- Disabled");
5448
}
5549

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-
8950
@Override
9051
public PluginServiceLocator getServiceLocator() {
9152
return serviceLocator;

src/main/java/org/mvplugins/multiverse/signportals/MultiverseSignPortalsPluginBinder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package org.mvplugins.multiverse.signportals;
22

33
import org.mvplugins.multiverse.core.inject.binder.JavaPluginBinder;
4+
import org.mvplugins.multiverse.core.module.MultiverseModuleBinder;
45
import org.mvplugins.multiverse.external.glassfish.hk2.utilities.binding.ScopedBindingBuilder;
56
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
67

7-
public class MultiverseSignPortalsPluginBinder extends JavaPluginBinder<MultiverseSignPortals> {
8+
public class MultiverseSignPortalsPluginBinder extends MultiverseModuleBinder<MultiverseSignPortals> {
89

910
protected MultiverseSignPortalsPluginBinder(@NotNull MultiverseSignPortals plugin) {
1011
super(plugin);

0 commit comments

Comments
 (0)