Skip to content

Commit 67a5098

Browse files
Fix up after action logic in the sequence
1 parent 0c60779 commit 67a5098

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

‎src/main/java/com/abilityapi/sequenceapi/Sequence.java‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,38 @@ public boolean applyAfter(final SequenceContext sequenceContext) {
133133

134134
final long current = System.currentTimeMillis();
135135

136-
if (!(this.lastTime + ((action.getDelay() / 20) * 1000) > current)) {
137-
if (!action.apply(sequenceContext)) {
138-
return this.fail(action, sequenceContext);
139-
}
136+
// 1. Fail the action if it is being executed before the delay.
140137

141-
this.index++;
138+
if (this.lastTime + ((action.getDelay() / 20) * 1000) > current) {
139+
return false;
140+
}
142141

143-
iterator.remove();
142+
// 2. Fail the action if it being executed after the expire.
144143

145-
if (!iterator.hasNext()) {
146-
if (this.index == this.actionsSize) this.state = State.FINISHED;
147-
}
144+
if (this.lastTime + ((action.getExpire() / 20) * 1000) < current) {
145+
return this.fail(action, sequenceContext);
146+
}
148147

149-
return this.succeed(action, sequenceContext);
148+
// 3. Run the action conditions and fail if they do not pass.
149+
150+
if (!action.apply(sequenceContext)) {
151+
return this.fail(action, sequenceContext);
150152
}
153+
154+
// 4. Succeed the action, remove it, increment the index and set finish if there are no more actions left.
155+
156+
this.index++;
157+
158+
iterator.remove();
159+
160+
if (!iterator.hasNext()) {
161+
if (this.index == this.actionsSize) this.state = State.FINISHED;
162+
}
163+
164+
return this.succeed(action, sequenceContext);
151165
}
152166

153-
return false;
167+
return true;
154168
}
155169

156170
/**

0 commit comments

Comments
 (0)