Skip to content

Commit 7c7003f

Browse files
authored
Enhance command feedback with fancy messages in EverythingCommand and KillCommand; update Updater to notify players about updates and downloads only once.
1 parent 1113135 commit 7c7003f

3 files changed

Lines changed: 79 additions & 58 deletions

File tree

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

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ public EverythingCommand(Everything plugin) {
4646
@Override
4747
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
4848
if (args.length == 0) {
49+
// Blue theme, not bold, prefix for every message
4950
Everything.sendFancy(sender, Component.text()
50-
.append(Component.text("❓ Help & Commands\n").color(NamedTextColor.GOLD).decorate(net.kyori.adventure.text.format.TextDecoration.BOLD))
51+
.append(Component.text("❓ Everything Help & Commands\n").color(NamedTextColor.BLUE))
5152
.append(Component.text("Click a command for usage. Hover for description.\n").color(NamedTextColor.GRAY))
5253
.build());
5354

@@ -66,10 +67,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
6667
}
6768
}
6869
Component cmdComponent = Component.text()
69-
.append(Component.text("• ").color(NamedTextColor.LIGHT_PURPLE))
70+
.append(Component.text("• ").color(NamedTextColor.BLUE))
7071
.append(Component.text(usageLine.toString())
7172
.color(NamedTextColor.AQUA)
72-
.decorate(net.kyori.adventure.text.format.TextDecoration.BOLD)
7373
.clickEvent(net.kyori.adventure.text.event.ClickEvent.suggestCommand("/" + cmd))
7474
.hoverEvent(net.kyori.adventure.text.event.HoverEvent.showText(
7575
Component.text(descText == null || descText.isEmpty() ? "No description." : descText)
@@ -89,13 +89,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
8989
switch (args[0].toLowerCase()) {
9090
case "reload":
9191
if (!sender.hasPermission("everything.reload")) {
92-
sender.sendMessage(Component.text("You do not have permission to use this command.")
93-
.color(NamedTextColor.RED));
92+
Everything.sendFancy(sender, Component.text("You do not have permission to use this command.").color(NamedTextColor.RED));
9493
return true;
9594
}
9695
plugin.reloadConfig();
97-
sender.sendMessage(Component.text("Plugin configuration reloaded successfully!")
98-
.color(NamedTextColor.GREEN));
96+
Everything.sendFancy(sender, Component.text("Plugin configuration reloaded successfully!").color(NamedTextColor.GREEN));
9997
return true;
10098

10199
case "info": {
@@ -144,32 +142,30 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
144142

145143
case "checkupdate":
146144
if (!sender.hasPermission("everything.admin")) {
147-
sender.sendMessage(Component.text("You don't have permission to check for updates!")
148-
.color(NamedTextColor.RED));
145+
Everything.sendFancy(sender, Component.text("You don't have permission to check for updates!").color(NamedTextColor.RED));
149146
return true;
150147
}
151-
152148
if (updater.isUpdateAvailable()) {
153-
sender.sendMessage(Component.text()
149+
Everything.sendFancy(sender, Component.text()
154150
.append(Component.text("A new version is available! ").color(NamedTextColor.GREEN))
155151
.append(Component.text("Current: ").color(NamedTextColor.YELLOW))
156152
.append(Component.text(plugin.getPluginMeta().getVersion()).color(NamedTextColor.WHITE))
157153
.append(Component.text(" Latest: ").color(NamedTextColor.YELLOW))
158-
.append(Component.text(updater.getLatestVersion()).color(NamedTextColor.WHITE)));
154+
.append(Component.text(updater.getLatestVersion()).color(NamedTextColor.WHITE))
155+
.build());
159156
} else {
160-
sender.sendMessage(Component.text("You are running the latest version!")
161-
.color(NamedTextColor.GREEN));
157+
Everything.sendFancy(sender, Component.text("You are running the latest version!").color(NamedTextColor.GREEN));
162158
}
163159
return true;
164160

165161

166162
case "test":
167-
sender.sendMessage(Component.text("[TEST] Listing and attempting to run all commands:").color(NamedTextColor.AQUA));
163+
Everything.sendFancy(sender, Component.text("[TEST] Listing and attempting to run all commands:").color(NamedTextColor.AQUA));
168164
List<String> testCommands = getPluginCommands();
169165
for (String cmd : testCommands) {
170166
org.bukkit.command.PluginCommand pluginCmd = plugin.getCommand(cmd);
171167
if (pluginCmd == null) {
172-
sender.sendMessage(Component.text("/" + cmd + " (Not registered)").color(NamedTextColor.RED));
168+
Everything.sendFancy(sender, Component.text("/" + cmd + " (Not registered)").color(NamedTextColor.RED));
173169
continue;
174170
}
175171
String usage = pluginCmd.getUsage();
@@ -185,7 +181,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
185181
if (descText != null && !descText.isEmpty()) {
186182
line.append(" - ").append(descText);
187183
}
188-
sender.sendMessage(Component.text(line.toString()).color(NamedTextColor.GRAY));
184+
Everything.sendFancy(sender, Component.text(line.toString()).color(NamedTextColor.GRAY));
189185
// Try to run the command with the sender as the player if possible
190186
try {
191187
String[] testArgs = new String[0];
@@ -204,24 +200,24 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
204200
if (sender instanceof org.bukkit.entity.Player) {
205201
testArgs = new String[] { ((org.bukkit.entity.Player)sender).getName() };
206202
} else {
207-
sender.sendMessage(Component.text("(Skipped: Needs player context)").color(NamedTextColor.DARK_GRAY));
203+
Everything.sendFancy(sender, Component.text("(Skipped: Needs player context)").color(NamedTextColor.DARK_GRAY));
208204
continue;
209205
}
210206
}
211207
pluginCmd.execute(sender, cmd, testArgs);
212-
sender.sendMessage(Component.text("(Executed)").color(NamedTextColor.DARK_GREEN));
208+
Everything.sendFancy(sender, Component.text("(Executed)").color(NamedTextColor.DARK_GREEN));
213209
} catch (Exception ex) {
214-
sender.sendMessage(Component.text("(Error executing: " + ex.getMessage() + ")").color(NamedTextColor.RED));
210+
Everything.sendFancy(sender, Component.text("(Error executing: " + ex.getMessage() + ")").color(NamedTextColor.RED));
215211
}
216212
}
217213

218214
// --- Fake updater test ---
219-
sender.sendMessage(Component.text("[TEST] Faking updater state...").color(NamedTextColor.LIGHT_PURPLE));
215+
Everything.sendFancy(sender, Component.text("[TEST] Faking updater state...").color(NamedTextColor.LIGHT_PURPLE));
220216
// Simulate update available
221217
String fakeCurrent = plugin.getPluginMeta().getVersion();
222218
String fakeLatest = "v99.99.99-FAKE";
223219
String fakeUrl = "https://example.com/fake-update.jar";
224-
sender.sendMessage(Component.text("[TEST] Simulated update available!").color(NamedTextColor.GREEN)
220+
Everything.sendFancy(sender, Component.text("[TEST] Simulated update available!").color(NamedTextColor.GREEN)
225221
.append(Component.text(" Current: ").color(NamedTextColor.YELLOW))
226222
.append(Component.text(fakeCurrent).color(NamedTextColor.WHITE))
227223
.append(Component.text(" Latest: ").color(NamedTextColor.YELLOW))
@@ -230,40 +226,39 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
230226
.append(Component.text(fakeUrl).color(NamedTextColor.AQUA))
231227
.append(Component.text(")").color(NamedTextColor.GRAY))
232228
);
233-
sender.sendMessage(Component.text("[TEST] (No real update performed, this is a debug simulation.)").color(NamedTextColor.DARK_GRAY));
229+
Everything.sendFancy(sender, Component.text("[TEST] (No real update performed, this is a debug simulation.)").color(NamedTextColor.DARK_GRAY));
234230

235231
// --- Print debug info ---
236-
sender.sendMessage(Component.text("[DEBUG] Plugin info:").color(NamedTextColor.YELLOW));
237-
sender.sendMessage(Component.text(" Name: " + plugin.getPluginMeta().getName()).color(NamedTextColor.GRAY));
238-
sender.sendMessage(Component.text(" Version: " + plugin.getPluginMeta().getVersion()).color(NamedTextColor.GRAY));
239-
sender.sendMessage(Component.text(" Authors: " + String.join(", ", plugin.getPluginMeta().getAuthors())).color(NamedTextColor.GRAY));
240-
sender.sendMessage(Component.text(" Description: " + plugin.getPluginMeta().getDescription()).color(NamedTextColor.GRAY));
241-
sender.sendMessage(Component.text("[DEBUG] Java version: " + System.getProperty("java.version")).color(NamedTextColor.GRAY));
242-
sender.sendMessage(Component.text("[DEBUG] OS: " + System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ")").color(NamedTextColor.GRAY));
243-
sender.sendMessage(Component.text("[DEBUG] Bukkit version: " + plugin.getServer().getBukkitVersion()).color(NamedTextColor.GRAY));
244-
sender.sendMessage(Component.text("[DEBUG] Data folder: " + plugin.getDataFolder().getAbsolutePath()).color(NamedTextColor.GRAY));
232+
Everything.sendFancy(sender, Component.text("[DEBUG] Plugin info:").color(NamedTextColor.YELLOW));
233+
Everything.sendFancy(sender, Component.text(" Name: " + plugin.getPluginMeta().getName()).color(NamedTextColor.GRAY));
234+
Everything.sendFancy(sender, Component.text(" Version: " + plugin.getPluginMeta().getVersion()).color(NamedTextColor.GRAY));
235+
Everything.sendFancy(sender, Component.text(" Authors: " + String.join(", ", plugin.getPluginMeta().getAuthors())).color(NamedTextColor.GRAY));
236+
Everything.sendFancy(sender, Component.text(" Description: " + plugin.getPluginMeta().getDescription()).color(NamedTextColor.GRAY));
237+
Everything.sendFancy(sender, Component.text("[DEBUG] Java version: " + System.getProperty("java.version")).color(NamedTextColor.GRAY));
238+
Everything.sendFancy(sender, Component.text("[DEBUG] OS: " + System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ")").color(NamedTextColor.GRAY));
239+
Everything.sendFancy(sender, Component.text("[DEBUG] Bukkit version: " + plugin.getServer().getBukkitVersion()).color(NamedTextColor.GRAY));
240+
Everything.sendFancy(sender, Component.text("[DEBUG] Data folder: " + plugin.getDataFolder().getAbsolutePath()).color(NamedTextColor.GRAY));
245241

246242
// --- Simulate config reload ---
247-
sender.sendMessage(Component.text("[TEST] Simulating config reload...").color(NamedTextColor.LIGHT_PURPLE));
243+
Everything.sendFancy(sender, Component.text("[TEST] Simulating config reload...").color(NamedTextColor.LIGHT_PURPLE));
248244
try {
249245
plugin.reloadConfig();
250-
sender.sendMessage(Component.text("[TEST] Config reload simulated successfully.").color(NamedTextColor.GREEN));
246+
Everything.sendFancy(sender, Component.text("[TEST] Config reload simulated successfully.").color(NamedTextColor.GREEN));
251247
} catch (Exception e) {
252-
sender.sendMessage(Component.text("[TEST] Config reload failed: " + e.getMessage()).color(NamedTextColor.RED));
248+
Everything.sendFancy(sender, Component.text("[TEST] Config reload failed: " + e.getMessage()).color(NamedTextColor.RED));
253249
}
254250

255251
// --- Simulate permission check ---
256-
sender.sendMessage(Component.text("[TEST] Permission check for 'everything.admin': ")
252+
Everything.sendFancy(sender, Component.text("[TEST] Permission check for 'everything.admin': ")
257253
.color(NamedTextColor.LIGHT_PURPLE)
258254
.append(Component.text(sender.hasPermission("everything.admin") ? "GRANTED" : "DENIED").color(sender.hasPermission("everything.admin") ? NamedTextColor.GREEN : NamedTextColor.RED))
259255
);
260256

261-
sender.sendMessage(Component.text("[TEST] End of diagnostics.").color(NamedTextColor.AQUA));
257+
Everything.sendFancy(sender, Component.text("[TEST] End of diagnostics.").color(NamedTextColor.AQUA));
262258
return true;
263259

264260
default:
265-
sender.sendMessage(Component.text("Unknown sub-command. Use /everything for help.")
266-
.color(NamedTextColor.RED));
261+
Everything.sendFancy(sender, Component.text("Unknown sub-command. Use /everything for help.").color(NamedTextColor.RED));
267262
return true;
268263
}
269264
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
1313
if (sender instanceof Player p) {
1414
if (args.length == 0) {
1515
p.setHealth(0);
16-
p.sendMessage(Component.text("You Have Opted To DIEEEE!")
16+
me.crazyg.everything.Everything.sendFancy(p, Component.text("You Have Opted To DIEEEE!")
1717
.color(NamedTextColor.DARK_RED)
1818
.decorate(TextDecoration.BOLD));
1919
} else {
@@ -23,15 +23,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
2323
// Bukkit.selectEntities supports selectors for 1.13+
2424
java.util.List<org.bukkit.entity.Entity> entities = Bukkit.selectEntities(sender, selector);
2525
if (entities.isEmpty()) {
26-
p.sendMessage(Component.text("No players/entities matched selector: " + selector)
26+
me.crazyg.everything.Everything.sendFancy(p, Component.text("No players/entities matched selector: " + selector)
2727
.color(NamedTextColor.RED));
2828
return true;
2929
}
3030
int killed = 0;
3131
for (org.bukkit.entity.Entity entity : entities) {
3232
if (entity instanceof Player target) {
3333
target.setHealth(0);
34-
target.sendMessage(Component.text("You have been killed by " + p.getName())
34+
me.crazyg.everything.Everything.sendFancy(target, Component.text("You have been killed by " + p.getName())
3535
.color(NamedTextColor.DARK_RED)
3636
.decorate(TextDecoration.BOLD));
3737
killed++;
@@ -40,32 +40,32 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
4040
killed++;
4141
}
4242
}
43-
p.sendMessage(Component.text("Killed " + killed + " target(s) for selector: " + selector)
43+
me.crazyg.everything.Everything.sendFancy(p, Component.text("Killed " + killed + " target(s) for selector: " + selector)
4444
.color(NamedTextColor.DARK_RED)
4545
.decorate(TextDecoration.BOLD));
4646
} catch (IllegalArgumentException ex) {
4747
// Not a selector, try as player name (case-insensitive, partial match)
4848
Player target = Bukkit.getServer().getPlayer(selector);
4949
if (target == null) {
50-
p.sendMessage(Component.text("This Player is not online")
50+
me.crazyg.everything.Everything.sendFancy(p, Component.text("This Player is not online")
5151
.color(NamedTextColor.RED));
5252
} else {
5353
target.setHealth(0);
54-
target.sendMessage(Component.text("You have been killed by " + p.getName())
54+
me.crazyg.everything.Everything.sendFancy(target, Component.text("You have been killed by " + p.getName())
5555
.color(NamedTextColor.DARK_RED)
5656
.decorate(TextDecoration.BOLD));
57-
p.sendMessage(Component.text("Killed player: " + target.getName())
57+
me.crazyg.everything.Everything.sendFancy(p, Component.text("Killed player: " + target.getName())
5858
.color(NamedTextColor.DARK_RED)
5959
.decorate(TextDecoration.BOLD));
6060
}
6161
}
6262
}
6363
} else if (sender instanceof ConsoleCommandSender p) {
64-
p.sendMessage(Component.text("Command cannot be run by console, Silly")
64+
me.crazyg.everything.Everything.sendFancy(p, Component.text("Command cannot be run by console, Silly")
6565
.color(NamedTextColor.DARK_RED)
6666
.decorate(TextDecoration.BOLD));
6767
} else if (sender instanceof BlockCommandSender p) {
68-
p.sendMessage(Component.text("Command cannot be run by command block, L")
68+
me.crazyg.everything.Everything.sendFancy(p, Component.text("Command cannot be run by command block, L")
6969
.color(NamedTextColor.DARK_RED)
7070
.decorate(TextDecoration.BOLD));
7171
}

0 commit comments

Comments
 (0)