Skip to content

Commit

Permalink
refactor(commands): refactoring the command system and adding kill fu…
Browse files Browse the repository at this point in the history
…nctionality

 - Renamed multiple classes and packages to make the structure clearer
 - Added implementation and completion of the kill command
 - Updated the processing logic of baseplugin command - optimized the implementation of configuration, data query and other functions
  • Loading branch information
Suisuroru committed Jan 30, 2025
1 parent 8b4bb5c commit 318bd71
Show file tree
Hide file tree
Showing 22 changed files with 134 additions and 76 deletions.
55 changes: 24 additions & 31 deletions src/main/java/fun/suya/suisuroru/commands/CommandRegister.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,40 @@
package fun.suya.suisuroru.commands;

import fun.suya.suisuroru.commands.execute.CommandManager;
import fun.suya.suisuroru.commands.execute.othercommands.ConfigRoot;
import fun.suya.suisuroru.commands.execute.othercommands.DataRoot;
import fun.suya.suisuroru.commands.execute.othercommands.Help;
import fun.suya.suisuroru.commands.execute.othercommands.ReportQuery;
import fun.suya.suisuroru.commands.execute.othercommands.config.Reload;
import fun.suya.suisuroru.commands.execute.vanilla.Ban;
import fun.suya.suisuroru.commands.execute.vanilla.Kill;
import fun.suya.suisuroru.commands.execute.vanilla.Pardon;
import fun.suya.suisuroru.commands.tab.othercommands.BasePluginTab;
import fun.suya.suisuroru.commands.tab.othercommands.ConfigTab;
import fun.suya.suisuroru.commands.tab.othercommands.DataTab;
import fun.suya.suisuroru.commands.tab.othercommands.ReportTab;
import fun.suya.suisuroru.commands.tab.vanilla.BanTab;
import fun.suya.suisuroru.commands.tab.vanilla.KillTab;
import fun.suya.suisuroru.commands.tab.vanilla.PardonTab;
import fun.suya.suisuroru.config.Config;
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.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 org.bukkit.plugin.java.JavaPlugin;

