开发者
repositories {
maven("https://jitpack.io/")
}
dependencies {
compileOnly("com.github.MrXiaoM:SweetTask:$VERSION:all")
}
1
2
3
4
5
6
2
3
4
5
6
# 添加子任务类型
首先,添加子任务参数格式
public class TaskExample implements ITask {
public static final String TYPE = "example";
@Override
public String type() {
return TYPE;
}
public static void register() {
ITask.registerParser(TYPE, (args, actionTips, warn) -> {
// args 是按空格分割的参数,在这里读取并返回子任务参数实例
if (args.length == 0) return null;
Integer target = Util.parseInt(args[args.length - 1]).orElse(null);
if (target == null) {
warn.accept("未输入数量");
return null;
}
return new TaskKill(target, actionTips);
});
}
public final int target;
public final String actionTips;
public TaskExample(int target, String actionTips) {
this.target = target;
this.actionTips = actionTips;
}
@Override
public String actionTips() {
return actionTips;
}
@Override
public int getTargetValue() {
return target;
}
}
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
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
然后,在触发某个操作时,扫描玩家正在进行的任务中是否有该子任务,并操作玩家的进度数据。
请参考 KillListener (opens new window),继承 AbstractListener 进行实现。
- 如果是为 SweetTask 进行贡献,为其添加
@AutoRegister注解,使得插件启用时,自动对其进行实例化并注册。 - 如果是添加外部插件子任务目标,直接实例化即可,它会被自动注册到 SweetTask 的生命周期中。在插件卸载时, 请务必调用
.unregister()以脱离 SweetTask 的生命周期。 另外需要注意的是,AbstractListener 的子类是单例的,请不要重复进行实例化操作。
上次更新: 2025/12/08, 04:32:33