crwdns129751:0crwdne129751:0

crwdns129753:0crwdne129753:0

crwdns129755:0crwdne129755:0

crwdns129757:0crwdne129757:0

import org.spongepowered.api.data.DataHolder;
import org.spongepowered.api.data.DataTransactionResult;
import org.spongepowered.api.data.manipulator.mutable.entity.HealthData;
import org.spongepowered.api.data.value.mutable.MutableBoundedValue;

import java.util.Optional;

public static DataTransactionResult heal(DataHolder target) {
    Optional<HealthData> healthOptional = target.get(HealthData.class);
    if (healthOptional.isPresent()) {
        HealthData healthData = healthOptional.get();

        double maxHealth = healthData.maxHealth().get();
        MutableBoundedValue<Double> currentHealth = healthData.health();
        currentHealth.set(maxHealth);
        healthData.set(currentHealth);

        target.offer(healthData);
    }
}

crwdns129759:0:javadoc:crwdne129759:0

crwdns129761:0:javadoc:crwdnd129761:0:doc:crwdne129761:0

crwdns129763:0:javadoc:crwdnd129763:0:javadoc:crwdnd129763:0:javadoc:crwdne129763:0

Tip

crwdns129765:0crwdne129765:0

crwdns129767:0crwdne129767:0

crwdns129769:0crwdne129769:0

import org.spongepowered.api.data.manipulator.mutable.DisplayNameData;

public void removeName(DataHolder target) {
    target.remove(DisplayNameData.class);
}

crwdns129771:0crwdne129771:0

crwdns129773:0crwdne129773:0

crwdns129775:0crwdne129775:0

public void swapHealth(DataHolder targetA, DataHolder targetB) {
    if (targetA.supports(HealthData.class) && targetB.supports(HealthData.class)) {
        HealthData healthA = targetA.getOrCreate(HealthData.class).get();
        HealthData healthB = targetB.getOrCreate(HealthData.class).get();
        targetA.offer(healthB);
        targetB.offer(healthA);
    }
}

crwdns129777:0crwdne129777:0

crwdns129779:0crwdne129779:0

crwdns129781:0:javadoc:crwdne129781:0

crwdns129783:0crwdne129783:0

import org.spongepowered.api.data.manipulator.DataManipulator;

public  <T extends DataManipulator<?,?>> void swapData(DataHolder targetA, DataHolder targetB, Class<T> dataClass) {
   if (targetA.supports(dataClass) && targetB.supports(dataClass)) {
       T dataA = targetA.getOrCreate(dataClass).get();
       T dataB = targetB.getOrCreate(dataClass).get();
       targetA.offer(dataB);
       targetB.offer(dataA);
   }
}

crwdns129785:0crwdne129785:0

crwdns129787:0crwdne129787:0

crwdns129789:0:javadoc:crwdnd129789:0:javadoc:crwdne129789:0

crwdns129791:0crwdne129791:0

crwdns129793:0crwdne129793:0

crwdns129795:0crwdne129795:0

crwdns129797:0crwdne129797:0

  • crwdns129799:0crwdne129799:0

  • crwdns129801:0crwdne129801:0

crwdns129803:0crwdne129803:0

  • crwdns129805:0crwdne129805:0

  • crwdns129807:0:javadoc:crwdnd129807:0:javadoc:crwdne129807:0