|
| 1 | +# PlayerStorageAPI |
| 2 | +Allows storing to Redis/MongoDB or both if you choose! |
| 3 | +Our API quickly adds database support to your minecraft plugins. |
| 4 | +View our [Spigot Page](https://www.spigotmc.org/resources/player-storage-api-maven-version.94290/) |
| 5 | + |
| 6 | +## Installation |
| 7 | + |
| 8 | +Use the package manager [Maven](https://maven.apache.org/) to add PlayerStorageAPI as a shaded dependency. |
| 9 | + |
| 10 | +```xml |
| 11 | + <repositories> |
| 12 | + <repository> |
| 13 | + <id>jitpack.io</id> |
| 14 | + <url>https://jitpack.io</url> |
| 15 | + </repository> |
| 16 | + </repositories> |
| 17 | + |
| 18 | + <dependencies> |
| 19 | + <dependency> |
| 20 | + <groupId>com.github.hidden1nin</groupId> |
| 21 | + <artifactId>PlayerStorageAPI</artifactId> |
| 22 | + <version>2.1-SNAPSHOT</version> |
| 23 | + </dependency> |
| 24 | + </dependencies> |
| 25 | +``` |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```java |
| 30 | +import com.hiddentech.playerstorage.PlayerStorageAPI; |
| 31 | + |
| 32 | +public final class Example extends JavaPlugin { |
| 33 | + |
| 34 | + private PlayerStorageAPI playerStorageAPI; |
| 35 | + |
| 36 | + @Override |
| 37 | + public void onEnable() { |
| 38 | + //Grab an instance of the PlayerStorageAPI |
| 39 | + this.playerStorageAPI = PlayerStorageAPI.getInstance(this); |
| 40 | + |
| 41 | + //Register values you would like to store |
| 42 | + playerStorageAPI.registerValue("foo",0); |
| 43 | + playerStorageAPI.registerValue("bar","string default value"); |
| 44 | + playerStorageAPI.registerValue("test",true); |
| 45 | + } |
| 46 | + |
| 47 | + //This event fires when a players data is loaded when they join |
| 48 | + public void playerJoinEvent(PlayerDataLoad event){ |
| 49 | + //Retrieve a stored value |
| 50 | + int value = playerStorageAPI.getInt(event.getplayer().getUniqueId(),"foo"); |
| 51 | + |
| 52 | + //Update the stored value |
| 53 | + playerStorageAPI.set(event.getplayer().getUniqueId(),"foo",value+1); |
| 54 | + } |
| 55 | + |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +``` |
| 60 | +## Config |
| 61 | +Once your plugin has started it will create a second config file inside your plugins folder, |
| 62 | +```yml |
| 63 | +Redis_Connection: change this! |
| 64 | +Redis_Port: 12345 |
| 65 | +Redis_Password: and this too! |
| 66 | +Redis_Data_Expire_After: 86400 |
| 67 | +Storage_Configuration: both |
| 68 | +Mongo_DB_Name: PlayerStorageAPI |
| 69 | +Mongo_DB_ConnectionString: Change Me Too! |
| 70 | +``` |
| 71 | +You need to change the connections aswell as the passwords. |
| 72 | +If you only need Redis functionality change |
| 73 | +```yml |
| 74 | +Storage_Configuration: both |
| 75 | +``` |
| 76 | +to |
| 77 | +```yml |
| 78 | +Storage_Configuration: redis |
| 79 | +``` |
| 80 | +or to use MongoDB |
| 81 | +```yml |
| 82 | +Storage_Configuration: mongo |
| 83 | +``` |
| 84 | +If you would like to use Redis for caching and MongoDB for deep storage leave it set to both, and change the Expire Time to how long you would like data to stay cached for (in seconds). |
| 85 | +
|
| 86 | +## Contact |
| 87 | +Reach me for support/questions on discord at Hidden1nin#9457 |
| 88 | +
|
| 89 | +## License |
| 90 | +[CC](https://creativecommons.org/) |
0 commit comments