Skip to content

Commit fb9d43e

Browse files
committed
wip
1 parent d4a26fc commit fb9d43e

File tree

57 files changed

+565
-454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+565
-454
lines changed

litecommands-annotations/src/dev/rollczi/litecommands/annotations/validator/requirment/AnnotatedValidator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.lang.annotation.Annotation;
99

10+
@Deprecated
1011
@FunctionalInterface
1112
public interface AnnotatedValidator<SENDER, T, A extends Annotation> {
1213

litecommands-annotations/src/dev/rollczi/litecommands/annotations/validator/requirment/AnnotatedValidatorProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.lang.annotation.Annotation;
88

9+
@Deprecated
910
public class AnnotatedValidatorProcessor<SENDER, T, A extends Annotation> implements AnnotationProcessor<SENDER> {
1011

1112
private final Class<A> annotationClass;

litecommands-annotations/src/dev/rollczi/litecommands/annotations/validator/requirment/RequirementAnnotatedValidatorImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.lang.annotation.Annotation;
1010

11+
@Deprecated
1112
class RequirementAnnotatedValidatorImpl<SENDER, T, A extends Annotation> implements RequirementValidator<SENDER, T> {
1213

1314
private final AnnotatedValidator<SENDER, T, A> validator;

litecommands-core/src/dev/rollczi/litecommands/LiteCommandsInternal.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import dev.rollczi.litecommands.command.builder.CommandBuilderCollector;
1010
import dev.rollczi.litecommands.editor.EditorService;
1111
import dev.rollczi.litecommands.message.MessageRegistry;
12+
import dev.rollczi.litecommands.permission.PermissionService;
1213
import dev.rollczi.litecommands.platform.PlatformSettings;
1314
import dev.rollczi.litecommands.platform.Platform;
1415
import dev.rollczi.litecommands.scheduler.Scheduler;
@@ -39,6 +40,9 @@ public interface LiteCommandsInternal<SENDER, C extends PlatformSettings> {
3940
@ApiStatus.Internal
4041
EditorService<SENDER> getEditorService();
4142

43+
@ApiStatus.Internal
44+
PermissionService getPermissionService();
45+
4246
@ApiStatus.Internal
4347
ValidatorService<SENDER> getValidatorService();
4448

litecommands-core/src/dev/rollczi/litecommands/argument/parser/ParseResult.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ static <EXPECTED> ParseCompletedResult<EXPECTED> failure(Object failedReason) {
5050
return new ParseCompletedResult<>(null, FailedReason.of(failedReason), false, Collections.emptyList());
5151
}
5252

53-
@Deprecated
54-
static <EXPECTED> ParseCompletedResult<EXPECTED> failure() {
55-
return new ParseCompletedResult<>(null, FailedReason.empty(), false, Collections.emptyList());
56-
}
57-
5853
@ApiStatus.Experimental
5954
static <EXPECTED> ParseCompletedResult<EXPECTED> conditional(EXPECTED parsed, List<RequirementCondition> conditions) {
6055
return new ParseCompletedResult<>(parsed, null, false, Collections.unmodifiableList(conditions));
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package dev.rollczi.litecommands.command;
22

3+
import dev.rollczi.litecommands.meta.MetaHolder;
4+
import org.jetbrains.annotations.Nullable;
5+
36
/**
47
* CommandNode is an any node of the command tree.
58
* @see CommandRoute
69
* @see dev.rollczi.litecommands.command.executor.CommandExecutor
710
*/
8-
public interface CommandNode<SENDER> {
11+
public interface CommandNode<SENDER> extends MetaHolder {
912

1013
CommandRoute<SENDER> getParent();
1114

15+
@Override
16+
@Nullable
17+
default MetaHolder parentMeta() {
18+
return getParent();
19+
}
20+
1221
}

litecommands-core/src/dev/rollczi/litecommands/command/executor/CommandExecuteResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static CommandExecuteResult failed(CommandExecutor<?> executor, FailedRea
8181
Preconditions.notNull(executor, "executor");
8282
Preconditions.notNull(failedReason, "failed cannot be null");
8383

84-
return new CommandExecuteResult(executor, null, null, failedReason.getReasonOr(null));
84+
return new CommandExecuteResult(executor, null, null, failedReason.getReason());
8585
}
8686

8787
}

litecommands-core/src/dev/rollczi/litecommands/command/executor/CommandExecuteService.java

Lines changed: 23 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,23 @@
33
import dev.rollczi.litecommands.LiteCommandsException;
44
import dev.rollczi.litecommands.argument.parser.input.ParseableInputMatcher;
55
import dev.rollczi.litecommands.command.CommandRoute;
6-
import dev.rollczi.litecommands.command.executor.event.CandidateExecutorFoundEvent;
7-
import dev.rollczi.litecommands.command.executor.event.CandidateExecutorMatchEvent;
6+
import dev.rollczi.litecommands.command.executor.event.CommandExecutorFoundEvent;
7+
import dev.rollczi.litecommands.command.executor.event.CommandExecutorNotFoundEvent;
88
import dev.rollczi.litecommands.command.executor.event.CommandPostExecutionEvent;
99
import dev.rollczi.litecommands.command.executor.event.CommandPreExecutionEvent;
10-
import dev.rollczi.litecommands.command.executor.flow.ExecuteFlow;
10+
import dev.rollczi.litecommands.invalidusage.InvalidUsage.Cause;
1111
import dev.rollczi.litecommands.invalidusage.InvalidUsageException;
1212
import dev.rollczi.litecommands.event.EventPublisher;
1313
import dev.rollczi.litecommands.handler.result.ResultHandleService;
14+
import dev.rollczi.litecommands.priority.MutablePrioritizedList;
15+
import dev.rollczi.litecommands.priority.PriorityLevel;
1416
import dev.rollczi.litecommands.requirement.RequirementMatchService;
1517
import dev.rollczi.litecommands.shared.FailedReason;
16-
import dev.rollczi.litecommands.flow.Flow;
17-
import dev.rollczi.litecommands.invalidusage.InvalidUsage;
1818
import dev.rollczi.litecommands.invocation.Invocation;
1919
import dev.rollczi.litecommands.meta.Meta;
2020
import dev.rollczi.litecommands.scheduler.Scheduler;
2121
import dev.rollczi.litecommands.scheduler.SchedulerPoll;
22-
import dev.rollczi.litecommands.validator.ValidatorService;
2322
import java.util.Iterator;
24-
import org.jetbrains.annotations.Nullable;
2523

2624
import java.util.concurrent.CompletableFuture;
2725
import java.util.concurrent.CompletionException;
@@ -30,20 +28,17 @@
3028

3129
public class CommandExecuteService<SENDER> {
3230

33-
private final ValidatorService<SENDER> validatorService;
3431
private final ResultHandleService<SENDER> resultResolver;
3532
private final Scheduler scheduler;
3633
private final RequirementMatchService<SENDER> requirementMatchService;
3734
private final EventPublisher publisher;
3835

3936
public CommandExecuteService(
40-
ValidatorService<SENDER> validatorService,
4137
ResultHandleService<SENDER> resultResolver,
4238
Scheduler scheduler,
4339
RequirementMatchService<SENDER> requirementMatchService,
4440
EventPublisher publisher
4541
) {
46-
this.validatorService = validatorService;
4742
this.resultResolver = resultResolver;
4843
this.scheduler = scheduler;
4944
this.requirementMatchService = requirementMatchService;
@@ -92,86 +87,51 @@ private <MATCHER extends ParseableInputMatcher<MATCHER>> CompletableFuture<Comma
9287
ParseableInputMatcher<MATCHER> matcher,
9388
CommandRoute<SENDER> commandRoute
9489
) {
95-
return this.execute(commandRoute.getExecutors().iterator(), invocation, matcher, commandRoute, null);
90+
return this.execute(commandRoute.getExecutors().iterator(), invocation, matcher, commandRoute, new MutablePrioritizedList<>());
9691
}
9792

9893
private <MATCHER extends ParseableInputMatcher<MATCHER>> CompletableFuture<CommandExecuteResult> execute(
9994
Iterator<CommandExecutor<SENDER>> executors,
10095
Invocation<SENDER> invocation,
10196
ParseableInputMatcher<MATCHER> matcher,
10297
CommandRoute<SENDER> commandRoute,
103-
@Nullable FailedReason last
98+
MutablePrioritizedList<FailedReason> failedReasons
10499
) {
105100
// Handle failed
106101
if (!executors.hasNext()) {
107-
// Route valid
108-
Flow validate = validatorService.validate(invocation, commandRoute);
109-
if (validate.isTerminate() || validate.isStopCurrent()) {
110-
return completedFuture(CommandExecuteResult.failed(validate.getReason()));
111-
} // TODO: event (CommandExcutorNotFoundEvent)
112-
113-
CommandExecutor<SENDER> executor = commandRoute.getExecutors().isEmpty()
114-
? null :
115-
commandRoute.getExecutors().last();
116-
117-
if (last != null && last.hasResult()) {
118-
return completedFuture(CommandExecuteResult.failed(executor, last));
102+
if (commandRoute.getExecutors().isEmpty()) {
103+
failedReasons.add(FailedReason.of(Cause.UNKNOWN_COMMAND, PriorityLevel.LOW));
119104
}
120105

121-
return completedFuture(CommandExecuteResult.failed(InvalidUsage.Cause.UNKNOWN_COMMAND));
106+
CommandExecutorNotFoundEvent event = publisher.publish(new CommandExecutorNotFoundEvent(invocation, commandRoute, failedReasons));
107+
108+
return completedFuture(CommandExecuteResult.failed(event.getFailedReason().getReason()));
122109
}
123110

124111
CommandExecutor<SENDER> executor = executors.next();
125112

126-
if (publisher.hasSubscribers(CandidateExecutorFoundEvent.class)) {
127-
CandidateExecutorFoundEvent<SENDER> foundEvent = publisher.publish(new CandidateExecutorFoundEvent<>(invocation, executor));
128-
if (foundEvent.getFlow() == ExecuteFlow.STOP) {
129-
return completedFuture(CommandExecuteResult.failed(executor, foundEvent.getFlowResult()));
130-
}
131-
132-
if (foundEvent.getFlow() == ExecuteFlow.SKIP) {
133-
return this.execute(executors, invocation, matcher, commandRoute, FailedReason.max(foundEvent.getFlowResult(), last));
134-
}
135-
}
136-
137113
// Handle matching arguments
138114
return this.requirementMatchService.match(executor, invocation, matcher.copy()).thenCompose(match -> {
139-
if (publisher.hasSubscribers(CandidateExecutorMatchEvent.class)) {
140-
CandidateExecutorMatchEvent<SENDER> matchEvent = publisher.publish(new CandidateExecutorMatchEvent<>(invocation, executor, match));
141-
if (matchEvent.getFlow() == ExecuteFlow.STOP) {
142-
return completedFuture(CommandExecuteResult.failed(executor, matchEvent.getFlowResult()));
143-
}
144-
145-
if (matchEvent.getFlow() == ExecuteFlow.SKIP) {
146-
return this.execute(executors, invocation, matcher, commandRoute, FailedReason.max(matchEvent.getFlowResult(), last));
147-
}
115+
CommandExecutorFoundEvent<SENDER> matchEvent = publisher.publish(new CommandExecutorFoundEvent<>(invocation, executor, match));
116+
if (matchEvent.isCancelled()) {
117+
return completedFuture(CommandExecuteResult.failed(executor, matchEvent.getCancelReason()));
148118
}
149119

150-
if (match.isFailed()) {
151-
FailedReason current = match.getFailedReason();
152-
153-
if (current.hasResult()) {
154-
return this.execute(executors, invocation, matcher, commandRoute, FailedReason.max(current, last));
155-
}
156-
157-
return this.execute(executors, invocation, matcher, commandRoute, last);
120+
CommandExecutorMatchResult processedMatch = matchEvent.getResult();
121+
if (processedMatch.isFailed()) {
122+
failedReasons.add(processedMatch.getFailedReason());
123+
return this.execute(executors, invocation, matcher, commandRoute, failedReasons);
158124
}
159125

160-
if (publisher.hasSubscribers(CommandPreExecutionEvent.class)) {
161-
CommandPreExecutionEvent<SENDER> executionEvent = publisher.publish(new CommandPreExecutionEvent<>(invocation, executor));
162-
if (executionEvent.getFlow() == ExecuteFlow.STOP) {
163-
return completedFuture(CommandExecuteResult.failed(executor, executionEvent.getFlowResult()));
164-
}
165-
166-
if (executionEvent.getFlow() == ExecuteFlow.SKIP) {
167-
return this.execute(executors, invocation, matcher, commandRoute, FailedReason.max(executionEvent.getFlowResult(), last));
168-
}
126+
CommandPreExecutionEvent<SENDER> executionEvent = publisher.publish(new CommandPreExecutionEvent<>(invocation, executor));
127+
if (executionEvent.isCancelled()) {
128+
return completedFuture(CommandExecuteResult.failed(executor, executionEvent.getCancelReason()));
169129
}
170130

171131
// Execution
172132
SchedulerPoll type = executor.metaCollector().findFirst(Meta.POLL_TYPE);
173133

174-
return scheduler.supply(type, () -> execute(match, executor));
134+
return scheduler.supply(type, () -> execute(processedMatch, executor));
175135
}).exceptionally(throwable -> toThrown(executor, throwable));
176136
}
177137

litecommands-core/src/dev/rollczi/litecommands/command/executor/event/AbstractCommandExecutorEvent.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

litecommands-core/src/dev/rollczi/litecommands/command/executor/event/CandidateExecutorFoundEvent.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

litecommands-core/src/dev/rollczi/litecommands/command/executor/event/CandidateExecutorMatchEvent.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

litecommands-core/src/dev/rollczi/litecommands/command/executor/event/CommandExecutorEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
/**
99
* Represents an event fired when a command executor is executed.
1010
* Flow:
11-
* - {@link CandidateExecutorFoundEvent}
12-
* - {@link CandidateExecutorMatchEvent}
11+
* - {@link CommandExecutorFoundEvent}
12+
* - {@link CommandExecutorFoundEvent}
1313
* - {@link CommandPreExecutionEvent}
1414
* - {@link CommandPostExecutionEvent}
1515
*/

0 commit comments

Comments
 (0)