Proper way to heal a player

What is the proper way to heal a player. I can’t use HealthData because it’s an abstract class.

HealthData is the correct thing to use, your heal method would look something like this:

public void heal(Player player) {
    HealthData health = player.getHealthData();
    health.setHealth(health.getMaxHealth());
    player.offer(health);
}

I think it would actually be living.setHealthData. Living is the only class I can find with any health function, but you can’t set it. Looked through the API code myself

Nope the snipit that I wrote is correct. There is no ‘Living.setHealthData’ all data manipulators are set back to their holders with the offer method.

If you are basing the fact that I am incorrect on it throwing an AbstractMethodError that is because it is not yet implemented, but will be soon.

1 Like

As far as I understand, Entity.offer is used to set the changed data of an entity or is it just for the health data?

Offer is for all data.

1 Like

Abstract class just means that it is not implemented yet.

Uhm, no? Abstract class means that you cannot instantiate it. It means you’ll have to use a subclass that is not abstract to create an instance.
An abstract class is very much implemented.

2 Likes

That’s strange, I thought you had to do

Player.getData(HealthData.class).get().getHealth()

or something

That is the same thing, getHealthData is just a short-cut

See

So I saw that the Health Data got implemented and decided to test it out but I still get the abstraction error. This is what I am trying to do.

Here.

This is the error I am getting.

Here

I am using Sponge Forge, the latest build.

It Looks like it’s not implemented yet.

hmm, how can I use this?

It’s implemented, but the entity.getHealthData shortcut method isn’t.

Try the full Player.getData(HealthData.class).get()

1 Like

Yep, that works!