crwdns118849:0crwdne118849:0
crwdns118851:0crwdne118851:0
crwdns118853:0crwdne118853:0
crwdns118855:0crwdne118855: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);
}
}
crwdns118857:0:javadoc:crwdne118857:0
crwdns118859:0:javadoc:crwdnd118859:0:doc:crwdne118859:0
crwdns118861:0:javadoc:crwdnd118861:0:javadoc:crwdnd118861:0:javadoc:crwdne118861:0
Tip
crwdns118863:0crwdne118863:0
crwdns118865:0crwdne118865:0
crwdns118867:0crwdne118867:0
import org.spongepowered.api.data.manipulator.mutable.DisplayNameData;
public void removeName(DataHolder target) {
target.remove(DisplayNameData.class);
}
crwdns118869:0crwdne118869:0
crwdns118871:0crwdne118871:0
crwdns118873:0crwdne118873: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);
}
}
crwdns118875:0crwdne118875:0
crwdns118877:0crwdne118877:0
crwdns118879:0:javadoc:crwdne118879:0
crwdns118881:0crwdne118881: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);
}
}
crwdns118883:0crwdne118883:0
crwdns118885:0crwdne118885:0
crwdns118887:0:javadoc:crwdnd118887:0:javadoc:crwdne118887:0
crwdns118889:0crwdne118889:0
crwdns118891:0crwdne118891:0
crwdns118893:0crwdne118893:0
crwdns118895:0crwdne118895:0
crwdns118897:0crwdne118897:0
crwdns118899:0crwdne118899:0
crwdns118901:0crwdne118901:0
crwdns118903:0crwdne118903:0
crwdns118905:0:javadoc:crwdnd118905:0:javadoc:crwdne118905:0