|
| 1 | +package org.mvplugins.multiverse.inventories; |
| 2 | + |
| 3 | +import org.jetbrains.annotations.NotNull; |
| 4 | +import org.mvplugins.multiverse.core.inject.PluginServiceLocator; |
| 5 | +import org.mvplugins.multiverse.inventories.config.InventoriesConfig; |
| 6 | +import org.mvplugins.multiverse.inventories.dataimport.DataImportManager; |
| 7 | +import org.mvplugins.multiverse.inventories.profile.PlayerNamesMapper; |
| 8 | +import org.mvplugins.multiverse.inventories.profile.ProfileCacheManager; |
| 9 | +import org.mvplugins.multiverse.inventories.profile.ProfileDataSource; |
| 10 | +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainerStoreProvider; |
| 11 | +import org.mvplugins.multiverse.inventories.profile.group.WorldGroupManager; |
| 12 | + |
| 13 | +import java.util.Objects; |
| 14 | + |
| 15 | +/** |
| 16 | + * Provides access to the Multiverse-Inventories API. |
| 17 | + */ |
| 18 | +public final class MultiverseInventoriesApi { |
| 19 | + |
| 20 | + private static MultiverseInventoriesApi instance; |
| 21 | + |
| 22 | + static void init(@NotNull PluginServiceLocator serviceLocator) { |
| 23 | + if (instance != null) { |
| 24 | + throw new IllegalStateException("MultiverseCoreApi has already been initialized!"); |
| 25 | + } |
| 26 | + instance = new MultiverseInventoriesApi(serviceLocator); |
| 27 | + } |
| 28 | + |
| 29 | + static void shutdown() { |
| 30 | + instance = null; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Gets the MultiverseInventoriesApi. This will throw an exception if the Multiverse-Inventories has not been initialized. |
| 35 | + * |
| 36 | + * @return The MultiverseInventoriesApi |
| 37 | + */ |
| 38 | + public static @NotNull MultiverseInventoriesApi get() { |
| 39 | + if (instance == null) { |
| 40 | + throw new IllegalStateException("MultiverseInventoriesApi has not been initialized!"); |
| 41 | + } |
| 42 | + return instance; |
| 43 | + } |
| 44 | + |
| 45 | + private final PluginServiceLocator serviceLocator; |
| 46 | + |
| 47 | + private MultiverseInventoriesApi(@NotNull PluginServiceLocator serviceProvider) { |
| 48 | + this.serviceLocator = serviceProvider; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Gets instance of our DataImportManager api. |
| 53 | + * |
| 54 | + * @return The DataImportManager instance |
| 55 | + */ |
| 56 | + public @NotNull DataImportManager getDataImportManager() { |
| 57 | + return Objects.requireNonNull(serviceLocator.getService(DataImportManager.class)); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Gets instance of our InventoriesConfig api. |
| 62 | + * |
| 63 | + * @return The InventoriesConfig instance |
| 64 | + */ |
| 65 | + public @NotNull InventoriesConfig getInventoriesConfig() { |
| 66 | + return Objects.requireNonNull(serviceLocator.getService(InventoriesConfig.class)); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Gets instance of our PlayerNamesMapper api. |
| 71 | + * |
| 72 | + * @return The PlayerNamesMapper instance |
| 73 | + */ |
| 74 | + public @NotNull PlayerNamesMapper getPlayerNamesMapper() { |
| 75 | + return Objects.requireNonNull(serviceLocator.getService(PlayerNamesMapper.class)); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Gets instance of our ProfileCacheManager api. |
| 80 | + * |
| 81 | + * @return The ProfileCacheManager instance |
| 82 | + */ |
| 83 | + public @NotNull ProfileCacheManager getProfileCacheManager() { |
| 84 | + return Objects.requireNonNull(serviceLocator.getService(ProfileCacheManager.class)); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Gets instance of our ProfileContainerStoreProvider api. |
| 89 | + * |
| 90 | + * @return The ProfileContainerStoreProvider instance |
| 91 | + */ |
| 92 | + public @NotNull ProfileContainerStoreProvider getProfileContainerStoreProvider() { |
| 93 | + return Objects.requireNonNull(serviceLocator.getService(ProfileContainerStoreProvider.class)); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Gets instance of our ProfileDataSource api. |
| 98 | + * |
| 99 | + * @return The ProfileDataSource instance |
| 100 | + */ |
| 101 | + public @NotNull ProfileDataSource getProfileDataSource() { |
| 102 | + return Objects.requireNonNull(serviceLocator.getService(ProfileDataSource.class)); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Gets instance of our WorldGroupManager api. |
| 107 | + * |
| 108 | + * @return The WorldGroupManager instance |
| 109 | + */ |
| 110 | + public @NotNull WorldGroupManager getWorldGroupManager() { |
| 111 | + return Objects.requireNonNull(serviceLocator.getService(WorldGroupManager.class)); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Gets the instance of Multiverse-Inventories's PluginServiceLocator. |
| 116 | + * <br/> |
| 117 | + * You can use this to hook into the hk2 dependency injection system used by Multiverse-Inventories. |
| 118 | + * |
| 119 | + * @return The Multiverse-Inventories's PluginServiceLocator |
| 120 | + */ |
| 121 | + public @NotNull PluginServiceLocator getServiceLocator() { |
| 122 | + return serviceLocator; |
| 123 | + } |
| 124 | +} |
0 commit comments