|
1 | | -# StorageManager API |
| 1 | +<p align="center"> |
| 2 | + <img src="./src/main/resources/assets/storagemanager-api/icon.png" width="128" alt="StorageManager API Icon"/> |
| 3 | +</p> |
2 | 4 |
|
3 | | -The StorageManager API provides a set of functions to manage and interact with different storage systems. It allows users to perform operations such as creating, reading, updating, and deleting data in a structured manner. |
| 5 | +<h1 align="center"> |
| 6 | +StorageManager API |
| 7 | +</h1> |
| 8 | + |
| 9 | +<p align="center"> |
| 10 | + <a href="https://github.com/superstrellaa/StorageManager-API/releases"> |
| 11 | + <img src="https://img.shields.io/github/v/release/superstrellaa/StorageManagerAPI?style=flat-square" /> |
| 12 | + </a> |
| 13 | + <img src="https://img.shields.io/badge/Minecraft-1.21-blue?style=flat-square" /> |
| 14 | + <img src="https://img.shields.io/badge/Loader-Fabric-blueviolet?style=flat-square" /> |
| 15 | + <a href="https://github.com/superstrellaa/StorageManager-API/issues"> |
| 16 | + <img src="https://img.shields.io/github/issues/superstrellaa/StorageManager-API?style=flat-square" /> |
| 17 | + </a> |
| 18 | + <img src="https://img.shields.io/github/license/superstrellaa/StorageManager-API?style=flat-square" /> |
| 19 | +</p> |
| 20 | + |
| 21 | +The **StorageManager API** provides an easy way to manage persistent storage for your mods. It allows you to create, read, update, and delete structured data in an efficient, server-friendly way. By default, it uses **SQLite** as the storage backend with write-behind caching for high performance. |
| 22 | + |
| 23 | +--- |
4 | 24 |
|
5 | 25 | ## Features |
6 | | -- Create, read, update, and delete data in various storage systems. |
7 | | -- Using SQLite as the default storage backend. |
8 | | -- Easy-to-use interface for managing storage operations in your own mod. |
9 | 26 |
|
10 | | -//TODO |
| 27 | +- Create, read, update, and delete data in your mods. |
| 28 | +- Async write caching to improve performance. |
| 29 | +- Built-in support for global and player-specific data. |
| 30 | +- Easy-to-use API with minimal boilerplate. |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## Important Notes |
| 35 | + |
| 36 | +- Do **not** touch the `.internal` package. It is meant for internal use only. It also contains tags ApiStatus.Internal. |
| 37 | +- The API is **server-side only**: |
| 38 | + - On client-side, the API does nothing and will only produce warnings if used. |
| 39 | + - Always call storage operations after the server has started. |
| 40 | +- There is no Maven repository for this mod yet. You must manually include the JAR in your project. |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +## Installation |
| 45 | + |
| 46 | +1. Download the **StorageManager API** JAR. |
| 47 | +2. In your mod project (where you have `build.gradle` and `gradle.properties`), create a folder called `lib`. |
| 48 | +3. Place the JAR inside the `lib` folder. |
| 49 | +4. Add the following to your `build.gradle`: |
| 50 | + |
| 51 | +``` gradle |
| 52 | +repositories { |
| 53 | + flatDir { |
| 54 | + dirs 'lib' |
| 55 | + } |
| 56 | +} |
| 57 | +
|
| 58 | +dependencies { |
| 59 | + modImplementation(name: "storagemanager-api-1.0.0+1.21.1") |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +5. Rebuild your project. The API is now ready to use. |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## 📝 Usage Examples |
| 68 | + |
| 69 | +### Registering Tables |
| 70 | + |
| 71 | +``` java |
| 72 | +StorageManager.registerTable( |
| 73 | + TableSchema.builder("global_data") |
| 74 | + .column("key", ColumnType.TEXT, true) |
| 75 | + .column("value", ColumnType.INTEGER) |
| 76 | + .primaryKey("key") |
| 77 | + .build() |
| 78 | +); |
| 79 | + |
| 80 | +StorageManager.registerTable( |
| 81 | + TableSchema.builder("player_data") |
| 82 | + .column("uuid", ColumnType.TEXT, true) |
| 83 | + .column("key", ColumnType.TEXT, true) |
| 84 | + .column("value", ColumnType.INTEGER) |
| 85 | + .primaryKey("uuid", "key") |
| 86 | + .build() |
| 87 | +); |
| 88 | +``` |
| 89 | + |
| 90 | +### Inserting Data |
| 91 | + |
| 92 | +``` java |
| 93 | +StorageManager.insert("global_data", new RowData() |
| 94 | + .set("key", "time") |
| 95 | + .set("value", 100) |
| 96 | +); |
| 97 | + |
| 98 | +StorageManager.insert("player_data", new RowData() |
| 99 | + .set("uuid", player.getUuidAsString()) |
| 100 | + .set("key", "points") |
| 101 | + .set("value", 50) |
| 102 | +); |
| 103 | +``` |
| 104 | + |
| 105 | +### Reading Data |
| 106 | + |
| 107 | +``` java |
| 108 | +var rows = StorageManager.select("player_data", Map.of( |
| 109 | + "uuid", player.getUuidAsString(), |
| 110 | + "key", "points" |
| 111 | +)); |
| 112 | + |
| 113 | +for (var row : rows) { |
| 114 | + int points = (Integer) row.values().get("value"); |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +### Updating / Deleting Data |
| 119 | + |
| 120 | +``` java |
| 121 | +StorageManager.delete("global_data", Map.of("key", "time")); |
| 122 | + |
| 123 | +StorageManager.insertImmediate("player_data", new RowData() |
| 124 | + .set("uuid", player.getUuidAsString()) |
| 125 | + .set("key", "points") |
| 126 | + .set("value", 75) |
| 127 | +); |
| 128 | +``` |
| 129 | + |
| 130 | +### Flush Cache |
| 131 | + |
| 132 | +``` java |
| 133 | +StorageManager.flushAll(); |
| 134 | +``` |
0 commit comments