Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Add Sponge Economy API support #2

Open
SirFancyBacon opened this issue Mar 3, 2020 · 2 comments
Open

[Request] Add Sponge Economy API support #2

SirFancyBacon opened this issue Mar 3, 2020 · 2 comments

Comments

@SirFancyBacon
Copy link

I will be first to admit i have never written a line of Java in my life!

But i believe this captures the idea of what i mean, and how it works.

// sponge things
import "org.spongepowered.api.Sponge";
import "org.spongepowered.api.service.economy.EconomyService";
// java things
import "java.util.UUID";
import "java.math.BigDecimal";

var uuid = //whatever the uuid of player whoever killed it
var value = //value pulled from monsters.conf

public class spongeEconomyDeposit(uuid,value){
    var account = org.spongepowered.api.service.economy.EconomyService.getOrCreateAccount(UUID.fromString(uuid)) //gets Economy Account for the Player.
    var value = java.util.UUID(value) //value in () is value to be deposited.
    var currency = org.spongepowered.api.service.economy.EconomyService.getDefaultCurrency() //gets DefaultCurrency of the Economy Plugin
    var cause = org.spongepowered.api.Sponge.getCauseStackManager().getCurrentCause() //gets the Cause Manager from Sponge

        account.get().deposit(currency,value,cause) //deposit amount of value into players account.
}

https://docs.spongepowered.org/stable/en/plugin/economy/index.html

@SirFancyBacon
Copy link
Author

SirFancyBacon commented May 12, 2020

I definitely know this will not work.. But to expand upon the above into more Java-esque syntax.

import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.service.economy.account.UniqueAccount;
import java.math.BigDecimal;
import java.util.Optional;
import com.onaple.brawlator.events.BrawlatorEntityDiedEvent;
import com.onaple.brawlator.BrawlatorKeys;


      Optional<EconomyService> serviceOpt = Sponge.getServiceManager().provide(EconomyService.class);
      if (serviceOpt.isPresent()) {
              EconomyService economyService = serviceOpt.get();
              //Do stuff wheb a Mob dies below this line...
              Account account = economyService.getOrCreateAccount(UUID.fromString(getPlayer.getUUID()); //gets Economy Account for the Player. **Need to get UUID of player that killed Mob this probably won't work.
              BigDecimal depositAmount = BigDecimal.valueOf(BrawlatorKeys.CURRENCYDROP); //Loads data from Brawlator Config for amount of currency to drop. **Needs configuration in Brawlator.
                        if (depositAmount.isPresent()) {
                            account.deposit(economyService.getDefaultCurrency(),depositAmount,Sponge.getCauseStackManager().getCurrentCause()); //Think this should work but honestly it's untested; should also add a cause since it'll just do it when the code runs.
                        }
      }else{
        log("No Economy plugin detected... Skipping Economy Support"); //can you use log in Java? needs testing.
      }

@obr-09
Copy link
Member

obr-09 commented Jul 18, 2020

It is definitely doable if it is among the Sponge library features!
We would probably add the money property (or interval if randomly picked between x and y) in the monster configuration. (We could also consider it like a loot in the loot tables for more control... But I believe this would be more confusing)

Not a very hard task either I believe. Will see what I can do next time I work on this

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

No branches or pull requests

2 participants