-
Notifications
You must be signed in to change notification settings - Fork 82
Developer API
This document outlines the basics of how plugin developers can use multiverse-inventories to both add custom shares to be used by their plugins, as well as how to use multiverse-inventories to check for a default or a share setup by another plugin.
-
Create a class for the static sharable definitions to go
public class MySharables { }
-
Decide what data the sharable will store.
If my plugin was an economy plugin i would use the Double type so that I could store the amount for each player
If I have a plugin that gives backpacks, I would use an array of ItemStack as the type because thats what is stored.
If I had something like a custom set of data per player, I could also write a custom class and use that.
-
Create a Sharable definition in your class. In this case I will use an ItemStack array, as its it will be for a custom inventory.
public class MySharables { public static final Sharable<ItemStack[]> MySharable = new Sharable.Builder<ItemStack[]>("mySharable", ItemStack[].class, new SharableHandler<ItemStack[]>() { @Override public void updateProfile(PlayerProfile profile, Player player) { profile.set(MySharable, player.getInventory().getContents()); } @Override public boolean updatePlayer(Player player, PlayerProfile profile) { ItemStack[] value = profile.get(MySharable); if ( value == null ) { return false; } player.getInventory().setContents(value); player.updateInventory(); return true; } }).stringSerializer(new ProfileEntry(false, "mySharable")).altName("ms").build(); }
The final ProfileEntry string defines the name in the config file itself, not just internally. The altName(String) function allows you to specify other values in the config file that would equate to the same internal name for the share.
Unfinished Wiki, Saving for tomorrow
Unfinished Wiki, Saving for tomorrow