|
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. |
@@ -70,65 +72,45 @@ public interface DamageStep { |
70 | 72 | void setSkipped(boolean skipped); |
71 | 73 |
|
72 | 74 | /** |
73 | | - * Sets whether this step is skipped. |
74 | | - * This has no effect if the step has already finished. |
| 75 | + * Skips this step. |
75 | 76 | * |
76 | 77 | * @see #isSkipped() |
| 78 | + * @throws IllegalStateException if called after the step has finished. |
77 | 79 | */ |
78 | | - default void trySetSkipped(boolean skipped) { |
79 | | - if (this.damageAfterSelf().isEmpty()) { |
80 | | - this.setSkipped(skipped); |
81 | | - } |
| 80 | + default void skip() { |
| 81 | + this.setSkipped(true); |
82 | 82 | } |
83 | 83 |
|
84 | 84 | /** |
85 | | - * Sets whether the children before this step are skipped. |
| 85 | + * Sets whether parts of this step are skipped. |
86 | 86 | * This has no effect on steps already finished. |
87 | 87 | * |
88 | 88 | * @see #isSkipped() |
89 | 89 | */ |
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()) { |
92 | 92 | for (DamageStep child : this.childrenBefore()) { |
93 | | - child.trySetSkipped(skipped); |
| 93 | + child.trySetSkipped(Part.ALL, skipped); |
94 | 94 | } |
95 | 95 | } |
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()) { |
106 | 100 | for (DamageStep child : this.childrenAfter()) { |
107 | | - child.trySetSkipped(skipped); |
| 101 | + child.trySetSkipped(Part.ALL, skipped); |
108 | 102 | } |
109 | 103 | } |
110 | 104 | } |
111 | 105 |
|
112 | 106 | /** |
113 | | - * Sets whether this step and its children are skipped. |
| 107 | + * Skips parts of this step. |
114 | 108 | * This has no effect on steps already finished. |
115 | 109 | * |
116 | 110 | * @see #isSkipped() |
117 | 111 | */ |
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); |
132 | 114 | } |
133 | 115 |
|
134 | 116 | /** |
@@ -205,4 +187,13 @@ default DamageStep root() { |
205 | 187 | * @return The list of children steps |
206 | 188 | */ |
207 | 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 | + } |
208 | 199 | } |
0 commit comments