Skip to content

Commit 38bc114

Browse files
committed
Replace trySetSkipped variants with a set of parts
1 parent 7f5762c commit 38bc114

File tree

1 file changed

+27
-36
lines changed
  • src/main/java/org/spongepowered/api/event/cause/entity/damage

1 file changed

+27
-36
lines changed

src/main/java/org/spongepowered/api/event/cause/entity/damage/DamageStep.java

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626

2727
import org.spongepowered.api.event.Cause;
2828

29+
import java.util.EnumSet;
2930
import java.util.List;
3031
import java.util.Optional;
3132
import java.util.OptionalDouble;
33+
import java.util.Set;
3234

3335
/**
3436
* A step represent an operation made by the platform (vanilla and mods) or modifiers added by plugins.
@@ -70,65 +72,45 @@ public interface DamageStep {
7072
void setSkipped(boolean skipped);
7173

7274
/**
73-
* Sets whether this step is skipped.
74-
* This has no effect if the step has already finished.
75+
* Skips this step.
7576
*
7677
* @see #isSkipped()
78+
* @throws IllegalStateException if called after the step has finished.
7779
*/
78-
default void trySetSkipped(boolean skipped) {
79-
if (this.damageAfterSelf().isEmpty()) {
80-
this.setSkipped(skipped);
81-
}
80+
default void skip() {
81+
this.setSkipped(true);
8282
}
8383

8484
/**
85-
* Sets whether the children before this step are skipped.
85+
* Sets whether parts of this step are skipped.
8686
* This has no effect on steps already finished.
8787
*
8888
* @see #isSkipped()
8989
*/
90-
default void trySetChildrenBeforeSkipped(boolean skipped) {
91-
if (this.damageBeforeSelf().isEmpty()) {
90+
default void trySetSkipped(Set<Part> parts, boolean skipped) {
91+
if (parts.contains(Part.CHILDREN_BEFORE) && this.damageBeforeSelf().isEmpty()) {
9292
for (DamageStep child : this.childrenBefore()) {
93-
child.trySetSkipped(skipped);
93+
child.trySetSkipped(Part.ALL, skipped);
9494
}
9595
}
96-
}
97-
98-
/**
99-
* Sets whether the children after this step are skipped.
100-
* This has no effect on steps already finished.
101-
*
102-
* @see #isSkipped()
103-
*/
104-
default void trySetChildrenAfterSkipped(boolean skipped) {
105-
if (this.damageAfterChildren().isEmpty()) {
96+
if (parts.contains(Part.SELF) && this.damageAfterSelf().isEmpty()) {
97+
this.setSkipped(skipped);
98+
}
99+
if (parts.contains(Part.CHILDREN_AFTER) && this.damageAfterChildren().isEmpty()) {
106100
for (DamageStep child : this.childrenAfter()) {
107-
child.trySetSkipped(skipped);
101+
child.trySetSkipped(Part.ALL, skipped);
108102
}
109103
}
110104
}
111105

112106
/**
113-
* Sets whether this step and its children are skipped.
107+
* Skips parts of this step.
114108
* This has no effect on steps already finished.
115109
*
116110
* @see #isSkipped()
117111
*/
118-
default void trySetAllSkipped(boolean skipped) {
119-
this.trySetChildrenBeforeSkipped(skipped);
120-
this.trySetSkipped(skipped);
121-
this.trySetChildrenAfterSkipped(skipped);
122-
}
123-
124-
/**
125-
* Skips this step.
126-
*
127-
* @see #isSkipped()
128-
* @throws IllegalStateException if called after the step has finished.
129-
*/
130-
default void skip() {
131-
this.setSkipped(true);
112+
default void trySkip(Set<Part> parts) {
113+
this.trySetSkipped(parts, true);
132114
}
133115

134116
/**
@@ -205,4 +187,13 @@ default DamageStep root() {
205187
* @return The list of children steps
206188
*/
207189
List<DamageStep> childrenAfter();
190+
191+
/**
192+
* The parts composing a step.
193+
*/
194+
enum Part {
195+
SELF, CHILDREN_BEFORE, CHILDREN_AFTER;
196+
197+
public static final EnumSet<Part> ALL = EnumSet.allOf(Part.class);
198+
}
208199
}

0 commit comments

Comments
 (0)