diff --git a/User-data.md b/User-data.md new file mode 100644 index 0000000..d6857ea --- /dev/null +++ b/User-data.md @@ -0,0 +1,22 @@ +To manage user data, the plugin provides two abstract classes that can be extended. These, named after our server, are ChromaGamerBase for any user and TBMCPlayerBase for a Minecraft player. The plugin stores each type of user's data in a different folder, for example the Minecraft player data goes to the `minecraft` folder while a Discord user's data goes to the `discord` folder. Each class that extends TBMCPlayerBase will get its own section in the player's file, so all plugin data can be reached by using the player's UUID. + +If you make a new user class (for a new platform), it must have a @UserClass or @AbstractUserClass annotation defining the folder name. You also need to register user classes (but not MC player classes) with TBMCCoreAPI.RegisterUserClass(). If you make a Minecraft player class, it must have a @PlayerClass annotation defining the section's name in the player's file. + +Then you can define fields in that class to get and set player data like so: + +``` +public final ConfigData somethingToStore = getConfig().getData("somethingToStore", "defaultValue"); +``` + +Then this field can be used as `somethingToStore.get()` or `somethingToStore.set("value")` and any changes will be saved automatically to the file in a couple of seconds. See the Config/Data page for more details. + +To get users of a given type, use `ChromaGamerBase.getUser("TheIDYouWantToUse", YourClass.class);`. This will automatically save into `TBMC/players/YourFolderName/TheIDYouWantToUse.yml`. To get Minecraft players, you can also use `TBMCPlayerBase.getPlayer(playerUUID, YourClass.class);`. Each instance will be cached for 2 hours, except Minecraft players which are cached while they are online. + +## Connecting users +If you have different user classes, they can be connected together. This is used for connecting Discord and Minecraft accounts. First, get both user classes, then use the connectWith() method: +``` +DiscordPlayer dp = ChromaGamerBase.getUser(did, DiscordPlayer.class); +TBMCPlayer mcp = TBMCPlayerBase.getPlayer(player.getUniqueId(), TBMCPlayer.class); +dp.connectWith(mcp); +``` +Then you can use `mcp.getAs(DiscordPlayer.class)` to get the Discord user from the Minecraft player for example. \ No newline at end of file