Add ExplosionEvent.Detonate#filterAffectedLocations
import org.spongepowered.api.world.explosion.Explosion;
import org.spongepowered.api.world.server.ServerWorld;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.function.Predicate;
/**
* Called when an {@link Explosion} occurs in a {@link World}.
* @return The list of blocks that will be affected by the explosion
*/
List<ServerLocation> getAffectedLocations();
+
+ /**
+ * Filters out {@link ServerLocation}'s from
+ * {@link #getAffectedLocations()} to be affected by this event.
+ *
+ * <p>Locations for which the predicate returns <code>false</code> will
+ * be removed from {@link #getAffectedLocations()}.</p>
+ *
+ * @param predicate The predicate to use for filtering
+ * @return The locations removed from {@link #getAffectedLocations()}
+ */
+ default List<ServerLocation> filterAffectedLocations(Predicate<ServerLocation> predicate) {
+ final List<ServerLocation> removedLocations = new ArrayList<>();
+
+ final Iterator<ServerLocation> iter = this.getAffectedLocations().iterator();
+ while (iter.hasNext()) {
+ final ServerLocation location = iter.next();
+
+ if (!predicate.test(location)) {
+ iter.remove();
+ removedLocations.add(location);
+ }
+ }
+
+ return removedLocations;
+ }
}
/**
