crwdns138485:0crwdne138485:0

Warning

crwdns138487:0crwdne138487:0

crwdns138489:0crwdne138489:0

crwdns138491:0crwdne138491:0

crwdns138493:0crwdne138493: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 void 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);
    }
}

crwdns138495:0:javadoc:crwdne138495:0

crwdns138497:0:javadoc:crwdnd138497:0:doc:crwdne138497:0

crwdns138499:0:javadoc:crwdnd138499:0:javadoc:crwdnd138499:0:javadoc:crwdne138499:0

Tip

crwdns138501:0crwdne138501:0

crwdns138503:0crwdne138503:0

crwdns138505:0crwdne138505:0

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

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

crwdns138507:0crwdne138507:0

crwdns138509:0crwdne138509:0

crwdns138511:0crwdne138511: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);
    }
}

crwdns138513:0crwdne138513:0

crwdns138515:0crwdne138515:0

crwdns138517:0:javadoc:crwdne138517:0

crwdns138519:0crwdne138519: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);
   }
}

crwdns138521:0crwdne138521:0

crwdns138523:0crwdne138523:0

crwdns138525:0:javadoc:crwdnd138525:0:javadoc:crwdne138525:0

crwdns138527:0crwdne138527:0

crwdns138529:0crwdne138529:0

crwdns138531:0crwdne138531:0

crwdns138533:0crwdne138533:0

  • crwdns138535:0crwdne138535:0

  • crwdns138537:0crwdne138537:0

crwdns138539:0crwdne138539:0

  • crwdns138541:0crwdne138541:0

  • crwdns138543:0:javadoc:crwdnd138543:0:javadoc:crwdne138543:0