Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
调整处理 reload 和 debug 命令的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
slinar committed Apr 12, 2019
1 parent 88ce5ea commit 0ea259b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 39 deletions.
75 changes: 38 additions & 37 deletions src/me/commandBlock/CmdCb.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;

public class CmdCb {
Expand All @@ -15,53 +16,53 @@ public class CmdCb {
}
};
static boolean debug = false;
private static CommandBlock ins = CommandBlock.getIns();

public static boolean exec(CommandSender sender, String[] args) {
if (sender instanceof org.bukkit.command.ConsoleCommandSender) {
public static void exec(CommandSender sender, String[] args) {
if (checkPermissions(sender)) {
if ((args.length == 1) && (args[0].equalsIgnoreCase("reload"))) {
ConfigFile.loadConfig();
return true;
reload(sender);
}
}

if (sender instanceof Player) {
// Player player = (Player)sender;

if (sender.isOp()) {
if ((args.length == 1) && (args[0].equalsIgnoreCase("reload"))) {
ConfigFile.loadConfig();
sender.sendMessage(ConfigFile.PREFIX + "已重载配置!");
return true;
}
if ((args.length >= 1) && (args[0].equalsIgnoreCase("debug"))) {
if (args.length == 1) {
sender.sendMessage(ConfigFile.PREFIX + "/cb debug on - 开启debug");
sender.sendMessage(ConfigFile.PREFIX + "/cb debug off - 关闭debug");
} else if (args[1].equalsIgnoreCase("on")) {
debug = true;
sender.sendMessage(ConfigFile.PREFIX + "debug 已开启!");
} else if (args[1].equalsIgnoreCase("off")) {
debug = false;
sender.sendMessage(ConfigFile.PREFIX + "debug 已关闭!");
} else {
sender.sendMessage(ConfigFile.PREFIX + "/cb debug on - 开启调试");
sender.sendMessage(ConfigFile.PREFIX + "/cb debug off - 关闭调试");
}
return true;
}
} else {
sender.sendMessage(ConfigFile.PREFIX + "你没有权限这样做!");
return true;
if ((args.length >= 1) && (args[0].equalsIgnoreCase("debug"))) {
debug(sender, args);
}

} else {
sender.sendMessage(ConfigFile.PREFIX_C + "你没有权限这样做!");
}
return false;
}

public static List<String> tab(CommandSender sender, String[] args) {
if ((args == null) || (args.length <= 1)) {
return args1;
}
return new ArrayList<String>();
}

private static boolean checkPermissions(CommandSender sender) {
if (sender instanceof ConsoleCommandSender) return true;
if (sender instanceof Player) return sender.isOp();
ins.getLogger().warning("未处理的命令发送者:" + sender.getClass().getName());
return false;
}

private static void reload(CommandSender sender) {
ConfigFile.loadConfig();
sender.sendMessage(ConfigFile.PREFIX_C + "已重载配置!");
}

private static void debug(CommandSender sender, String[] args) {
if (args.length == 1) {
sender.sendMessage(ConfigFile.PREFIX_C + "/cb debug on - 开启debug");
sender.sendMessage(ConfigFile.PREFIX_C + "/cb debug off - 关闭debug");
} else if (args[1].equalsIgnoreCase("on")) {
debug = true;
sender.sendMessage(ConfigFile.PREFIX_C + "debug 已开启!");
} else if (args[1].equalsIgnoreCase("off")) {
debug = false;
sender.sendMessage(ConfigFile.PREFIX_C + "debug 已关闭!");
} else {
sender.sendMessage(ConfigFile.PREFIX_C + "/cb debug on - 开启调试");
sender.sendMessage(ConfigFile.PREFIX_C + "/cb debug off - 关闭调试");
}
}
}
6 changes: 4 additions & 2 deletions src/me/commandBlock/CmdExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

public class CmdExecutor implements CommandExecutor, TabCompleter {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("cb"))
return CmdCb.exec(sender, args);
if (cmd.getName().equalsIgnoreCase("cb")) {
CmdCb.exec(sender, args);
return true;
}
return false;
}

Expand Down

0 comments on commit 0ea259b

Please sign in to comment.