-
Notifications
You must be signed in to change notification settings - Fork 2
StatShops API
StatShops provides an abstract StatShopsExtension class. To provide your own Currencies, DynamicPricing Values, Articles, Entry Modules or Shop Types, you can create your own class that overrides the empty methods of the StatShopsExtension class. StatShops will load all Extensions that have been registered before it was enabled. Therefore it is important that you dont forget to put StatShops on "load-before" in your plugin.yml and that you register your Extension with
StatShops.registerExtension(myExtensionInstance);
StatShops enables its compatibility with vault through its own instance of the StatShopsExtension class. You can check it out as a reference. TODO link
Your extension might require some messages. Since StatShops allows administrators to choose a language, you can register messages at the TranslationHandler. They will be then loaded from the language.yml. You can also provide a default message that will be written to the current language.yml if the message could not be loaded.
StatShopsExtension provides a method that you can override:
@Override
public void registerMessages(TranslationHandler translationHandler) {
super.registerMessages(translationHandler);
translationHandler.registerMessages(all, the, messages, you, need);
}
If you want to register a currency like gems to StatShops, you first need to create a StatShops Currency. Don't forget to also register the Article and Costs submodules! Currencies define the way a transaction is to be handled. For example, there is an ItemStack currency that describes the giving and taking of items. If your currency is not object-bound but virtual (e.g. Vault), you don't need a type parameter. Otherwise, the type parameter is the treated object type. If you want to introduce a currency where a customer has to pay with mobs leashed to his hand, the type parameter would be "Entity" and the getAmount() method would count the leashed mobs. If one wants to pay with items of a certain material, independent of its other attributes, the type parameter would be "Material" and getAmount() would only count the amount of items in the players inventory of the given type.
@Override
public void registerCurrencies(CurrencyHandler currencyHandler) {
super.registerCurrencies(currencyHandler);
CURRENCY_VAULT = new Currency<>(
"money",
StatShops.getInstance().getShopsConfig().getCurrencyVaultFormatting(),
StatShops.getInstance().getShopsConfig().getCurrencyVaultFormattingDiscounted(),
(integer, unused) -> Component.text(integer == 1 ? economy.currencyNameSingular() : economy.currencyNamePlural())
) {
@Override
public double applyDiscount(double amount, double discount) {
return amount * discount;
}
@Override
public double getAmount(Customer customer, Void object) {
return economy.getBalance(customer.getPlayer());
}
@Override
public boolean addAmount(Customer customer, double amount, Void object) {
return economy.depositPlayer(customer.getPlayer(), amount).transactionSuccess();
}
@Override
public boolean removeAmount(Customer customer, double amount, Void object) {
return economy.withdrawPlayer(customer.getPlayer(), amount).transactionSuccess();
}
};
currencyHandler.registerCurrency(CURRENCY_VAULT);
}
The last constructor parameter converts the amount into the singular or plural Component of your currency. In case of an ItemStack as object it might also convert the ItemStack into a translatable Component.
StatShops supports the usage of dynamic prices. This includes placeholders like db:diamond, which will be replaced by the default_values.yml in the root directory. Your plugin can provide pricings to be parsed. Dynamic pricings might be used to get the count of a certain itemstack in a players inventory or to get the online player count. Placeholders registered by your plugin have to be keyed and will be placed in the format <:>, e.g. vault:max_amount