2026-02-13 18:50:05 +08:00
|
|
|
|
package com.playerblocklife;
|
|
|
|
|
|
|
|
|
|
|
|
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 java.util.UUID;
|
|
|
|
|
|
|
|
|
|
|
|
public class AdminCommands implements CommandExecutor {
|
|
|
|
|
|
private final PlayerBlockLife plugin;
|
|
|
|
|
|
|
|
|
|
|
|
public AdminCommands(PlayerBlockLife plugin) {
|
|
|
|
|
|
this.plugin = plugin;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2026-02-13 22:03:17 +08:00
|
|
|
|
MessageManager msgManager = plugin.getMessageManager();
|
|
|
|
|
|
ConfigManager config = plugin.getConfigManager();
|
|
|
|
|
|
|
|
|
|
|
|
String commandName = command.getName().toLowerCase();
|
|
|
|
|
|
|
|
|
|
|
|
// 检查命令是否启用
|
|
|
|
|
|
if (!config.isCommandEnabled(commandName)) {
|
|
|
|
|
|
String message = msgManager.getMessage("game.errors.command_disabled",
|
|
|
|
|
|
"&c此命令已被禁用!");
|
|
|
|
|
|
sender.sendMessage(message);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查管理员权限和配置
|
|
|
|
|
|
if (!sender.hasPermission("playerblocklife.admin") || config.isAdminOnly(commandName)) {
|
|
|
|
|
|
String message = msgManager.getMessage("game.errors.no_permission",
|
|
|
|
|
|
"&c你没有权限使用此命令!");
|
|
|
|
|
|
sender.sendMessage(message);
|
2026-02-13 18:50:05 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 22:03:17 +08:00
|
|
|
|
if (commandName.equals("pblreload")) {
|
2026-02-13 20:56:03 +08:00
|
|
|
|
// 调用插件的完整重载方法
|
|
|
|
|
|
plugin.reloadPluginConfig();
|
2026-02-13 22:03:17 +08:00
|
|
|
|
String message = msgManager.getCommandMessage("pblreload", "success",
|
|
|
|
|
|
"&a配置已重载!");
|
|
|
|
|
|
sender.sendMessage(message);
|
2026-02-13 18:50:05 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 22:03:17 +08:00
|
|
|
|
if (commandName.equals("pbldelete")) {
|
2026-02-13 18:50:05 +08:00
|
|
|
|
if (args.length < 1) {
|
2026-02-13 22:03:17 +08:00
|
|
|
|
String usage = msgManager.getCommandMessage("pbldelete", "usage",
|
|
|
|
|
|
"&c用法: /pbldelete <玩家>");
|
|
|
|
|
|
sender.sendMessage(usage);
|
2026-02-13 18:50:05 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String targetName = args[0];
|
|
|
|
|
|
Player target = Bukkit.getPlayer(targetName);
|
|
|
|
|
|
UUID targetId;
|
|
|
|
|
|
|
|
|
|
|
|
if (target != null) {
|
|
|
|
|
|
targetId = target.getUniqueId();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 尝试从离线玩家获取UUID
|
2026-02-13 20:56:03 +08:00
|
|
|
|
try {
|
|
|
|
|
|
targetId = Bukkit.getOfflinePlayer(targetName).getUniqueId();
|
|
|
|
|
|
} catch (Exception e) {
|
2026-02-13 22:03:17 +08:00
|
|
|
|
String message = msgManager.getMessage("game.errors.player_not_found",
|
|
|
|
|
|
"&c找不到玩家: {player}");
|
|
|
|
|
|
message = message.replace("{player}", targetName);
|
|
|
|
|
|
sender.sendMessage(message);
|
2026-02-13 20:56:03 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2026-02-13 18:50:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
plugin.getBlockManager().clearPlayerBlocks(targetId);
|
2026-02-13 22:03:17 +08:00
|
|
|
|
String message = msgManager.getCommandMessage("pbldelete", "success",
|
|
|
|
|
|
"&a已删除玩家 {player} 的生命方块!");
|
|
|
|
|
|
message = message.replace("{player}", targetName);
|
|
|
|
|
|
sender.sendMessage(message);
|
2026-02-13 18:50:05 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 22:03:17 +08:00
|
|
|
|
if (commandName.equals("pblrevive")) {
|
2026-02-13 18:50:05 +08:00
|
|
|
|
Player target;
|
|
|
|
|
|
|
|
|
|
|
|
if (args.length < 1) {
|
|
|
|
|
|
if (!(sender instanceof Player)) {
|
2026-02-13 22:03:17 +08:00
|
|
|
|
String usage = msgManager.getCommandMessage("pblrevive", "usage",
|
|
|
|
|
|
"&c用法: /pblrevive [玩家]");
|
|
|
|
|
|
sender.sendMessage(usage);
|
2026-02-13 18:50:05 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
target = (Player) sender;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
target = Bukkit.getPlayer(args[0]);
|
|
|
|
|
|
if (target == null) {
|
2026-02-13 22:03:17 +08:00
|
|
|
|
String message = msgManager.getMessage("game.errors.player_offline",
|
|
|
|
|
|
"&c玩家 {player} 不在线!");
|
|
|
|
|
|
message = message.replace("{player}", args[0]);
|
|
|
|
|
|
sender.sendMessage(message);
|
2026-02-13 18:50:05 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 20:56:03 +08:00
|
|
|
|
if (plugin.getLifeSystem() != null) {
|
|
|
|
|
|
plugin.getLifeSystem().revivePlayer(target);
|
2026-02-13 22:03:17 +08:00
|
|
|
|
String message = msgManager.getCommandMessage("pblrevive", "success",
|
|
|
|
|
|
"&a玩家 {player} 已复活!");
|
|
|
|
|
|
message = message.replace("{player}", target.getName());
|
|
|
|
|
|
sender.sendMessage(message);
|
2026-02-13 20:56:03 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
sender.sendMessage("§c复活失败:生命系统未初始化");
|
|
|
|
|
|
}
|
2026-02-13 18:50:05 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 22:03:17 +08:00
|
|
|
|
if (commandName.equals("pblstats")) {
|
2026-02-13 20:56:03 +08:00
|
|
|
|
if (plugin.getBlockManager() == null) {
|
|
|
|
|
|
sender.sendMessage("§c方块管理器未初始化");
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 18:50:05 +08:00
|
|
|
|
int totalPlayers = plugin.getBlockManager().getPlayerBlocksCount();
|
|
|
|
|
|
int totalBlocks = plugin.getBlockManager().getTotalBlocksCount();
|
2026-02-13 22:03:17 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取统计标题
|
|
|
|
|
|
String title = msgManager.getCommandMessage("pblstats", "title",
|
|
|
|
|
|
"&6=== PlayerBlockLife 统计 ===");
|
|
|
|
|
|
sender.sendMessage(title);
|
|
|
|
|
|
|
|
|
|
|
|
// 在线玩家统计
|
|
|
|
|
|
String onlineMsg = msgManager.getCommandMessage("pblstats", "online_players",
|
|
|
|
|
|
"&e在线玩家: {count}");
|
|
|
|
|
|
onlineMsg = onlineMsg.replace("{count}", String.valueOf(Bukkit.getOnlinePlayers().size()));
|
|
|
|
|
|
sender.sendMessage(onlineMsg);
|
|
|
|
|
|
|
|
|
|
|
|
// 总方块统计
|
|
|
|
|
|
String blocksMsg = msgManager.getCommandMessage("pblstats", "total_blocks",
|
|
|
|
|
|
"&e总生命方块: {count}");
|
|
|
|
|
|
blocksMsg = blocksMsg.replace("{count}", String.valueOf(totalBlocks));
|
|
|
|
|
|
sender.sendMessage(blocksMsg);
|
|
|
|
|
|
|
|
|
|
|
|
// 淘汰玩家统计
|
|
|
|
|
|
int eliminatedCount = 0;
|
|
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
|
|
|
|
if (plugin.getBlockManager().getRemainingBlocks(player.getUniqueId()) == 0) {
|
|
|
|
|
|
eliminatedCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
String eliminatedMsg = msgManager.getCommandMessage("pblstats", "eliminated_players",
|
|
|
|
|
|
"&e已淘汰玩家: {count}");
|
|
|
|
|
|
eliminatedMsg = eliminatedMsg.replace("{count}", String.valueOf(eliminatedCount));
|
|
|
|
|
|
sender.sendMessage(eliminatedMsg);
|
|
|
|
|
|
|
|
|
|
|
|
sender.sendMessage("§7在线玩家详情:");
|
2026-02-13 18:50:05 +08:00
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
|
|
|
|
int blocks = plugin.getBlockManager().getRemainingBlocks(player.getUniqueId());
|
2026-02-13 20:56:03 +08:00
|
|
|
|
String status = blocks > 0 ? "§a存活" : "§c已淘汰";
|
|
|
|
|
|
sender.sendMessage("§7- " + player.getName() + ": §e" + blocks + " §7/ §a5 §7(" + status + "§7)");
|
2026-02-13 18:50:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 20:56:03 +08:00
|
|
|
|
sender.sendMessage("§a=================================");
|
2026-02-13 18:50:05 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 22:03:17 +08:00
|
|
|
|
String unknownMsg = msgManager.getMessage("game.errors.invalid_arguments",
|
|
|
|
|
|
"&c未知的管理员命令!");
|
|
|
|
|
|
sender.sendMessage(unknownMsg);
|
2026-02-13 18:50:05 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|