|
1 | 1 | package dev.faststats.velocity; |
2 | 2 |
|
| 3 | +import com.google.inject.Inject; |
| 4 | +import com.velocitypowered.api.plugin.PluginContainer; |
3 | 5 | import com.velocitypowered.api.plugin.annotation.DataDirectory; |
4 | 6 | import com.velocitypowered.api.proxy.ProxyServer; |
5 | 7 | import dev.faststats.Config; |
6 | | -import dev.faststats.FastStatsContext; |
| 8 | +import dev.faststats.SimpleContext; |
7 | 9 | import dev.faststats.Token; |
8 | 10 | import dev.faststats.config.SimpleConfig; |
9 | 11 | import org.slf4j.Logger; |
|
15 | 17 | * |
16 | 18 | * @since 0.23.0 |
17 | 19 | */ |
18 | | -public final class VelocityContext extends FastStatsContext { |
| 20 | +public final class VelocityContext extends SimpleContext { |
| 21 | + private final PluginContainer plugin; |
19 | 22 | private final ProxyServer server; |
20 | 23 | private final Logger logger; |
21 | 24 | private final Path dataDirectory; |
22 | 25 |
|
23 | 26 | public VelocityContext( |
24 | 27 | final Config config, |
| 28 | + final PluginContainer plugin, |
25 | 29 | final ProxyServer server, |
26 | 30 | final Logger logger, |
27 | 31 | final Path dataDirectory, |
28 | 32 | @Token final String token |
29 | 33 | ) { |
30 | 34 | super(config, token); |
| 35 | + this.plugin = plugin; |
31 | 36 | this.server = server; |
32 | 37 | this.logger = logger; |
33 | 38 | this.dataDirectory = dataDirectory; |
34 | 39 | } |
35 | 40 |
|
36 | 41 | public VelocityContext( |
| 42 | + final PluginContainer plugin, |
37 | 43 | final ProxyServer server, |
38 | 44 | final Logger logger, |
39 | 45 | @DataDirectory final Path dataDirectory, |
40 | 46 | @Token final String token |
41 | 47 | ) { |
42 | | - this(SimpleConfig.read(dataDirectory.resolveSibling("faststats").resolve("config.properties")), server, logger, dataDirectory, token); |
| 48 | + this(SimpleConfig.read(dataDirectory.resolveSibling("faststats").resolve("config.properties")), plugin, server, logger, dataDirectory, token); |
43 | 49 | } |
44 | 50 |
|
45 | 51 | @Override |
46 | 52 | public VelocityMetrics.Factory metrics() { |
47 | | - return new VelocityMetrics.Factory(this, server, logger, dataDirectory); |
| 53 | + return new VelocityMetrics.Factory(this, plugin, server, logger, dataDirectory); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Injectable Velocity context builder. |
| 58 | + * |
| 59 | + * @since 0.23.0 |
| 60 | + */ |
| 61 | + public static final class Builder { |
| 62 | + private final PluginContainer plugin; |
| 63 | + private final ProxyServer server; |
| 64 | + private final Logger logger; |
| 65 | + private final Path dataDirectory; |
| 66 | + |
| 67 | + /** |
| 68 | + * Creates a new Velocity context builder. |
| 69 | + * |
| 70 | + * @param server the velocity server |
| 71 | + * @param logger the plugin logger |
| 72 | + * @param dataDirectory the plugin data directory |
| 73 | + * @apiNote This instance can be injected into your plugin. |
| 74 | + * @since 0.23.0 |
| 75 | + */ |
| 76 | + @Inject |
| 77 | + public Builder( |
| 78 | + final PluginContainer plugin, |
| 79 | + final ProxyServer server, |
| 80 | + final Logger logger, |
| 81 | + @DataDirectory final Path dataDirectory |
| 82 | + ) { |
| 83 | + this.plugin = plugin; |
| 84 | + this.server = server; |
| 85 | + this.logger = logger; |
| 86 | + this.dataDirectory = dataDirectory; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Builds the finalized Velocity context. |
| 91 | + * |
| 92 | + * @param token the FastStats project token |
| 93 | + * @return the Velocity context |
| 94 | + * @throws IllegalArgumentException if the token is invalid |
| 95 | + * @since 0.23.0 |
| 96 | + */ |
| 97 | + public VelocityContext build(@Token final String token) throws IllegalArgumentException { |
| 98 | + return new VelocityContext(plugin, server, logger, dataDirectory, token); |
| 99 | + } |
48 | 100 | } |
49 | 101 | } |
0 commit comments