crwdns148989:0crwdne148989:0

crwdns148991:0crwdne148991:0

crwdns148993:0crwdne148993:0

crwdns148995:0crwdne148995: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);
    }
}

crwdns148997:0:javadoc:crwdne148997:0

crwdns148999:0:javadoc:crwdnd148999:0:doc:crwdne148999:0

crwdns149001:0:javadoc:crwdnd149001:0:javadoc:crwdnd149001:0:javadoc:crwdne149001:0

Tip

crwdns149003:0crwdne149003:0

crwdns149005:0crwdne149005:0

crwdns149007:0crwdne149007:0

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

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

crwdns149009:0crwdne149009:0

crwdns149011:0crwdne149011:0

crwdns149013:0crwdne149013: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);
    }
}

crwdns149015:0crwdne149015:0

crwdns149017:0crwdne149017:0

crwdns149019:0:javadoc:crwdne149019:0

crwdns149021:0crwdne149021: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);
   }
}

crwdns149023:0crwdne149023:0

crwdns149025:0crwdne149025:0

crwdns149027:0:javadoc:crwdnd149027:0:javadoc:crwdne149027:0

crwdns149029:0crwdne149029:0

crwdns149031:0crwdne149031:0

crwdns149033:0crwdne149033:0

crwdns149035:0crwdne149035:0

  • crwdns149037:0crwdne149037:0

  • crwdns149039:0crwdne149039:0

crwdns149041:0crwdne149041:0

  • crwdns149043:0crwdne149043:0

  • crwdns149045:0:javadoc:crwdnd149045:0:javadoc:crwdne149045:0