Skip to content

Commit d145992

Browse files
committed
add command for plugin info and reload
1 parent 39da951 commit d145992

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed

src/main/java/pro/cloudnode/smp/cloudnodemsg/CloudnodeMSG.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.bukkit.plugin.java.JavaPlugin;
44
import org.jetbrains.annotations.NotNull;
5+
import pro.cloudnode.smp.cloudnodemsg.command.MainCommand;
56
import pro.cloudnode.smp.cloudnodemsg.command.MessageCommand;
67

78
import java.util.Objects;
@@ -21,6 +22,7 @@ public void onEnable() {
2122
saveDefaultConfig();
2223
reload();
2324

25+
Objects.requireNonNull(getCommand("cloudnodemsg")).setExecutor(new MainCommand());
2426
Objects.requireNonNull(getCommand("message")).setExecutor(new MessageCommand());
2527
}
2628

src/main/java/pro/cloudnode/smp/cloudnodemsg/Permission.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ public final class Permission {
77
* Allows using the /msg and /r commands
88
*/
99
public final static @NotNull String USE = "cloudnodemsg.use";
10+
11+
/**
12+
* Allows reloading the plugin
13+
*/
14+
public final static @NotNull String RELOAD = "cloudnodemsg.reload";
1015
}

src/main/java/pro/cloudnode/smp/cloudnodemsg/PluginConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ public PluginConfig(final @NotNull FileConfiguration config) {
7575
);
7676
}
7777

78+
/**
79+
* Plugin reloaded
80+
*/
81+
public @NotNull Component reloaded() {
82+
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("reloaded")));
83+
}
84+
7885
/**
7986
* Name for console/server that should appear as {@code <sender>} or {@code <recipient>} in messages
8087
*/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package pro.cloudnode.smp.cloudnodemsg.command;
2+
3+
import io.papermc.paper.plugin.configuration.PluginMeta;
4+
import net.kyori.adventure.text.minimessage.MiniMessage;
5+
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
6+
import org.bukkit.command.CommandSender;
7+
import org.jetbrains.annotations.NotNull;
8+
import pro.cloudnode.smp.cloudnodemsg.CloudnodeMSG;
9+
import pro.cloudnode.smp.cloudnodemsg.Permission;
10+
import pro.cloudnode.smp.cloudnodemsg.error.NoPermissionError;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
public final class MainCommand extends Command {
16+
17+
@Override
18+
public boolean onCommand(final @NotNull CommandSender sender, final @NotNull org.bukkit.command.Command command, final @NotNull String label, @NotNull String @NotNull [] args) {
19+
if (args.length == 1) switch (args[0]) {
20+
case "reload", "rl" -> {
21+
return reload(sender);
22+
}
23+
}
24+
return info(sender);
25+
}
26+
27+
private boolean info(final @NotNull CommandSender sender) {
28+
final @NotNull PluginMeta meta = CloudnodeMSG.getInstance().getPluginMeta();
29+
return sendMessage(sender, MiniMessage.miniMessage().deserialize("<green><name> by <author></green><newline><green>Version: <white><version></white></green>",
30+
Placeholder.unparsed("name", meta.getName()),
31+
Placeholder.unparsed("author", String.join(", ", meta.getAuthors())),
32+
Placeholder.unparsed("version", meta.getVersion())
33+
));
34+
}
35+
36+
private boolean reload(final @NotNull CommandSender sender) {
37+
if (!sender.hasPermission(Permission.RELOAD)) return new NoPermissionError().send(sender);
38+
CloudnodeMSG.getInstance().reload();
39+
return sendMessage(sender, CloudnodeMSG.getInstance().config().reloaded());
40+
}
41+
42+
@Override
43+
public @NotNull List<@NotNull String> onTabComplete(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String @NotNull [] args) {
44+
final @NotNull List<@NotNull String> completions = new ArrayList<>();
45+
if (args.length == 1)
46+
if (sender.hasPermission(Permission.RELOAD) && "reload".startsWith(args[0].toLowerCase())) completions.add("reload");
47+
return completions;
48+
}
49+
}

src/main/resources/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ console-name: "Server"
1818
# <usage> - the command usage parameters
1919
usage: "<yellow>(!) Usage:</yellow> <white>/<command> <usage></white>"
2020

21+
# Plugin reloaded
22+
reloaded: "<green>(!) Plugin successfully reloaded.</green>"
23+
2124
# Error messages
2225
errors:
2326
# No permission

src/main/resources/plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ commands:
88
description: Send a private message
99
usage: /<command> <player> <message>
1010
aliases: [ "msg", "tell", "t", "whisper", "dm", "m", "pm" ]
11+
cloudnodemsg:
12+
description: CloudnodeMSG
13+
usage: /<command>

0 commit comments

Comments
 (0)