summaryrefslogtreecommitdiff
path: root/dicore3/command/src/main/java/io/dico/dicore/command/registration/reflect/ICommandInterceptor.java
blob: 1e56b8ad98f200169dc7deef7330c8d78da8c1e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package io.dico.dicore.command.registration.reflect;

import io.dico.dicore.command.ExecutionContext;

import java.lang.reflect.Method;

public interface ICommandInterceptor {

    /**
     * Get the receiver of the command, if applicable.
     * A command has a receiver if its first parameter implements {@link ICommandReceiver}
     * and its instance object implements this interface.
     *
     * @param context the context of execution
     * @param target the method of the command
     * @param cmdName the name of the command
     * @return the receiver
     */
    default ICommandReceiver getReceiver(ExecutionContext context, Method target, String cmdName) {
        return null;
    }

    /**
     * If applicable, get the coroutine context to use in suspend functions (Kotlin only).
     * The return type is object to avoid depending on the kotlin runtime.
     *
     * @param context the context of execution
     * @param target the method of the command
     * @param cmdName the name of the command
     * @return the coroutine context
     */
    default Object getCoroutineContext(ExecutionContext context, Method target, String cmdName) {
        return null;
    }

}