|
1 | 1 | package com.eternalcode.example; |
2 | 2 |
|
| 3 | +import com.eternalcode.example.command.ReloadCommand; |
| 4 | +import com.eternalcode.example.command.SwitchCommand; |
| 5 | +import com.eternalcode.example.config.ConfigurationManager; |
| 6 | +import com.eternalcode.example.config.MessagesConfig; |
| 7 | +import com.eternalcode.example.notice.ExampleMultification; |
3 | 8 | import com.google.inject.Inject; |
| 9 | +import com.velocitypowered.api.command.CommandSource; |
| 10 | +import com.velocitypowered.api.event.Subscribe; |
4 | 11 | import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; |
| 12 | +import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; |
5 | 13 | import com.velocitypowered.api.plugin.Plugin; |
| 14 | +import com.velocitypowered.api.plugin.annotation.DataDirectory; |
6 | 15 | import com.velocitypowered.api.proxy.ProxyServer; |
| 16 | +import dev.rollczi.litecommands.LiteCommands; |
| 17 | +import dev.rollczi.litecommands.velocity.LiteVelocityFactory; |
| 18 | + |
| 19 | +import java.nio.file.Path; |
7 | 20 |
|
8 | 21 | @Plugin( |
9 | 22 | id = "example-velocity-plugin", |
|
15 | 28 | public class ExampleVelocityPlugin { |
16 | 29 |
|
17 | 30 | private final ProxyServer server; |
| 31 | + private final Path dataDirectory; |
| 32 | + |
| 33 | + private LiteCommands<CommandSource> liteCommands; |
18 | 34 |
|
19 | 35 | @Inject |
20 | | - public ExampleVelocityPlugin(ProxyServer server) { |
| 36 | + public ExampleVelocityPlugin(ProxyServer server, @DataDirectory Path dataDirectory) { |
21 | 37 | this.server = server; |
| 38 | + this.dataDirectory = dataDirectory; |
22 | 39 | } |
23 | 40 |
|
| 41 | + @Subscribe |
24 | 42 | void onProxyInitialize(ProxyInitializeEvent event) { |
| 43 | + MessagesConfig messagesConfig = new MessagesConfig(); |
| 44 | + ExampleMultification multification = new ExampleMultification((Plugin) this, this.server, messagesConfig); |
| 45 | + |
| 46 | + ConfigurationManager configurationManager = new ConfigurationManager(this.dataDirectory.toFile(), |
| 47 | + multification.getNoticeRegistry()); |
| 48 | + configurationManager.load(messagesConfig, "messages.yml"); |
| 49 | + |
| 50 | + this.liteCommands = LiteVelocityFactory.builder(this.server) |
| 51 | + .commands( |
| 52 | + new ReloadCommand(configurationManager, multification), |
| 53 | + new SwitchCommand(multification)) |
| 54 | + .build(); |
| 55 | + |
| 56 | + this.server.getEventManager().register(this, new PlayerConnectListener(multification)); |
| 57 | + } |
25 | 58 |
|
| 59 | + @Subscribe |
| 60 | + void onProxyShutdown(ProxyShutdownEvent event) { |
| 61 | + if (this.liteCommands != null) { |
| 62 | + this.liteCommands.unregister(); |
| 63 | + } |
26 | 64 | } |
27 | 65 | } |
0 commit comments