mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 14:28:46 +00:00
add help command and add getDescription on BaseCommand...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
9cd2259672
commit
304f4dad59
@ -5,7 +5,7 @@ package cn.citycraft.Yum;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.Yum.commands.CommandHandler;
|
||||
import cn.citycraft.Yum.commands.HandlerCommand;
|
||||
import cn.citycraft.Yum.manager.YumManager;
|
||||
import cn.citycraft.config.FileConfig;
|
||||
import cn.citycraft.utils.VersionChecker;
|
||||
@ -27,7 +27,7 @@ public class Yum extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
CommandHandler cmdhandler = new CommandHandler(this);
|
||||
HandlerCommand cmdhandler = new HandlerCommand(this);
|
||||
this.getCommand("yum").setExecutor(cmdhandler);
|
||||
this.getCommand("yum").setTabCompleter(cmdhandler);
|
||||
yumgr = new YumManager(this);
|
||||
|
@ -30,6 +30,41 @@ public abstract class BaseCommand {
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令参数
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param label
|
||||
* - 命令
|
||||
* @param args
|
||||
* - 命令附加参数
|
||||
* @throws CommandException
|
||||
* - 命令异常
|
||||
*/
|
||||
public abstract void execute(CommandSender sender, String label, String[] args) throws CommandException;
|
||||
|
||||
public List<String> getCommandList() {
|
||||
List<String> cmds = new ArrayList<String>();
|
||||
cmds.add(name);
|
||||
cmds.addAll(Arrays.asList(aliases));
|
||||
return cmds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得命令描述
|
||||
*
|
||||
* @return 命令描述
|
||||
*/
|
||||
public abstract String getDescription();
|
||||
|
||||
/**
|
||||
* 获得最小参数个数
|
||||
*
|
||||
* @return 最小参数个数
|
||||
*/
|
||||
public abstract int getMinimumArguments();
|
||||
|
||||
/**
|
||||
* 获取命令名称
|
||||
*
|
||||
@ -39,16 +74,6 @@ public abstract class BaseCommand {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置命令权限
|
||||
*
|
||||
* @param permission
|
||||
* - 命令权限
|
||||
*/
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得命令权限
|
||||
*
|
||||
@ -58,6 +83,13 @@ public abstract class BaseCommand {
|
||||
return permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得可能的参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getPossibleArguments();
|
||||
|
||||
/**
|
||||
* 检查Sender权限
|
||||
*
|
||||
@ -71,34 +103,6 @@ public abstract class BaseCommand {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得可能的参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getPossibleArguments();
|
||||
|
||||
/**
|
||||
* 获得最小参数个数
|
||||
*
|
||||
* @return 最小参数个数
|
||||
*/
|
||||
public abstract int getMinimumArguments();
|
||||
|
||||
/**
|
||||
* 执行命令参数
|
||||
*
|
||||
* @param sender
|
||||
* - 命令发送者
|
||||
* @param label
|
||||
* - 命令
|
||||
* @param args
|
||||
* - 命令附加参数
|
||||
* @throws CommandException
|
||||
* - 命令异常
|
||||
*/
|
||||
public abstract void execute(CommandSender sender, String label, String[] args) throws CommandException;
|
||||
|
||||
/**
|
||||
* 是否只有玩家才能执行此命令
|
||||
*
|
||||
@ -114,24 +118,23 @@ public abstract class BaseCommand {
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public final boolean isValidTrigger(String name) {
|
||||
if (this.name.equalsIgnoreCase(name)) {
|
||||
if (this.name.equalsIgnoreCase(name))
|
||||
return true;
|
||||
}
|
||||
if (aliases != null) {
|
||||
for (String alias : aliases) {
|
||||
if (alias.equalsIgnoreCase(name)) {
|
||||
if (aliases != null)
|
||||
for (String alias : aliases)
|
||||
if (alias.equalsIgnoreCase(name))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> getCommandList() {
|
||||
List<String> cmds = new ArrayList<String>();
|
||||
cmds.add(name);
|
||||
cmds.addAll(Arrays.asList(aliases));
|
||||
return cmds;
|
||||
/**
|
||||
* 设置命令权限
|
||||
*
|
||||
* @param permission
|
||||
* - 命令权限
|
||||
*/
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,13 +31,17 @@ public class CommandDelete extends BaseCommand {
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
String pluginname = args[0];
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
if (plugin != null)
|
||||
YumManager.plugman.deletePlugin(sender, plugin);
|
||||
} else {
|
||||
else
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "删除插件";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
|
@ -29,16 +29,10 @@ public class CommandInfo extends BaseCommand {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return false;
|
||||
};
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
if (args.length == 0) {
|
||||
if (args.length == 0)
|
||||
return;
|
||||
}
|
||||
String pluginname = args[0];
|
||||
Plugin plugin = main.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
@ -52,9 +46,13 @@ public class CommandInfo extends BaseCommand {
|
||||
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().size() == 0 ? "无" : ""));
|
||||
StringUtil.sendStringArray(sender, desc.getSoftDepend());
|
||||
sender.sendMessage("§6插件物理路径: §3" + YumManager.plugman.getPluginFile(plugin).getAbsolutePath());
|
||||
} else {
|
||||
} else
|
||||
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "查看插件详情";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,4 +64,9 @@ public class CommandInfo extends BaseCommand {
|
||||
public String getPossibleArguments() {
|
||||
return "<插件名称>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,11 @@ public class CommandInstall extends BaseCommand {
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "安装插件";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
|
@ -28,16 +28,15 @@ public class CommandList extends BaseCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return false;
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins())
|
||||
sender.sendMessage("§6 - " + YumManager.plugman.getFormattedName(plugin, true));
|
||||
};
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
sender.sendMessage("§6 - " + YumManager.plugman.getFormattedName(plugin, true));
|
||||
}
|
||||
public String getDescription() {
|
||||
return "列出已安装插件列表";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,4 +48,9 @@ public class CommandList extends BaseCommand {
|
||||
public String getPossibleArguments() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -31,13 +31,17 @@ public class CommandLoad extends BaseCommand {
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
String pluginname = args[0];
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin == null) {
|
||||
if (plugin == null)
|
||||
YumManager.plugman.load(sender, pluginname);
|
||||
} else {
|
||||
else
|
||||
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "载入插件";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
|
@ -35,13 +35,17 @@ public class CommandReload extends BaseCommand {
|
||||
return;
|
||||
}
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
if (plugin != null)
|
||||
YumManager.plugman.reload(sender, plugin);
|
||||
} else {
|
||||
else
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "重载插件";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
|
@ -32,14 +32,12 @@ public class CommandRepo extends BaseCommand {
|
||||
switch (cmd) {
|
||||
case "add":
|
||||
if (args.length == 2) {
|
||||
if (YumManager.repo.addRepositories(args[1])) {
|
||||
if (YumManager.repo.addRepositories(args[1]))
|
||||
sender.sendMessage("§6仓库: §a插件信息已缓存!");
|
||||
} else {
|
||||
else
|
||||
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或无法访问!");
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
sender.sendMessage("§6仓库: §c请输入源地址!");
|
||||
}
|
||||
break;
|
||||
case "list":
|
||||
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
|
||||
@ -56,6 +54,11 @@ public class CommandRepo extends BaseCommand {
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "插件源命令";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
|
@ -31,13 +31,17 @@ public class CommandUnload extends BaseCommand {
|
||||
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
|
||||
String pluginname = args[0];
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
if (plugin != null)
|
||||
YumManager.plugman.unload(sender, plugin);
|
||||
} else {
|
||||
else
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "卸载插件";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
|
@ -41,6 +41,11 @@ public class CommandUpdate extends BaseCommand {
|
||||
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "更新插件";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
@ -48,7 +53,7 @@ public class CommandUpdate extends BaseCommand {
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "<插件名称> <插件版本>";
|
||||
return "<插件名称> [插件版本]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,6 +42,11 @@ public class CommandUpgrade extends BaseCommand {
|
||||
});
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "升级插件";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 0;
|
||||
@ -49,7 +54,7 @@ public class CommandUpgrade extends BaseCommand {
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "<插件名称> <插件版本>";
|
||||
return "[插件名称]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,7 @@ import cn.citycraft.Yum.manager.YumManager;
|
||||
*
|
||||
* @author 蒋天蓓 2015年8月22日上午8:29:44
|
||||
*/
|
||||
public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
public class HandlerCommand implements CommandExecutor, TabCompleter {
|
||||
/**
|
||||
* 已注册命令列表(包括别名)
|
||||
*/
|
||||
@ -45,7 +45,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
* @param yum
|
||||
* - 插件主类
|
||||
*/
|
||||
public CommandHandler(Yum yum) {
|
||||
public HandlerCommand(Yum yum) {
|
||||
this.main = yum;
|
||||
registerCommand(new CommandList(yum));
|
||||
registerCommand(new CommandInstall(yum));
|
||||
@ -93,6 +93,12 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
if (args.length == 0)
|
||||
return true;
|
||||
String subcmd = args[0];
|
||||
if (subcmd.equalsIgnoreCase("help")) {
|
||||
sender.sendMessage("§6=========YUM插件帮助列表=========");
|
||||
for (BaseCommand command : commandlist)
|
||||
sender.sendMessage(String.format("§6/yum §a%1$s %2$s §6- §b%3$s", command.getName(), command.getPossibleArguments(), command.getDescription()));
|
||||
return true;
|
||||
}
|
||||
String[] subargs = moveStrings(args, 1);
|
||||
for (BaseCommand command : commandlist)
|
||||
if (command.isValidTrigger(subcmd)) {
|
Loading…
Reference in New Issue
Block a user