|
26 | 26 |
|
27 | 27 | import org.spongepowered.api.event.Cause; |
28 | 28 |
|
| 29 | +import java.util.EnumSet; |
29 | 30 | import java.util.List; |
30 | 31 | import java.util.Optional; |
31 | 32 | import java.util.OptionalDouble; |
| 33 | +import java.util.Set; |
32 | 34 |
|
33 | 35 | /** |
34 | 36 | * A step represent an operation made by the platform (vanilla and mods) or modifiers added by plugins. |
@@ -79,6 +81,38 @@ default void skip() { |
79 | 81 | this.setSkipped(true); |
80 | 82 | } |
81 | 83 |
|
| 84 | + /** |
| 85 | + * Sets whether parts of this step are skipped. |
| 86 | + * This has no effect on steps already finished. |
| 87 | + * |
| 88 | + * @see #isSkipped() |
| 89 | + */ |
| 90 | + default void trySetSkipped(Set<Part> parts, boolean skipped) { |
| 91 | + if (parts.contains(Part.CHILDREN_BEFORE) && this.damageBeforeSelf().isEmpty()) { |
| 92 | + for (DamageStep child : this.childrenBefore()) { |
| 93 | + child.trySetSkipped(Part.ALL, skipped); |
| 94 | + } |
| 95 | + } |
| 96 | + if (parts.contains(Part.SELF) && this.damageAfterSelf().isEmpty()) { |
| 97 | + this.setSkipped(skipped); |
| 98 | + } |
| 99 | + if (parts.contains(Part.CHILDREN_AFTER) && this.damageAfterChildren().isEmpty()) { |
| 100 | + for (DamageStep child : this.childrenAfter()) { |
| 101 | + child.trySetSkipped(Part.ALL, skipped); |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Skips parts of this step. |
| 108 | + * This has no effect on steps already finished. |
| 109 | + * |
| 110 | + * @see #isSkipped() |
| 111 | + */ |
| 112 | + default void trySkip(Set<Part> parts) { |
| 113 | + this.trySetSkipped(parts, true); |
| 114 | + } |
| 115 | + |
82 | 116 | /** |
83 | 117 | * The damage just before the children of this step. |
84 | 118 | * Returns empty if the value is not known yet. |
@@ -153,4 +187,13 @@ default DamageStep root() { |
153 | 187 | * @return The list of children steps |
154 | 188 | */ |
155 | 189 | 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 | + } |
156 | 199 | } |
0 commit comments