新增只允许控制台执行选项...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-11-26 19:52:08 +08:00
parent 3de19da03b
commit aef2aff1b7
16 changed files with 84 additions and 63 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>cn.citycraft</groupId> <groupId>cn.citycraft</groupId>
<artifactId>Yum</artifactId> <artifactId>Yum</artifactId>
<version>1.8.5</version> <version>1.8.6</version>
<name>Yum</name> <name>Yum</name>
<description>Minecraft 服务器插件管理系统</description> <description>Minecraft 服务器插件管理系统</description>
<build> <build>
@ -55,7 +55,7 @@
</build> </build>
<properties> <properties>
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url> <jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
<update.description>&amp;c重大更新 支持一键更新老版本插件...</update.description> <update.description>&amp;c新增只允许控制台执行选项...</update.description>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<repositories> <repositories>

View File

@ -5,21 +5,10 @@ package cn.citycraft.Yum;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.utils.VersionChecker; import cn.citycraft.PluginHelper.utils.VersionChecker;
import cn.citycraft.Yum.api.YumAPI; import cn.citycraft.Yum.api.YumAPI;
import cn.citycraft.Yum.commands.CommandDelete; import cn.citycraft.Yum.commands.YumCommand;
import cn.citycraft.Yum.commands.CommandInfo;
import cn.citycraft.Yum.commands.CommandInstall;
import cn.citycraft.Yum.commands.CommandList;
import cn.citycraft.Yum.commands.CommandLoad;
import cn.citycraft.Yum.commands.CommandReload;
import cn.citycraft.Yum.commands.CommandRepo;
import cn.citycraft.Yum.commands.CommandUnload;
import cn.citycraft.Yum.commands.CommandUpdate;
import cn.citycraft.Yum.commands.CommandUpdateAll;
import cn.citycraft.Yum.commands.CommandUpgrade;
/** /**
* MC插件仓库 * MC插件仓库
@ -28,34 +17,18 @@ import cn.citycraft.Yum.commands.CommandUpgrade;
*/ */
public class Yum extends JavaPlugin { public class Yum extends JavaPlugin {
public FileConfig config; public FileConfig config;
public YumAPI yumgr;
public void initCommands() {
final HandlerSubCommand cmdhandler = new HandlerSubCommand(this, "yum");
cmdhandler.registerCommand(new CommandList(this));
cmdhandler.registerCommand(new CommandInstall(this));
cmdhandler.registerCommand(new CommandUpdate(this));
cmdhandler.registerCommand(new CommandUpdateAll(this));
cmdhandler.registerCommand(new CommandDelete(this));
cmdhandler.registerCommand(new CommandInfo(this));
cmdhandler.registerCommand(new CommandRepo(this));
cmdhandler.registerCommand(new CommandReload(this));
cmdhandler.registerCommand(new CommandLoad(this));
cmdhandler.registerCommand(new CommandUnload(this));
cmdhandler.registerCommand(new CommandUpgrade(this));
}
@Override @Override
public void onDisable() { public void onDisable() {
YumAPI.repo.cacheToJson(config); YumAPI.getRepo().cacheToJson(config);
config.save(); config.save();
} }
@Override @Override
public void onEnable() { public void onEnable() {
this.initCommands(); new YumCommand(this);
yumgr = new YumAPI(this); new YumAPI(this);
YumAPI.repo.jsonToCache(config); YumAPI.getRepo().jsonToCache(config);
YumAPI.updaterepo(); YumAPI.updaterepo();
new VersionChecker(this); new VersionChecker(this);
} }

View File

@ -22,9 +22,11 @@ import cn.citycraft.Yum.manager.RepositoryManager;
* 2015年9月1日上午10:59:47 * 2015年9月1日上午10:59:47
*/ */
public class YumAPI { public class YumAPI {
public static DownloadManager download; private static DownloadManager download;
public static PluginsManager plugman;
public static RepositoryManager repo; private static PluginsManager plugman;
private static RepositoryManager repo;
protected static Plugin main; protected static Plugin main;
@ -45,6 +47,33 @@ public class YumAPI {
plugman.deletePlugin(plugin); plugman.deletePlugin(plugin);
} }
/**
* 获得下载管理器
*
* @return {@link DownloadManager}
*/
public static DownloadManager getDownload() {
return download;
}
/**
* 获得插件管理器
*
* @return {@link PluginsManager}
*/
public static PluginsManager getPlugman() {
return plugman;
}
/**
* 获得仓库管理器
*
* @return {@link RepositoryManager}
*/
public static RepositoryManager getRepo() {
return repo;
}
/** /**
* 安装新插件 * 安装新插件
* *

View File

@ -37,7 +37,7 @@ public class CommandDelete extends BaseCommand {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) { if (plugin != null) {
if (YumAPI.plugman.deletePlugin(sender, plugin)) { if (YumAPI.getPlugman().deletePlugin(sender, plugin)) {
sender.sendMessage("§c删除: §a插件 " + pluginname + " 已从服务器卸载并删除!"); sender.sendMessage("§c删除: §a插件 " + pluginname + " 已从服务器卸载并删除!");
} else { } else {
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!"); sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");

View File

@ -51,7 +51,7 @@ public class CommandInfo extends BaseCommand {
StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a"); StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a");
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().size() == 0 ? "" : "")); sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().size() == 0 ? "" : ""));
StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a"); StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a");
sender.sendMessage("§6插件物理路径: §3" + YumAPI.plugman.getPluginFile(plugin).getAbsolutePath()); sender.sendMessage("§6插件物理路径: §3" + YumAPI.getPlugman().getPluginFile(plugin).getAbsolutePath());
} else { } else {
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
} }
@ -60,7 +60,7 @@ public class CommandInfo extends BaseCommand {
@Override @Override
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
if (!args[0].equalsIgnoreCase("install") && !args[0].equalsIgnoreCase("repo")) { if (!args[0].equalsIgnoreCase("install") && !args[0].equalsIgnoreCase("repo")) {
return StringUtil.copyPartialMatches(args[1], YumAPI.plugman.getPluginNames(false), new ArrayList<String>()); return StringUtil.copyPartialMatches(args[1], YumAPI.getPlugman().getPluginNames(false), new ArrayList<String>());
} }
return null; return null;
} }

View File

@ -59,7 +59,7 @@ public class CommandInstall extends BaseCommand {
@Override @Override
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
if (args[0].equalsIgnoreCase("install")) { if (args[0].equalsIgnoreCase("install")) {
return StringUtil.copyPartialMatches(args[1], YumAPI.repo.getAllPluginName(), new ArrayList<String>()); return StringUtil.copyPartialMatches(args[1], YumAPI.getRepo().getAllPluginName(), new ArrayList<String>());
} }
return null; return null;
} }

View File

@ -34,7 +34,7 @@ public class CommandList extends BaseCommand {
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: "); sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
sender.sendMessage("§6 - " + YumAPI.plugman.getFormattedName(plugin, true)); sender.sendMessage("§6 - " + YumAPI.getPlugman().getFormattedName(plugin, true));
} }
}; };
} }

View File

@ -37,7 +37,7 @@ public class CommandLoad extends BaseCommand {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin == null) { if (plugin == null) {
YumAPI.plugman.load(sender, pluginname); YumAPI.getPlugman().load(sender, pluginname);
} else { } else {
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!"); sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
} }

View File

@ -36,12 +36,12 @@ public class CommandReload extends BaseCommand {
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0]; final String pluginname = args[0];
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) { if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
YumAPI.plugman.reloadAll(sender); YumAPI.getPlugman().reloadAll(sender);
return; return;
} }
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) { if (plugin != null) {
YumAPI.plugman.reload(sender, plugin); YumAPI.getPlugman().reload(sender, plugin);
} else { } else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
} }

View File

@ -45,8 +45,8 @@ public class CommandRepo extends BaseCommand {
switch (cmd) { switch (cmd) {
case "add": case "add":
if (args.length == 2) { if (args.length == 2) {
if (YumAPI.repo.addRepositories(sender, args[1])) { if (YumAPI.getRepo().addRepositories(sender, args[1])) {
final String reponame = YumAPI.repo.getRepoCache(args[1]).name; final String reponame = YumAPI.getRepo().getRepoCache(args[1]).name;
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!"); sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
} else { } else {
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!"); sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
@ -57,9 +57,9 @@ public class CommandRepo extends BaseCommand {
break; break;
case "del": case "del":
if (args.length == 2) { if (args.length == 2) {
final Repositories delrepo = YumAPI.repo.getRepoCache(args[1]); final Repositories delrepo = YumAPI.getRepo().getRepoCache(args[1]);
if (delrepo != null) { if (delrepo != null) {
YumAPI.repo.delRepositories(sender, args[1]); YumAPI.getRepo().delRepositories(sender, args[1]);
sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!"); sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!");
} else { } else {
sender.sendMessage("§6仓库: §c源地址未找到!"); sender.sendMessage("§6仓库: §c源地址未找到!");
@ -69,23 +69,23 @@ public class CommandRepo extends BaseCommand {
} }
break; break;
case "delall": case "delall":
YumAPI.repo.getRepoCache().getRepos().clear(); YumAPI.getRepo().getRepoCache().getRepos().clear();
sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!"); sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!");
break; break;
case "list": case "list":
sender.sendMessage("§6仓库: §b缓存的插件信息如下 "); sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
StringUtil.sendStringArray(sender, YumAPI.repo.getAllPluginsInfo()); StringUtil.sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo());
break; break;
case "all": case "all":
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 "); sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
StringUtil.sendStringArray(sender, YumAPI.repo.getRepoCache().getAllRepoInfo()); StringUtil.sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo());
break; break;
case "clean": case "clean":
YumAPI.repo.clean(); YumAPI.getRepo().clean();
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!"); sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
break; break;
case "update": case "update":
YumAPI.repo.updateRepositories(sender); YumAPI.getRepo().updateRepositories(sender);
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!"); sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
break; break;
} }
@ -100,7 +100,7 @@ public class CommandRepo extends BaseCommand {
return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "all", "list", "delall", "clean", "update", "del" }), new ArrayList<String>()); return StringUtil.copyPartialMatches(args[1], Arrays.asList(new String[] { "add", "all", "list", "delall", "clean", "update", "del" }), new ArrayList<String>());
} }
if (args.length == 3 && (args[1] == "add" || args[1] == "del")) { if (args.length == 3 && (args[1] == "add" || args[1] == "del")) {
return StringUtil.copyPartialMatches(args[2], YumAPI.repo.getRepos().keySet(), new ArrayList<String>()); return StringUtil.copyPartialMatches(args[2], YumAPI.getRepo().getRepos().keySet(), new ArrayList<String>());
} }
} }
return null; return null;

View File

@ -37,7 +37,7 @@ public class CommandUnload extends BaseCommand {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) { if (plugin != null) {
YumAPI.plugman.unload(sender, plugin); YumAPI.getPlugman().unload(sender, plugin);
} else { } else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!"); sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
} }

View File

@ -19,9 +19,6 @@ import cn.citycraft.Yum.api.YumAPI;
public class CommandUpdate extends BaseCommand { public class CommandUpdate extends BaseCommand {
Yum main; Yum main;
/**
* @param name
*/
public CommandUpdate(final Yum main) { public CommandUpdate(final Yum main) {
super(); super();
this.main = main; this.main = main;

View File

@ -18,9 +18,6 @@ import cn.citycraft.Yum.api.YumAPI;
public class CommandUpdateAll extends BaseCommand { public class CommandUpdateAll extends BaseCommand {
Yum main; Yum main;
/**
* @param name
*/
public CommandUpdateAll(final Yum main) { public CommandUpdateAll(final Yum main) {
super(); super();
this.main = main; this.main = main;

View File

@ -35,7 +35,7 @@ public class CommandUpgrade extends BaseCommand {
@Override @Override
public void run() { public void run() {
if (args.length == 0) { if (args.length == 0) {
YumAPI.plugman.upgrade(sender); YumAPI.getPlugman().upgrade(sender);
} else { } else {
final String pluginname = args[0]; final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname); final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);

View File

@ -0,0 +1,22 @@
package cn.citycraft.Yum.commands;
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
import cn.citycraft.Yum.Yum;
public class YumCommand {
public YumCommand(final Yum yum) {
final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "yum");
cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyCommandConsole", false));
cmdhandler.registerCommand(new CommandList(yum));
cmdhandler.registerCommand(new CommandInstall(yum));
cmdhandler.registerCommand(new CommandUpdate(yum));
cmdhandler.registerCommand(new CommandUpdateAll(yum));
cmdhandler.registerCommand(new CommandDelete(yum));
cmdhandler.registerCommand(new CommandInfo(yum));
cmdhandler.registerCommand(new CommandRepo(yum));
cmdhandler.registerCommand(new CommandReload(yum));
cmdhandler.registerCommand(new CommandLoad(yum));
cmdhandler.registerCommand(new CommandUnload(yum));
cmdhandler.registerCommand(new CommandUpgrade(yum));
}
}

View File

@ -0,0 +1,3 @@
Version: 1.0
#是否只允许控制台执行插件命令
onlyCommandConsole: false