Skip to content

[Request] Add Sponge Economy API support #2

Description

@SirFancyBacon

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

Activity

  1. SirFancyBacon commented on May 12, 2020

    @SirFancyBacon
    Author

    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.
          }
    
    
  2. obr-09 commented on Jul 18, 2020

    @obr-09
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions