Skip to content

Conversation

@federkone
Copy link

Hello! I would like to know if we could add the following extension, which is quite simple but useful for economic systems that want to have a multiple currency flow. Current consumers will not be affected by this new feature since it is only an extension that could be used OR not without interrupting the workflow.

import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyMultiCurrency;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicesManager;

import static org.bukkit.Bukkit.getServer;

public class ExampleUseApi{
    private EconomyMultiCurrency economyMultiCurrency;
    private Economy economy;

    private void setupEconomyExample1() {
        ServicesManager serviceManager = Bukkit.getServicesManager();

        if (getServer().getPluginManager().getPlugin("Vault") != null) {
            
            RegisteredServiceProvider<Economy> serviceVaultEconomy = serviceManager.getRegistration(Economy.class); //Vault v1.7.3 and earlier
            RegisteredServiceProvider<EconomyMultiCurrency> serviceVaultEconomyMultiCurrency = serviceManager.getRegistration(EconomyMultiCurrency.class); //EconomyMultiCurrency extends Economy
            if (serviceVaultEconomy != null) {
                economy = serviceVaultEconomy.getProvider();
            }
            if (serviceVaultEconomyMultiCurrency != null) {
                economyMultiCurrency = serviceVaultEconomyMultiCurrency.getProvider();
            }
        }
    }
    //If you want, you can only capture EconomyMulticurrency since it extends Economy
    // This feature will allow us to inject EconomyMultiCurrency into existing systems that consume Economy.class
    //Example:
    private void setUpEconomyExample2(){
        ServicesManager serviceManager = Bukkit.getServicesManager();
        if (getServer().getPluginManager().getPlugin("Vault") != null) {
            
            RegisteredServiceProvider<EconomyMultiCurrency> serviceVaultEconomyMultiCurrency = serviceManager.getRegistration(EconomyMultiCurrency.class);
            if (serviceVaultEconomyMultiCurrency != null) {
                economyMultiCurrency = serviceVaultEconomyMultiCurrency.getProvider();
                economy = economyMultiCurrency; //EconomyMultiCurrency unboxing to Economy
            }
        }
    }
}

@creatorfromhell
Copy link
Contributor

Hello! I would like to know if we could add the following extension, which is quite simple but useful for economic systems that want to have a multiple currency flow. Current consumers will not be affected by this new feature since it is only an extension that could be used OR not without interrupting the workflow.

import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyMultiCurrency;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicesManager;

import static org.bukkit.Bukkit.getServer;

public class ExampleUseApi{
    private EconomyMultiCurrency economyMultiCurrency;
    private Economy economy;

    private void setupEconomyExample1() {
        ServicesManager serviceManager = Bukkit.getServicesManager();

        if (getServer().getPluginManager().getPlugin("Vault") != null) {
            
            RegisteredServiceProvider<Economy> serviceVaultEconomy = serviceManager.getRegistration(Economy.class); //Vault v1.7.3 and earlier
            RegisteredServiceProvider<EconomyMultiCurrency> serviceVaultEconomyMultiCurrency = serviceManager.getRegistration(EconomyMultiCurrency.class); //EconomyMultiCurrency extends Economy
            if (serviceVaultEconomy != null) {
                economy = serviceVaultEconomy.getProvider();
            }
            if (serviceVaultEconomyMultiCurrency != null) {
                economyMultiCurrency = serviceVaultEconomyMultiCurrency.getProvider();
            }
        }
    }
    //If you want, you can only capture EconomyMulticurrency since it extends Economy
    // This feature will allow us to inject EconomyMultiCurrency into existing systems that consume Economy.class
    //Example:
    private void setUpEconomyExample2(){
        ServicesManager serviceManager = Bukkit.getServicesManager();
        if (getServer().getPluginManager().getPlugin("Vault") != null) {
            
            RegisteredServiceProvider<EconomyMultiCurrency> serviceVaultEconomyMultiCurrency = serviceManager.getRegistration(EconomyMultiCurrency.class);
            if (serviceVaultEconomyMultiCurrency != null) {
                economyMultiCurrency = serviceVaultEconomyMultiCurrency.getProvider();
                economy = economyMultiCurrency; //EconomyMultiCurrency unboxing to Economy
            }
        }
    }
}

Hello, Vault is more or less inactive, LlmDl and I made a fork that has been gaining traction and has multicurrency support called VaultUnlocked. https://github.com/TheNewEconomy/VaultUnlockedAPI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants