|
1 | 1 | package pl.mrstudios.deathrun.api; |
2 | 2 |
|
3 | | -import org.bukkit.plugin.PluginDescriptionFile; |
4 | 3 | import org.jetbrains.annotations.NotNull; |
| 4 | +import org.jetbrains.annotations.Nullable; |
5 | 5 | import pl.mrstudios.deathrun.api.arena.IArena; |
6 | 6 | import pl.mrstudios.deathrun.api.arena.trap.ITrapRegistry; |
7 | 7 |
|
8 | | -public class API { |
| 8 | +import static com.google.common.base.Preconditions.checkArgument; |
| 9 | +import static com.google.common.base.Preconditions.checkNotNull; |
| 10 | +import static org.jetbrains.annotations.ApiStatus.Internal; |
| 11 | +import static org.jetbrains.annotations.ApiStatus.ScheduledForRemoval; |
9 | 12 |
|
10 | | - private final @NotNull IArena arena; |
11 | | - private final @NotNull ITrapRegistry trapRegistry; |
| 13 | +public record API( |
| 14 | + @NotNull IArena arenaInstance, |
| 15 | + @NotNull ITrapRegistry trapRegistryInstance |
| 16 | +) { |
12 | 17 |
|
13 | | - private final @NotNull String version; |
| 18 | + @Deprecated( |
| 19 | + forRemoval = true, |
| 20 | + since = "1.3.0" |
| 21 | + ) |
| 22 | + @ScheduledForRemoval(inVersion = "1.4.0") |
| 23 | + public @NotNull IArena getArena() { |
| 24 | + return this.arenaInstance(); |
| 25 | + } |
14 | 26 |
|
15 | | - public API( |
16 | | - @NotNull IArena arena, |
17 | | - @NotNull ITrapRegistry trapRegistry, |
18 | | - @NotNull PluginDescriptionFile pluginDescriptionFile |
19 | | - ) { |
| 27 | + @Deprecated( |
| 28 | + forRemoval = true, |
| 29 | + since = "1.3.0" |
| 30 | + ) |
| 31 | + @ScheduledForRemoval(inVersion = "1.4.0") |
| 32 | + public @NotNull ITrapRegistry getTrapRegistry() { |
| 33 | + return this.trapRegistryInstance(); |
| 34 | + } |
20 | 35 |
|
21 | | - setInstance(this); |
| 36 | + @Deprecated( |
| 37 | + forRemoval = true, |
| 38 | + since = "1.3.0" |
| 39 | + ) |
| 40 | + @ScheduledForRemoval(inVersion = "1.4.0") |
| 41 | + public @NotNull String getVersion() { |
| 42 | + return pluginVersion(); |
| 43 | + } |
22 | 44 |
|
23 | | - this.arena = arena; |
24 | | - this.trapRegistry = trapRegistry; |
25 | | - this.version = pluginDescriptionFile.getVersion(); |
| 45 | + @Deprecated( |
| 46 | + forRemoval = true, |
| 47 | + since = "1.3.0" |
| 48 | + ) |
| 49 | + @ScheduledForRemoval(inVersion = "1.4.0") |
| 50 | + public static @Nullable API instance; |
26 | 51 |
|
| 52 | + /* Version Related */ |
| 53 | + public @NotNull String pluginVersion() { |
| 54 | + return "{version}"; |
27 | 55 | } |
28 | 56 |
|
29 | | - public @NotNull IArena getArena() { |
30 | | - return arena; |
| 57 | + public @NotNull String pluginGitBranch() { |
| 58 | + return "{gitBranch}"; |
31 | 59 | } |
32 | 60 |
|
33 | | - public @NotNull ITrapRegistry getTrapRegistry() { |
34 | | - return trapRegistry; |
| 61 | + public @NotNull String pluginGitCommit() { |
| 62 | + return "{gitCommitHash}"; |
35 | 63 | } |
36 | 64 |
|
37 | | - public @NotNull String getVersion() { |
38 | | - return version; |
| 65 | + /* Static Methods */ |
| 66 | + public static @NotNull API apiInstance() { |
| 67 | + return checkNotNull(instance, "Instance of API is not initialized yet!"); |
39 | 68 | } |
40 | 69 |
|
41 | | - public static @NotNull API instance; |
42 | | - |
43 | | - protected static void setInstance(@NotNull API api) { |
44 | | - instance = api; |
| 70 | + @Internal |
| 71 | + public static void createInstance( |
| 72 | + @NotNull IArena arenaInstance, |
| 73 | + @NotNull ITrapRegistry trapRegistryInstance |
| 74 | + ) { |
| 75 | + checkArgument(instance == null, "Instance of API is already initialized!"); |
| 76 | + instance = new API( |
| 77 | + arenaInstance, |
| 78 | + trapRegistryInstance |
| 79 | + ); |
45 | 80 | } |
46 | 81 |
|
47 | 82 | } |
0 commit comments