-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaperCommandService.java
More file actions
77 lines (68 loc) · 3.32 KB
/
PaperCommandService.java
File metadata and controls
77 lines (68 loc) · 3.32 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package net.onelitefeather.stardust.service;
import net.kyori.adventure.text.format.NamedTextColor;
import net.onelitefeather.stardust.StardustPlugin;
import net.onelitefeather.stardust.command.commands.*;
import net.onelitefeather.stardust.command.mapper.BukkitSenderMapper;
import org.bukkit.command.CommandSender;
import org.incendo.cloud.annotation.specifier.Greedy;
import org.incendo.cloud.annotations.*;
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.minecraft.extras.AudienceProvider;
import org.incendo.cloud.minecraft.extras.MinecraftHelp;
import org.incendo.cloud.paper.PaperCommandManager;
public class PaperCommandService {
private final StardustPlugin plugin;
private final PaperCommandManager<CommandSender> paperCommandManager;
private final AnnotationParser<CommandSender> annotationParser;
private final MinecraftHelp<CommandSender> minecraftHelp;
private final MinecraftHelp.HelpColors helpColors = MinecraftHelp.helpColors(
NamedTextColor.GOLD,
NamedTextColor.YELLOW,
NamedTextColor.GOLD,
NamedTextColor.GRAY,
NamedTextColor.GOLD
);
public PaperCommandService(StardustPlugin plugin) {
this.plugin = plugin;
this.paperCommandManager = buildCommandSystem();
this.annotationParser = buildAnnotationParser(paperCommandManager);
this.minecraftHelp = buildHelpSystem(paperCommandManager);
}
@SuppressWarnings("UnstableApiUsage")
private PaperCommandManager<CommandSender> buildCommandSystem() {
return PaperCommandManager.builder(new BukkitSenderMapper())
.executionCoordinator(ExecutionCoordinator.asyncCoordinator())
.buildOnEnable(plugin);
}
private AnnotationParser<CommandSender> buildAnnotationParser(PaperCommandManager<CommandSender> commandManager) {
return new AnnotationParser<>(commandManager, CommandSender.class);
}
private MinecraftHelp<CommandSender> buildHelpSystem(PaperCommandManager<CommandSender> commandManager) {
return MinecraftHelp.<CommandSender>builder()
.commandManager(commandManager)
.audienceProvider(AudienceProvider.nativeAudience())
.commandPrefix("/stardust")
.colors(helpColors)
.build();
}
public void registerCommands() {
annotationParser.parse(this);
annotationParser.parse(new FlightCommand(plugin));
annotationParser.parse(new GlowCommand(plugin));
annotationParser.parse(new GodmodeCommand(plugin));
annotationParser.parse(new HealCommand(plugin));
annotationParser.parse(new RenameCommand(plugin));
annotationParser.parse(new IPSameCommand(plugin));
annotationParser.parse(new RepairCommand(plugin));
annotationParser.parse(new SignCommand(plugin));
annotationParser.parse(new SkullCommand(plugin));
annotationParser.parse(new VanishCommand(plugin));
annotationParser.parse(plugin.getSyncFrogService());
}
@Command("stardust help [query]")
@CommandDescription("Shows the help menu")
@Permission("stardust.command.help")
private void helpCommand(CommandSender sender, @Argument("query") @Greedy String query) {
minecraftHelp.queryCommands(query != null ? query : "", sender);
}
}