Skip to content

Commit

Permalink
[skip]feat(commands): add rcon command support
Browse files Browse the repository at this point in the history
  • Loading branch information
Suisuroru committed Feb 3, 2025
1 parent c21d1f7 commit 34dc05e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
13 changes: 5 additions & 8 deletions src/main/java/fun/suya/suisuroru/commands/CommandRegister.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package fun.suya.suisuroru.commands;

import fun.suya.suisuroru.commands.execute.othercommands.sub.Config;
import fun.suya.suisuroru.commands.execute.othercommands.sub.Data;
import fun.suya.suisuroru.commands.execute.othercommands.sub.Help;
import fun.suya.suisuroru.commands.execute.othercommands.sub.ReportQuery;
import fun.suya.suisuroru.commands.execute.othercommands.sub.*;
import fun.suya.suisuroru.commands.execute.othercommands.sub.config.Reload;
import fun.suya.suisuroru.commands.tab.othercommands.BasePlugin;
import fun.suya.suisuroru.commands.tab.othercommands.sub.Report;
import fun.suya.suisuroru.commands.tab.vanilla.Ban;
import fun.suya.suisuroru.commands.tab.vanilla.Kill;
import fun.suya.suisuroru.commands.tab.vanilla.Pardon;
import fun.xd.suka.command.ReportCommand;
import fun.suya.suisuroru.commands.execute.othercommands.sub.Report;
import org.bukkit.plugin.java.JavaPlugin;

public class CommandRegister {
Expand All @@ -26,8 +22,8 @@ public static void registerCommand(JavaPlugin plugin) {
}
// new functions
plugin.getCommand("basepluginhelp").setExecutor(new Help());
plugin.getCommand("report").setExecutor(new ReportCommand());
plugin.getCommand("report").setTabCompleter(new Report());
plugin.getCommand("report").setExecutor(new Report());
plugin.getCommand("report").setTabCompleter(new fun.suya.suisuroru.commands.tab.othercommands.sub.Report());
plugin.getCommand("bpconfig").setExecutor(new Config());
plugin.getCommand("bpconfig").setTabCompleter(new fun.suya.suisuroru.commands.tab.othercommands.sub.Config());
plugin.getCommand("bpreload").setExecutor(new Reload());
Expand All @@ -36,5 +32,6 @@ public static void registerCommand(JavaPlugin plugin) {
plugin.getCommand("query-report").setExecutor(new ReportQuery());
plugin.getCommand("bpdata").setExecutor(new Data());
plugin.getCommand("bpdata").setTabCompleter(new fun.suya.suisuroru.commands.tab.othercommands.sub.Data());
plugin.getCommand("rcon").setExecutor(new Rcon());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fun.suya.suisuroru.commands.execute.othercommands;

import fun.suya.suisuroru.commands.execute.othercommands.sub.*;
import fun.xd.suka.command.ReportCommand;
import fun.suya.suisuroru.commands.execute.othercommands.sub.Report;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -16,12 +16,13 @@
*/
public class BasePlugin implements CommandExecutor {

ReportCommand report = new ReportCommand();
Report report = new Report();
Config config = new Config();
ReportQuery query = new ReportQuery();
Help help = new Help();
Data data = new Data();
Kill kill = new Kill();
Rcon rcon = new Rcon();

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Expand Down Expand Up @@ -60,6 +61,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
kill.onCommand(sender, command, label, subArgs);
break;
}
case "rcon": {
rcon.onCommand(sender, command, label, subArgs);
break;
}
default: {
sender.sendMessage("Unknown command. Usage: /baseplugin [report|reload|config|data|query-report] [args...]");
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fun.suya.suisuroru.commands.execute.othercommands.sub;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import static fun.suya.suisuroru.rcon.RconCommandExecute.executeRconCommand;

public class Rcon implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
sender.sendMessage("此命令为测试命令,不显示使用方法");
String address = args[0];
String[] parts = address.split(":");
String IP;
int port;
if (parts.length == 2) {
IP = parts[0];
port = Integer.parseInt(parts[1]);
} else {
sender.sendMessage("请输入正确的IP地址和端口号");
return true;
}
String psd = args[1];
StringBuilder CommandBuilder = new StringBuilder();
for (int i = 2; i < args.length; i++) {
CommandBuilder.append(args[i]).append(" ");
}
String full_command = CommandBuilder.toString().trim();
sender.sendMessage(executeRconCommand(IP, port, psd, full_command));
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.xd.suka.command;
package fun.suya.suisuroru.commands.execute.othercommands.sub;

import fun.suya.suisuroru.config.Config;
import fun.suya.suisuroru.data.Report.ReportDataManager;
Expand All @@ -21,7 +21,7 @@

import static fun.xd.suka.Main.LOGGER;

public class ReportCommand implements CommandExecutor {
public class Report implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (sender instanceof Player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
completions.add("data");
completions.add("query-report");
completions.add("kill");
completions.add("rcon");
} else if (args.length >= 2) {
String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
switch (args[0].toLowerCase()) {
Expand Down

0 comments on commit 34dc05e

Please sign in to comment.