clean up command...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-09-22 20:03:59 +08:00
parent 7ee4ff9dcd
commit 8c17dd8908
11 changed files with 83 additions and 204 deletions

View File

@ -20,6 +20,10 @@ public abstract class BaseCommand {
private String name; private String name;
private String permission; private String permission;
private String[] aliases; private String[] aliases;
private String description = "";
private int minimumArguments = 0;
private String possibleArguments = "";
private boolean onlyPlayerExecutable = false;
public BaseCommand(String name) { public BaseCommand(String name) {
this(name, new String[0]); this(name, new String[0]);
@ -56,14 +60,18 @@ public abstract class BaseCommand {
* *
* @return 命令描述 * @return 命令描述
*/ */
public abstract String getDescription(); public String getDescription() {
return description;
}
/** /**
* 获得最小参数个数 * 获得最小参数个数
* *
* @return 最小参数个数 * @return 最小参数个数
*/ */
public abstract int getMinimumArguments(); public int getMinimumArguments() {
return minimumArguments;
}
/** /**
* 获取命令名称 * 获取命令名称
@ -88,7 +96,9 @@ public abstract class BaseCommand {
* *
* @return * @return
*/ */
public abstract String getPossibleArguments(); public String getPossibleArguments() {
return possibleArguments;
}
/** /**
* 检查Sender权限 * 检查Sender权限
@ -108,7 +118,9 @@ public abstract class BaseCommand {
* *
* @return 是否为玩家命令 * @return 是否为玩家命令
*/ */
public abstract boolean isOnlyPlayerExecutable(); public boolean isOnlyPlayerExecutable() {
return onlyPlayerExecutable;
}
/** /**
* 命令匹配检测 * 命令匹配检测
@ -127,6 +139,36 @@ public abstract class BaseCommand {
return false; return false;
} }
/**
* 设置命令的描述信息
*
* @param description
* - 命令描述
*/
public void setDescription(String description) {
this.description = description;
}
/**
* 设置命令的最小参数个数
*
* @param minimumArguments
* - 最小参数个数
*/
public void setMinimumArguments(int minimumArguments) {
this.minimumArguments = minimumArguments;
}
/**
* 设置是否只允许玩家执行
*
* @param onlyPlayerExecutable
* - 是否只允许玩家执行
*/
public void setOnlyPlayerExecutable(boolean onlyPlayerExecutable) {
this.onlyPlayerExecutable = onlyPlayerExecutable;
}
/** /**
* 设置命令权限 * 设置命令权限
* *
@ -137,4 +179,14 @@ public abstract class BaseCommand {
this.permission = permission; this.permission = permission;
} }
/**
* 设置可能的命令参数
*
* @param possibleArguments
* - 可能的命令参数
*/
public void setPossibleArguments(String possibleArguments) {
this.possibleArguments = possibleArguments;
}
} }

View File

@ -25,6 +25,9 @@ public class CommandDelete extends BaseCommand {
public CommandDelete(Yum main) { public CommandDelete(Yum main) {
super("delete"); super("delete");
this.main = main; this.main = main;
setDescription("删除插件");
setMinimumArguments(1);
setPossibleArguments("<插件名称>");
} }
@Override @Override
@ -39,24 +42,4 @@ public class CommandDelete extends BaseCommand {
else else
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}; };
@Override
public String getDescription() {
return "删除插件";
}
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public String getPossibleArguments() {
return "<插件名称>";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
} }

View File

@ -27,6 +27,8 @@ public class CommandInfo extends BaseCommand {
public CommandInfo(Yum main) { public CommandInfo(Yum main) {
super("info"); super("info");
this.main = main; this.main = main;
setDescription("查看插件详情");
setPossibleArguments("<插件名称>");
} }
@Override @Override
@ -49,24 +51,4 @@ public class CommandInfo extends BaseCommand {
} else } else
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
}; };
@Override
public String getDescription() {
return "查看插件详情";
}
@Override
public int getMinimumArguments() {
return 0;
}
@Override
public String getPossibleArguments() {
return "<插件名称>";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
} }

View File

@ -25,6 +25,9 @@ public class CommandInstall extends BaseCommand {
public CommandInstall(Yum main) { public CommandInstall(Yum main) {
super("install"); super("install");
this.main = main; this.main = main;
setDescription("安装插件");
setMinimumArguments(1);
setPossibleArguments("<插件名称>");
} }
@Override @Override
@ -42,24 +45,4 @@ public class CommandInstall extends BaseCommand {
sender.sendMessage("§c插件已安装在服务器 需要更新请使用yum update " + pluginname + "!"); sender.sendMessage("§c插件已安装在服务器 需要更新请使用yum update " + pluginname + "!");
}; };
@Override
public String getDescription() {
return "安装插件";
}
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public String getPossibleArguments() {
return "<插件名称>";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
} }

