Skip to content

Commit a7c92fd

Browse files
authored
Refactor EverythingCommand to use Adventure API for improved message formatting and color handling
1 parent b405b99 commit a7c92fd

File tree

1 file changed

+50
-19
lines changed

1 file changed

+50
-19
lines changed

src/main/java/me/crazyg/everything/commands/EverythingCommand.java

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package me.crazyg.everything.commands;
22

33
import me.crazyg.everything.Everything;
4-
import org.bukkit.ChatColor;
4+
import net.kyori.adventure.text.Component;
5+
import net.kyori.adventure.text.format.NamedTextColor;
56
import org.bukkit.command.Command;
67
import org.bukkit.command.CommandExecutor;
78
import org.bukkit.command.CommandSender;
@@ -18,40 +19,70 @@ public EverythingCommand(Everything plugin) {
1819
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
1920
if (args.length == 0) {
2021
// Display help/info page if no sub-command is provided
21-
sender.sendMessage(ChatColor.GOLD + "Everything Plugin - Help");
22-
sender.sendMessage(ChatColor.YELLOW + "/everything reload" + ChatColor.WHITE + " - Reload the plugin configuration.");
23-
sender.sendMessage(ChatColor.YELLOW + "/everything info" + ChatColor.WHITE + " - Display plugin information.");
24-
sender.sendMessage(ChatColor.YELLOW + "/gmc" + ChatColor.WHITE + " - Changes your gamemode to creative mode");
25-
sender.sendMessage(ChatColor.YELLOW + "/gms" + ChatColor.WHITE + " - Changes your gamemode to survival mode");
26-
sender.sendMessage(ChatColor.YELLOW + "/gmsp" + ChatColor.WHITE + " - Changes your gamemode to spectator mode");
27-
sender.sendMessage(ChatColor.YELLOW + "/gma" + ChatColor.WHITE + " - Changes your gamemode to adventure mode");
28-
sender.sendMessage(ChatColor.YELLOW + "/setspawn" + ChatColor.WHITE + " - Set the spawn point for the world.");
29-
sender.sendMessage(ChatColor.YELLOW + "/spawn" + ChatColor.WHITE + " - Teleport to the spawn point.");
30-
sender.sendMessage(ChatColor.YELLOW + "/report" + ChatColor.WHITE + " - Report a player to the server staff.");
31-
sender.sendMessage(ChatColor.YELLOW + "/god" + ChatColor.WHITE + " - Toggle god mode on/off.");
22+
sender.sendMessage(Component.text("Everything Plugin - Help").color(NamedTextColor.GOLD));
23+
sender.sendMessage(Component.text()
24+
.append(Component.text("/everything reload").color(NamedTextColor.YELLOW))
25+
.append(Component.text(" - Reload the plugin configuration.").color(NamedTextColor.WHITE)));
26+
sender.sendMessage(Component.text()
27+
.append(Component.text("/everything info").color(NamedTextColor.YELLOW))
28+
.append(Component.text(" - Display plugin information.").color(NamedTextColor.WHITE)));
29+
sender.sendMessage(Component.text()
30+
.append(Component.text("/gmc").color(NamedTextColor.YELLOW))
31+
.append(Component.text(" - Changes your gamemode to creative mode").color(NamedTextColor.WHITE)));
32+
sender.sendMessage(Component.text()
33+
.append(Component.text("/gms").color(NamedTextColor.YELLOW))
34+
.append(Component.text(" - Changes your gamemode to survival mode").color(NamedTextColor.WHITE)));
35+
sender.sendMessage(Component.text()
36+
.append(Component.text("/gmsp").color(NamedTextColor.YELLOW))
37+
.append(Component.text(" - Changes your gamemode to spectator mode").color(NamedTextColor.WHITE)));
38+
sender.sendMessage(Component.text()
39+
.append(Component.text("/gma").color(NamedTextColor.YELLOW))
40+
.append(Component.text(" - Changes your gamemode to adventure mode").color(NamedTextColor.WHITE)));
41+
sender.sendMessage(Component.text()
42+
.append(Component.text("/setspawn").color(NamedTextColor.YELLOW))
43+
.append(Component.text(" - Set the spawn point for the world.").color(NamedTextColor.WHITE)));
44+
sender.sendMessage(Component.text()
45+
.append(Component.text("/spawn").color(NamedTextColor.YELLOW))
46+
.append(Component.text(" - Teleport to the spawn point.").color(NamedTextColor.WHITE)));
47+
sender.sendMessage(Component.text()
48+
.append(Component.text("/report").color(NamedTextColor.YELLOW))
49+
.append(Component.text(" - Report a player to the server staff.").color(NamedTextColor.WHITE)));
50+
sender.sendMessage(Component.text()
51+
.append(Component.text("/god").color(NamedTextColor.YELLOW))
52+
.append(Component.text(" - Toggle god mode on/off.").color(NamedTextColor.WHITE)));
3253
return true;
3354
}
3455

3556
// Handle sub-commands
3657
switch (args[0].toLowerCase()) {
3758
case "reload":
3859
if (!sender.hasPermission("everything.reload")) {
39-
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
60+
sender.sendMessage(Component.text("You do not have permission to use this command.")
61+
.color(NamedTextColor.RED));
4062
return true;
4163
}
4264
plugin.reloadConfig();
43-
sender.sendMessage(ChatColor.GREEN + "Plugin configuration reloaded successfully!");
65+
sender.sendMessage(Component.text("Plugin configuration reloaded successfully!")
66+
.color(NamedTextColor.GREEN));
4467
return true;
4568

4669
case "info":
47-
sender.sendMessage(ChatColor.GOLD + "Everything Plugin - Info");
48-
sender.sendMessage(ChatColor.YELLOW + "Version: " + ChatColor.WHITE + plugin.getDescription().getVersion());
49-
sender.sendMessage(ChatColor.YELLOW + "Author: " + ChatColor.WHITE + String.join(", ", plugin.getDescription().getAuthors()));
50-
sender.sendMessage(ChatColor.YELLOW + "Description: " + ChatColor.WHITE + plugin.getDescription().getDescription());
70+
sender.sendMessage(Component.text("Everything Plugin - Info")
71+
.color(NamedTextColor.GOLD));
72+
sender.sendMessage(Component.text()
73+
.append(Component.text("Version: ").color(NamedTextColor.YELLOW))
74+
.append(Component.text(plugin.getPluginMeta().getVersion()).color(NamedTextColor.WHITE)));
75+
sender.sendMessage(Component.text()
76+
.append(Component.text("Author: ").color(NamedTextColor.YELLOW))
77+
.append(Component.text(String.join(", ", plugin.getPluginMeta().getAuthors())).color(NamedTextColor.WHITE)));
78+
sender.sendMessage(Component.text()
79+
.append(Component.text("Description: ").color(NamedTextColor.YELLOW))
80+
.append(Component.text(plugin.getPluginMeta().getDescription()).color(NamedTextColor.WHITE)));
5181
return true;
5282

5383
default:
54-
sender.sendMessage(ChatColor.RED + "Unknown sub-command. Use /everything for help.");
84+
sender.sendMessage(Component.text("Unknown sub-command. Use /everything for help.")
85+
.color(NamedTextColor.RED));
5586
return true;
5687
}
5788
}

0 commit comments

Comments
 (0)