Hello, So first off thank you so far everyone for helping out. I’m sure if I knew where to look and how to read JavaDocs to a fault I wouldn’t nessecarily have too many questions. However I don’t, so My question today is using the below logic how would i add an ammount to the exising player’s balance?
???so i’m having difficutly with the deposit portion…
I have
("$", 50, ???)
however at cause(???) i’m drawing a blank…what would be a good cause?
PS, this is being done on an entityDeath event…however is says “The method deposit(Currency, BigDecimal, Cause) in the type Account is not applicable for the arguments (String, int, DestructEntityEvent.Death)”
Thanks
A real easy cause is to get your PluginContainer and then just call Cause.source(container).build(). But check your other two arguments; they need to be a Currency and a BigDecimal, not a String and an int (just like the error says).
@Listener
public void MobDeath(DestructEntityEvent.Death event, @First EntityDamageSource src, @Before(PluginContainer.class) Cause cause){
Entity killer = src.getSource();
if ((killer instanceof Player)){
Player player = (Player)killer;
String player2 = player.getUniqueId().toString();
if(event.getTargetEntity().getType().equals(EntityTypes.BAT)){
player.sendMessage(Text.of("You Killed a chicken & earned some Money"));
Cause.source(cause).build();
BigDecimal bd = new BigDecimal("50");
this.economyService.getOrCreateAccount(player2).get().deposit(economyService.getDefaultCurrency(), bd, cause);
}
}
}
}
…so what i’m trying to do is get the dependancy set up for EconomyLite…so how would i set this up from here…mind you there is no other code yet written besides fore this. So there is no PluginContainer besides for the id name and version. Because i’m not understanding it. A little help would b appreiciated. I know some of the rest of the code mainly at the deposit isn’t finished. But that’s cause i’m trying to figure out how to set the cause up.
… I’m not sure what you’re attempting to do here. Regardless, the PluginContainer isn’t something you get from a Cause, it’s something you inject. Or you could get it from the PluginManager.
You don’t hook into an Economy plugin directly, you only use the economy service and the plugin that implements the economy api takes care of the rest.
For the Cause you need to provide your plugin’s PluginContainer which could be done as below in your main plugin class:
Also you’re not exactly building your cause correctly.
The first thing you need is your PluginContainer but you should always add more causes if available, this can be just about any object such as an entity, a block, an item, etc.
With your example, here’s how I would construct the Cause.
Cause cause = Cause.of(NamedCause.source(Plugin.getInstance().getPluginContainer()), NamedCause.owner(event.getTargetEntity()));
EDIT: I highly recommend giving this a read to learn more about causes and how they work.
here’s what What I have The error log is inside…it’s telling me that (or what I understand) that the Cause is null… so My question is where did I not set this correctly? please help thank you.
Ok but if I take out the static then in the Eco class i gent an error over the HOB.getPluginContainer() Portion of the text. The error becomes:
So how would i then go about calling the non static inject into the static class of EcoRewards?
Ok however I’m still getting an error when i do that and actually do kill the bat…mind you it’s giving the message like it should. however then it still states this Error log
Well, the only two things that you have defined on that line are HOB.getInstance and HOB#getPluginContainer. And your class is the first stack frame, not second or third, meaning it can’t be HOB#getPluginContainer because otherwise Cause would be throwing the NPE. Therefore, HOB.getInstance() is returning null.