|
27 | 27 | import com.google.inject.TypeLiteral;
|
28 | 28 | import com.google.inject.name.Names;
|
29 | 29 | import java.nio.file.Path;
|
| 30 | +import java.util.Optional; |
30 | 31 | import java.util.concurrent.ExecutionException;
|
31 | 32 | import javax.inject.Inject;
|
32 | 33 | import org.slf4j.Logger;
|
33 | 34 | import org.slf4j.LoggerFactory;
|
| 35 | +import org.spongepowered.api.Server; |
| 36 | +import org.spongepowered.api.Sponge; |
34 | 37 | import org.spongepowered.api.command.Command;
|
| 38 | +import org.spongepowered.api.command.registrar.CommandRegistrar; |
| 39 | +import org.spongepowered.api.config.ConfigDir; |
35 | 40 | import org.spongepowered.api.config.DefaultConfig;
|
36 | 41 | import org.spongepowered.api.event.Listener;
|
37 |
| -import org.spongepowered.api.event.lifecycle.RegisterCommandEvent; |
| 42 | +import org.spongepowered.api.event.lifecycle.StartingEngineEvent; |
| 43 | +import org.spongepowered.api.scheduler.Scheduler; |
38 | 44 | import org.spongepowered.configurate.CommentedConfigurationNode;
|
39 | 45 | import org.spongepowered.configurate.loader.ConfigurationLoader;
|
40 | 46 | import org.spongepowered.plugin.builtin.jvm.Plugin;
|
|
43 | 49 | // do not extend StoreysPlugin, because we exclude that class in shadowJar
|
44 | 50 |
|
45 | 51 | private static final Logger LOG = LoggerFactory.getLogger(StoreysWebPlugin.class);
|
46 |
| - private VertxStarter vertxStarter; |
47 |
| - private LoginCommand loginCommand; |
48 |
| - private TokenCommand tokenCommand; |
49 | 52 |
|
| 53 | + @Inject @ConfigDir(sharedRoot = false) private Path configDir; |
50 | 54 | @Inject @DefaultConfig(sharedRoot = true) private ConfigurationLoader<CommentedConfigurationNode> configurationLoader;
|
51 | 55 |
|
52 |
| - @Override public void start(PluginInstance plugin, Path configDir) throws Exception { |
| 56 | + @Listener public final void onGameStartingServer(StartingEngineEvent<Server> event) throws Exception { |
| 57 | + LOG.info("See https://github.com/OASIS-learn-study/minecraft-storeys-maker for how to use /story and /narrate commands"); |
| 58 | + start(this, configDir); |
| 59 | + } |
| 60 | + |
| 61 | + @Override public void start(PluginInstance plugin, Path configDir) { |
| 62 | + LOG.info("See https://github.com/OASIS-learn-study/minecraft-storeys-maker for how to use /story and /narrate commands"); |
53 | 63 | super.start(plugin, configDir);
|
54 | 64 |
|
55 | 65 | Injector injector = pluginInjector.createChildInjector(binder -> {
|
|
60 | 70 | binder.bind(new TypeLiteral<ConfigurationLoader<CommentedConfigurationNode>>() {
|
61 | 71 | }).toInstance(configurationLoader);
|
62 | 72 | binder.bind(LocationToolListener.class);
|
| 73 | + binder.bind(Scheduler.class).toInstance(Sponge.asyncScheduler()); |
63 | 74 | });
|
64 | 75 | StaticWebServerVerticle staticWebServerVerticle = injector.getInstance(StaticWebServerVerticle.class);
|
65 | 76 |
|
66 | 77 | TokenProvider tokenProvider = injector.getInstance(TokenProvider.class);
|
67 |
| - loginCommand = new LoginCommand(tokenProvider); |
68 |
| - tokenCommand = new TokenCommand(tokenProvider); |
| 78 | + LoginCommand loginCommand = new LoginCommand(tokenProvider); |
| 79 | + TokenCommand tokenCommand = new TokenCommand(tokenProvider); |
69 | 80 |
|
| 81 | + final Optional<CommandRegistrar<Command.Parameterized>> registrar = Sponge.server().commandManager().registrar(Command.Parameterized.class); |
| 82 | + final CommandRegistrar<Command.Parameterized> commandRegistrar = registrar.get(); |
| 83 | + commandRegistrar.register(plugin.getPluginContainer(), loginCommand.createCommand(), loginCommand.getName(), loginCommand.aliases()); |
| 84 | + commandRegistrar.register(plugin.getPluginContainer(), tokenCommand.createCommand(), tokenCommand.getName(), tokenCommand.aliases()); |
70 | 85 | try {
|
71 | 86 | try {
|
72 |
| - vertxStarter = new VertxStarter(); |
| 87 | + VertxStarter vertxStarter = new VertxStarter(); |
73 | 88 | vertxStarter.deployVerticle(staticWebServerVerticle).toCompletableFuture().get();
|
74 | 89 |
|
75 | 90 | } catch (ExecutionException | InterruptedException e) {
|
|
82 | 97 | throw e;
|
83 | 98 | }
|
84 | 99 | }
|
85 |
| - |
86 |
| - @Listener public void register(RegisterCommandEvent<Command.Raw> event) { |
87 |
| - event.register(this.getPluginContainer(), |
88 |
| - (Command.Raw) loginCommand.callable(), loginCommand.aliases().get(0), loginCommand.aliases().toArray(new String[0])); |
89 |
| - } |
90 | 100 | }
|
0 commit comments