Skip to content

Commit 05fcf7f

Browse files
committed
Info Command
`/sp info <id>` added, mostly for debugging, not yet designed for use in gameplay.
1 parent 065d2c2 commit 05fcf7f

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

src/main/java/adhdmc/simpleprefixes/SimplePrefixes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package adhdmc.simpleprefixes;
22

33
import adhdmc.simpleprefixes.command.CommandHandler;
4+
import adhdmc.simpleprefixes.command.subcommand.InfoCommand;
45
import adhdmc.simpleprefixes.command.subcommand.ReloadCommand;
56
import adhdmc.simpleprefixes.command.subcommand.ResetCommand;
67
import adhdmc.simpleprefixes.command.subcommand.SetCommand;
@@ -45,6 +46,7 @@ private void registerCommands() {
4546
this.getCommand("simpleprefix").setExecutor(new CommandHandler());
4647
CommandHandler.subcommandList.clear();
4748
CommandHandler.subcommandList.put("set", new SetCommand());
49+
CommandHandler.subcommandList.put("info", new InfoCommand());
4850
CommandHandler.subcommandList.put("reset", new ResetCommand());
4951
CommandHandler.subcommandList.put("reload", new ReloadCommand());
5052
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package adhdmc.simpleprefixes.command.subcommand;
2+
3+
import adhdmc.simpleprefixes.SimplePrefixes;
4+
import adhdmc.simpleprefixes.command.SubCommand;
5+
import adhdmc.simpleprefixes.util.Prefix;
6+
import net.kyori.adventure.text.Component;
7+
import net.kyori.adventure.text.minimessage.MiniMessage;
8+
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
9+
import org.bukkit.command.CommandSender;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
public class InfoCommand extends SubCommand {
15+
16+
public InfoCommand() {
17+
super("info", "Displays information about the given prefix.", "/sp info <id>");
18+
}
19+
20+
@Override
21+
public void execute(CommandSender sender, String[] args) {
22+
Prefix prefix = Prefix.getPrefix(args[0]);
23+
if (prefix == null) {
24+
// TODO: Configurable message, message enum.
25+
sender.sendRichMessage("<red>PLACEHOLDER: NOT VALID ID");
26+
return;
27+
}
28+
sender.sendMessage(buildInfoString(prefix));
29+
}
30+
31+
@Override
32+
public List<String> getSubcommandArguments(CommandSender sender, String[] args) {
33+
if (args.length != 2) return new ArrayList<>();
34+
List<String> returnList = new ArrayList<>();
35+
for (String s : Prefix.getPrefixes().keySet()) {
36+
if (s.toLowerCase().contains(args[1].toLowerCase())) returnList.add(s);
37+
}
38+
return returnList;
39+
}
40+
41+
private Component buildInfoString(Prefix prefix) {
42+
// TODO: Configurable message, message enum.
43+
String infoString = """
44+
<green>--==[</green><prefix_name><reset><green>]==--</green>
45+
<prefix_id>
46+
<prefix_description>
47+
<prefix_requirements>
48+
""";
49+
String prefix_name = "" + prefix.prefix;
50+
String prefix_id = "<yellow><u>Prefix ID:</u></yellow> " + prefix.prefixId;
51+
String prefix_description = "<yellow><u>Description:</u></yellow> " + String.join(" ", prefix.description);
52+
StringBuilder prefix_requirements = new StringBuilder("<yellow><u>Requirements:</u></yellow>");
53+
for (String requirement : prefix.requirements) {
54+
prefix_requirements.append("\n ").append(requirement);
55+
}
56+
return SimplePrefixes.getMiniMessage().deserialize(infoString,
57+
Placeholder.parsed("prefix_id", prefix_id),
58+
Placeholder.parsed("prefix_name", prefix_name),
59+
Placeholder.parsed("prefix_description", prefix_description),
60+
Placeholder.parsed("prefix_requirements", prefix_requirements.toString())
61+
);
62+
}
63+
}

0 commit comments

Comments
 (0)