public class CommandRegister {
public static void registerCommand(JavaPlugin plugin) {
if (Config.VanillaCommandsRewritten) {
if (fun.suya.suisuroru.config.Config.VanillaCommandsRewritten) {
// vanilla functions
plugin.getCommand("ban").setExecutor(new Ban());
plugin.getCommand("ban").setTabCompleter(new BanTab());
plugin.getCommand("pardon").setExecutor(new Pardon());
plugin.getCommand("pardon").setTabCompleter(new PardonTab());
plugin.getCommand("kill").setExecutor(new Kill());
plugin.getCommand("kill").setTabCompleter(new KillTab());
plugin.getCommand("ban").setExecutor(new fun.suya.suisuroru.commands.execute.vanilla.Ban());
plugin.getCommand("ban").setTabCompleter(new Ban());
plugin.getCommand("pardon").setExecutor(new fun.suya.suisuroru.commands.execute.vanilla.Pardon());
plugin.getCommand("pardon").setTabCompleter(new Pardon());
plugin.getCommand("kill").setExecutor(new fun.suya.suisuroru.commands.execute.vanilla.Kill());
plugin.getCommand("kill").setTabCompleter(new Kill());
}
// new functions
plugin.getCommand("basepluginhelp").setExecutor(new Help());
plugin.getCommand("report").setExecutor(new ReportCommand());
plugin.getCommand("report").setTabCompleter(new ReportTab());
plugin.getCommand("bpconfig").setExecutor(new ConfigRoot());
plugin.getCommand("bpconfig").setTabCompleter(new ConfigTab());
plugin.getCommand("report").setTabCompleter(new 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());
plugin.getCommand("baseplugin").setExecutor(new CommandManager());
plugin.getCommand("baseplugin").setTabCompleter(new BasePluginTab());
plugin.getCommand("baseplugin").setExecutor(new fun.suya.suisuroru.commands.execute.othercommands.BasePlugin());
plugin.getCommand("baseplugin").setTabCompleter(new BasePlugin());
plugin.getCommand("query-report").setExecutor(new ReportQuery());
plugin.getCommand("bpdata").setExecutor(new DataRoot());
plugin.getCommand("bpdata").setTabCompleter(new DataTab());
plugin.getCommand("bpdata").setExecutor(new Data());
plugin.getCommand("bpdata").setTabCompleter(new fun.suya.suisuroru.commands.tab.othercommands.sub.Data());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package fun.suya.suisuroru.commands.execute;
package fun.suya.suisuroru.commands.execute.othercommands;

import fun.suya.suisuroru.commands.execute.othercommands.ConfigRoot;
import fun.suya.suisuroru.commands.execute.othercommands.DataRoot;
import fun.suya.suisuroru.commands.execute.othercommands.Help;
import fun.suya.suisuroru.commands.execute.othercommands.ReportQuery;
import fun.suya.suisuroru.commands.execute.othercommands.sub.*;
import fun.xd.suka.command.ReportCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -17,13 +14,14 @@
* Date: 2024/9/28 13:43
* function: Manager command in baseplugin
*/
public class CommandManager implements CommandExecutor {
public class BasePlugin implements CommandExecutor {

ReportCommand report = new ReportCommand();
ConfigRoot config = new ConfigRoot();
Config config = new Config();
ReportQuery query = new ReportQuery();
Help help = new Help();
DataRoot data = new DataRoot();
Data data = new Data();
Kill kill = new Kill();

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Expand Down Expand Up @@ -58,6 +56,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
data.onCommand(sender, command, label, subArgs);
break;
}
case "kill": {
kill.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
@@ -1,8 +1,8 @@
package fun.suya.suisuroru.commands.execute.othercommands;
package fun.suya.suisuroru.commands.execute.othercommands.sub;

import fun.suya.suisuroru.commands.execute.othercommands.config.Query;
import fun.suya.suisuroru.commands.execute.othercommands.config.Reload;
import fun.suya.suisuroru.commands.execute.othercommands.config.Set;
import fun.suya.suisuroru.commands.execute.othercommands.sub.config.Query;
import fun.suya.suisuroru.commands.execute.othercommands.sub.config.Reload;
import fun.suya.suisuroru.commands.execute.othercommands.sub.config.Set;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -16,7 +16,7 @@
* Date: 2024/10/14 22:41
* function: Config settings
*/
public class ConfigRoot implements CommandExecutor {
public class Config implements CommandExecutor {

Reload reload = new Reload();
Query query = new Query();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package fun.suya.suisuroru.commands.execute.othercommands;
package fun.suya.suisuroru.commands.execute.othercommands.sub;

import fun.suya.suisuroru.commands.execute.othercommands.data.Query;
import fun.suya.suisuroru.commands.execute.othercommands.sub.data.Query;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

public class DataRoot implements CommandExecutor {
public class Data implements CommandExecutor {
Query query = new Query();

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.execute.othercommands;
package fun.suya.suisuroru.commands.execute.othercommands.sub;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -23,6 +23,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
sender.sendMessage("§4查询举报记录:/baseplugin query-report");
sender.sendMessage("§4配置文件处理:使用/baseplugin config获取更多帮助");
sender.sendMessage("§4验证数据处理:使用/baseplugin data获取更多帮助");
sender.sendMessage("§4异常玩家kill:使用/baseplugin kill <玩家名>");
} else if (!sender.isOp()) {
sender.sendMessage("§a举报玩家:/baseplugin report <玩家名> <原因>");
}
Expand All @@ -33,6 +34,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
sender.sendMessage("[管理员/控制台]查询举报记录:/baseplugin query-report");
sender.sendMessage("[管理员/控制台]配置文件处理:使用/baseplugin config获取更多帮助");
sender.sendMessage("[管理员/控制台]验证数据处理:使用/baseplugin data获取更多帮助");
sender.sendMessage("[管理员/控制台]异常玩家kill:使用/baseplugin kill <玩家名>");
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fun.suya.suisuroru.commands.execute.othercommands.sub;

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

public class Kill implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!sender.isOp()) {
sender.sendMessage("你没有权限执行此命令!");
return true;
}
if (args.length == 0) {
sender.sendMessage("§4请输入玩家名");
} else {
Player target = sender.getServer().getPlayer(args[0]);
if (target != null && target.isOnline()) {
target.setHealth(0);
Bukkit.broadcastMessage("§4BasePlugin已尝试清除玩家: " + args[0]);
} else {
sender.sendMessage("§4玩家不在线或不存在");
}
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.execute.othercommands;
package fun.suya.suisuroru.commands.execute.othercommands.sub;

import fun.suya.suisuroru.data.Report.ReportDataActions;
import org.bukkit.command.Command;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.execute.othercommands.config;
package fun.suya.suisuroru.commands.execute.othercommands.sub.config;

import fun.suya.suisuroru.config.Config;
import org.bukkit.command.Command;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.execute.othercommands.config;
package fun.suya.suisuroru.commands.execute.othercommands.sub.config;

import fun.suya.suisuroru.config.ConfigManager;
import org.bukkit.command.Command;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.execute.othercommands.config;
package fun.suya.suisuroru.commands.execute.othercommands.sub.config;

import fun.suya.suisuroru.config.ConfigManager;
import org.bukkit.command.Command;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package fun.suya.suisuroru.commands.execute.othercommands.data;
package fun.suya.suisuroru.commands.execute.othercommands.sub.data;

import fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions.DataQueryByName;
import fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions.DataQueryByQQ;
import fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions.DataQueryByUUID;
import fun.suya.suisuroru.commands.execute.othercommands.sub.data.query.DataQueryByName;
import fun.suya.suisuroru.commands.execute.othercommands.sub.data.query.DataQueryByQQ;
import fun.suya.suisuroru.commands.execute.othercommands.sub.data.query.DataQueryByUUID;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions;
package fun.suya.suisuroru.commands.execute.othercommands.sub.data.query;

import fun.suya.suisuroru.data.AuthData.DataGet;
import org.bukkit.command.Command;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions;
package fun.suya.suisuroru.commands.execute.othercommands.sub.data.query;

import fun.suya.suisuroru.data.AuthData.DataGet;
import org.bukkit.command.Command;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions;
package fun.suya.suisuroru.commands.execute.othercommands.sub.data.query;

import fun.suya.suisuroru.data.AuthData.DataGet;
import org.bukkit.command.Command;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fun.suya.suisuroru.commands.tab.othercommands;

import fun.suya.suisuroru.commands.tab.othercommands.sub.Config;
import fun.suya.suisuroru.commands.tab.othercommands.sub.Data;
import fun.suya.suisuroru.commands.tab.othercommands.sub.Kill;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
Expand All @@ -15,20 +18,22 @@
* Date: 2024/10/15 03:01
* function: Provides tab completion for the baseplugin command
*/
public class BasePluginTab implements TabCompleter {
public class BasePlugin implements TabCompleter {
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
ConfigTab config = new ConfigTab();
ConfigTab report = new ConfigTab();
DataTab data = new DataTab();
Config config = new Config();
Config report = new Config();
Data data = new Data();
Kill kill = new Kill();
List<String> completions = new ArrayList<>();
if (args.length == 1) {
completions.add("help");
completions.add("report");
completions.add("config");
completions.add("data");
completions.add("query-report");
completions.add("kill");
} else if (args.length >= 2) {
String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
switch (args[0].toLowerCase()) {
Expand All @@ -44,6 +49,10 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
completions = data.onTabComplete(sender, command, label, subArgs);
break;
}
case "kill": {
completions = kill.onTabComplete(sender, command, label, subArgs);
break;
}
default: {
sender.sendMessage("Unknown command. Usage: /baseplugin config [reload|query|set] [args...]");
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.tab.othercommands;
package fun.suya.suisuroru.commands.tab.othercommands.sub;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -16,7 +16,7 @@
* Date: 2024/10/18 22:11
* function: Provides tab completion for the bpconfig command
*/
public class ConfigTab implements TabCompleter {
public class Config implements TabCompleter {
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.tab.othercommands;
package fun.suya.suisuroru.commands.tab.othercommands.sub;

import fun.suya.suisuroru.module.impl.OnlinePlayerListGet;
import org.bukkit.command.Command;
Expand All @@ -10,7 +10,7 @@
import java.util.ArrayList;
import java.util.List;

public class DataTab implements TabCompleter {
public class Data implements TabCompleter {
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fun.suya.suisuroru.commands.tab.othercommands.sub;

import fun.suya.suisuroru.module.impl.OnlinePlayerListGet;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class Kill implements TabCompleter {

@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
List<String> completions = new ArrayList<>();
if (args.length == 1) {
// 返回所有在线玩家的名字
completions.addAll(OnlinePlayerListGet.GetOnlinePlayerList());
}
return completions;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.suya.suisuroru.commands.tab.othercommands;
package fun.suya.suisuroru.commands.tab.othercommands.sub;

import fun.suya.suisuroru.module.impl.OnlinePlayerListGet;
import org.bukkit.command.Command;
Expand All @@ -15,7 +15,7 @@
* Date: 2024/10/15 01:41
* function: Provides tab completion for the report command
*/
public class ReportTab implements TabCompleter {
public class Report implements TabCompleter {

@Nullable
@Override
Expand All @@ -24,9 +24,6 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
if (args.length == 1) {
// 返回所有在线玩家的名字
completions.addAll(OnlinePlayerListGet.GetOnlinePlayerList());
} else if (args.length >= 2) {
// 不返回任何补全结果
return completions; // 返回空列表
}
return completions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.ArrayList;
import java.util.List;

public class BanTab implements TabCompleter {
public class Ban implements TabCompleter {

public static List<String> getOnlinePlayerNames(CommandSender sender, String partialName) {
List<String> playerNames = new ArrayList<>();
Expand Down
Loading

0 comments on commit 318bd71

Please sign in to comment.