Projectile shooter can be null e.g. if the entity died
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.projectile.source.ProjectileSource;
+import java.util.Optional;
+
/**
* Represents entities that act as projectiles and can fly in the air.
* For example, Arrows.
* {@link Keys#SHOOTER}
* @return The shooter
*/
- default Value.Mutable<ProjectileSource> shooter() {
- return this.requireValue(Keys.SHOOTER).asMutable();
+ default Optional<Value.Mutable<ProjectileSource>> shooter() {
+ return this.getValue(Keys.SHOOTER).map(Value::asMutable);
}
}
