Class StorageManager
java.lang.Object
me.tayebyassine.homestead.storage.StorageManager
Central manager for all region storages.
Handles loading, saving, and caching of SharedStorage instances,
and coordinates open StorageMenu views so they stay synchronised
when the underlying storage changes.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcloseAllMenus(long regionId) Force-close all open menus for the given region.static voidclosePlayerMenus(org.bukkit.entity.Player player) Force-close all menus owned by the given player.static SharedStoragecreateStorage(long regionId, int size) Create a new empty storage for the given region and persist it.static voiddeleteStorage(long regionId) Delete the storage for the given region from both the cache and the persisted file, and close all open menus.static SharedStoragegetExistingStorage(long regionId) Get the cached storage for the given region without loading from disk.static SharedStoragegetStorage(long regionId) Get the storage for the given region, creating it from the persisted file if it is not yet cached.static booleanhasStorage(long regionId) Check whether a storage exists for the given region, either in the in-memory cache or on disk.static voidinit()Initialize the storage manager with the plugin instance and load the persisted storage file.static voidregisterMenu(long regionId, StorageMenu menu) Register an openStorageMenuso it receives updates when the underlying storage changes.static voidreplaceStorage(long regionId, SharedStorage newStorage) Replace the storage for the given region with a new instance and refresh all open menus.static voidsaveAll()Persist all cached storages to disk synchronously.static voidsaveStorage(long regionId) Persist the storage for the given region to disk asynchronously.static voidunregisterMenu(long regionId, StorageMenu menu) Unregister aStorageMenuso it no longer receives updates.static voidupdateAllMenus(long regionId) Refresh the full display of all open menus for the given region.static voidupdateSlot(long regionId, int slot) Update a single slot across all open menus for the given region.
-
Method Details
-
init
public static void init()Initialize the storage manager with the plugin instance and load the persisted storage file. -
getStorage
Get the storage for the given region, creating it from the persisted file if it is not yet cached.- Parameters:
regionId- the unique region ID- Returns:
- the shared storage instance, never
null
-
getExistingStorage
Get the cached storage for the given region without loading from disk.- Parameters:
regionId- the unique region ID- Returns:
- the cached storage, or
nullif not yet loaded
-
hasStorage
public static boolean hasStorage(long regionId) Check whether a storage exists for the given region, either in the in-memory cache or on disk.- Parameters:
regionId- the unique region ID- Returns:
trueif a storage is present
-
createStorage
Create a new empty storage for the given region and persist it.- Parameters:
regionId- the unique region IDsize- the inventory size (must be a valid Bukkit size)- Returns:
- the newly created storage
-
deleteStorage
public static void deleteStorage(long regionId) Delete the storage for the given region from both the cache and the persisted file, and close all open menus.- Parameters:
regionId- the unique region ID
-
saveStorage
public static void saveStorage(long regionId) Persist the storage for the given region to disk asynchronously.- Parameters:
regionId- the unique region ID
-
saveAll
public static void saveAll()Persist all cached storages to disk synchronously.Called during plugin shutdown to ensure no data is lost.
-
registerMenu
Register an openStorageMenuso it receives updates when the underlying storage changes.- Parameters:
regionId- the unique region IDmenu- the menu to register
-
unregisterMenu
Unregister aStorageMenuso it no longer receives updates.- Parameters:
regionId- the unique region IDmenu- the menu to unregister
-
updateAllMenus
public static void updateAllMenus(long regionId) Refresh the full display of all open menus for the given region.- Parameters:
regionId- the unique region ID
-
updateSlot
public static void updateSlot(long regionId, int slot) Update a single slot across all open menus for the given region.- Parameters:
regionId- the unique region IDslot- the inventory slot index
-
closeAllMenus
public static void closeAllMenus(long regionId) Force-close all open menus for the given region. Typically called when the storage is being deleted.- Parameters:
regionId- the unique region ID
-
closePlayerMenus
public static void closePlayerMenus(org.bukkit.entity.Player player) Force-close all menus owned by the given player. Called when the player disconnects.- Parameters:
player- the player whose menus to close
-