View File

@ -25,6 +25,7 @@ public class CommandList extends BaseCommand {
public CommandList(Yum main) { public CommandList(Yum main) {
super("list"); super("list");
this.main = main; this.main = main;
setDescription("列出已安装插件列表");
} }
@Override @Override
@ -33,24 +34,4 @@ public class CommandList extends BaseCommand {
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) for (Plugin plugin : Bukkit.getPluginManager().getPlugins())
sender.sendMessage("§6 - " + YumManager.plugman.getFormattedName(plugin, true)); sender.sendMessage("§6 - " + YumManager.plugman.getFormattedName(plugin, true));
}; };
@Override
public String getDescription() {
return "列出已安装插件列表";
}
@Override
public int getMinimumArguments() {
return 0;
}
@Override
public String getPossibleArguments() {
return "";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
} }

View File

@ -25,6 +25,9 @@ public class CommandLoad extends BaseCommand {
public CommandLoad(Yum main) { public CommandLoad(Yum main) {
super("load"); super("load");
this.main = main; this.main = main;
setDescription("载入插件");
setMinimumArguments(1);
setPossibleArguments("<插件名称>");
} }
@Override @Override
@ -36,24 +39,4 @@ public class CommandLoad extends BaseCommand {
else else
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!"); sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
}; };
@Override
public String getDescription() {
return "载入插件";
}
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public String getPossibleArguments() {
return "<插件名称>";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
} }

View File

@ -25,6 +25,9 @@ public class CommandReload extends BaseCommand {
public CommandReload(Yum main) { public CommandReload(Yum main) {
super("reload"); super("reload");
this.main = main; this.main = main;
setDescription("重载插件");
setMinimumArguments(1);
setPossibleArguments("<插件名称|all|*>");
} }
@Override @Override
@ -40,24 +43,4 @@ public class CommandReload extends BaseCommand {
else else
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}; };
@Override
public String getDescription() {
return "重载插件";
}
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public String getPossibleArguments() {
return "<插件名称|all|*>";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
} }

View File

@ -24,6 +24,9 @@ public class CommandRepo extends BaseCommand {
public CommandRepo(Yum main) { public CommandRepo(Yum main) {
super("repo"); super("repo");
this.main = main; this.main = main;
setDescription("插件源命令");
setMinimumArguments(1);
setPossibleArguments("<add|del|clean|list> <仓库名称>");
} }
@Override @Override
@ -53,24 +56,4 @@ public class CommandRepo extends BaseCommand {
break; break;
} }
}; };
@Override
public String getDescription() {
return "插件源命令";
}
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public String getPossibleArguments() {
return "<add|del|clean|list> <仓库名称>";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
} }

View File

@ -25,6 +25,9 @@ public class CommandUnload extends BaseCommand {
public CommandUnload(Yum main) { public CommandUnload(Yum main) {
super("unload"); super("unload");
this.main = main; this.main = main;
setDescription("卸载插件");
setMinimumArguments(1);
setPossibleArguments("<插件名称>");
} }
@Override @Override
@ -36,24 +39,4 @@ public class CommandUnload extends BaseCommand {
else else
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}; };
@Override
public String getDescription() {
return "卸载插件";
}
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public String getPossibleArguments() {
return "<插件名称>";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
} }

View File

@ -23,6 +23,9 @@ public class CommandUpdate extends BaseCommand {
public CommandUpdate(Yum main) { public CommandUpdate(Yum main) {
super("update"); super("update");
this.main = main; this.main = main;
setDescription("更新插件");
setMinimumArguments(1);
setPossibleArguments("<插件名称> [插件版本]");
} }
@Override @Override
@ -40,24 +43,4 @@ public class CommandUpdate extends BaseCommand {
else else
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!"); sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
}; };
@Override
public String getDescription() {
return "更新插件";
}
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public String getPossibleArguments() {
return "<插件名称> [插件版本]";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
} }

View File

@ -23,6 +23,9 @@ public class CommandUpgrade extends BaseCommand {
public CommandUpgrade(Yum main) { public CommandUpgrade(Yum main) {
super("upgrade"); super("upgrade");
this.main = main; this.main = main;
setDescription("升级插件");
setMinimumArguments(1);
setPossibleArguments("<插件名称>");
} }
@Override @Override
@ -41,24 +44,4 @@ public class CommandUpgrade extends BaseCommand {
} }
}); });
}; };
@Override
public String getDescription() {
return "升级插件";
}
@Override
public int getMinimumArguments() {
return 0;
}
@Override
public String getPossibleArguments() {
return "[插件名称]";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
} }