mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-12-23 05:08:47 +00:00
新增只允许控制台执行选项...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
3de19da03b
commit
aef2aff1b7
4
pom.xml
4
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.citycraft</groupId>
|
||||
<artifactId>Yum</artifactId>
|
||||
<version>1.8.5</version>
|
||||
<version>1.8.6</version>
|
||||
<name>Yum</name>
|
||||
<description>Minecraft 服务器插件管理系统</description>
|
||||
<build>
|
||||
@ -55,7 +55,7 @@
|
||||
</build>
|
||||
<properties>
|
||||
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
||||
<update.description>&c重大更新 支持一键更新老版本插件...</update.description>
|
||||
<update.description>&c新增只允许控制台执行选项...</update.description>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<repositories>
|
||||
|
@ -5,21 +5,10 @@ package cn.citycraft.Yum;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||
import cn.citycraft.Yum.api.YumAPI;
|
||||
import cn.citycraft.Yum.commands.CommandDelete;
|
||||
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;
|
||||
import cn.citycraft.Yum.commands.YumCommand;
|
||||
|
||||
/**
|
||||
* MC插件仓库
|
||||
@ -28,34 +17,18 @@ import cn.citycraft.Yum.commands.CommandUpgrade;
|
||||
*/
|
||||
public class Yum extends JavaPlugin {
|
||||
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
|
||||
public void onDisable() {
|
||||
YumAPI.repo.cacheToJson(config);
|
||||
YumAPI.getRepo().cacheToJson(config);
|
||||
config.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.initCommands();
|
||||
yumgr = new YumAPI(this);
|
||||
YumAPI.repo.jsonToCache(config);
|
||||
new YumCommand(this);
|
||||
new YumAPI(this);
|
||||
YumAPI.getRepo().jsonToCache(config);
|
||||
YumAPI.updaterepo();
|
||||
new VersionChecker(this);
|
||||
}
|
||||
|
@ -22,9 +22,11 @@ import cn.citycraft.Yum.manager.RepositoryManager;
|
||||
* 2015年9月1日上午10:59:47
|
||||
*/
|
||||
public class YumAPI {
|
||||
public static DownloadManager download;
|
||||
public static PluginsManager plugman;
|
||||
public static RepositoryManager repo;
|
||||
private static DownloadManager download;
|
||||
|
||||
private static PluginsManager plugman;
|
||||
|
||||
private static RepositoryManager repo;
|
||||
|
||||
protected static Plugin main;
|
||||
|
||||
@ -45,6 +47,33 @@ public class YumAPI {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装新插件
|
||||
*
|
||||
|
@ -37,7 +37,7 @@ public class CommandDelete extends BaseCommand {
|
||||
final String pluginname = args[0];
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
if (YumAPI.plugman.deletePlugin(sender, plugin)) {
|
||||
if (YumAPI.getPlugman().deletePlugin(sender, plugin)) {
|
||||
sender.sendMessage("§c删除: §a插件 " + pluginname + " 已从服务器卸载并删除!");
|
||||
} else {
|
||||
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
|
||||
|
@ -51,7 +51,7 @@ public class CommandInfo extends BaseCommand {
|
||||
StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a");
|
||||
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().size() == 0 ? "无" : ""));
|
||||
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 {
|
||||
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
@ -60,7 +60,7 @@ public class CommandInfo extends BaseCommand {
|
||||
@Override
|
||||
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")) {
|
||||
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;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class CommandInstall extends BaseCommand {
|
||||
@Override
|
||||
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||
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;
|
||||
}
|
||||
|
@ -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 {
|
||||
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
|
||||
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
sender.sendMessage("§6 - " + YumAPI.plugman.getFormattedName(plugin, true));
|
||||
sender.sendMessage("§6 - " + YumAPI.getPlugman().getFormattedName(plugin, true));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class CommandLoad extends BaseCommand {
|
||||
final String pluginname = args[0];
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin == null) {
|
||||
YumAPI.plugman.load(sender, pluginname);
|
||||
YumAPI.getPlugman().load(sender, pluginname);
|
||||
} else {
|
||||
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
|
||||
}
|
||||
|
@ -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 {
|
||||
final String pluginname = args[0];
|
||||
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
|
||||
YumAPI.plugman.reloadAll(sender);
|
||||
YumAPI.getPlugman().reloadAll(sender);
|
||||
return;
|
||||
}
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
YumAPI.plugman.reload(sender, plugin);
|
||||
YumAPI.getPlugman().reload(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ public class CommandRepo extends BaseCommand {
|
||||
switch (cmd) {
|
||||
case "add":
|
||||
if (args.length == 2) {
|
||||
if (YumAPI.repo.addRepositories(sender, args[1])) {
|
||||
final String reponame = YumAPI.repo.getRepoCache(args[1]).name;
|
||||
if (YumAPI.getRepo().addRepositories(sender, args[1])) {
|
||||
final String reponame = YumAPI.getRepo().getRepoCache(args[1]).name;
|
||||
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
|
||||
@ -57,9 +57,9 @@ public class CommandRepo extends BaseCommand {
|
||||
break;
|
||||
case "del":
|
||||
if (args.length == 2) {
|
||||
final Repositories delrepo = YumAPI.repo.getRepoCache(args[1]);
|
||||
final Repositories delrepo = YumAPI.getRepo().getRepoCache(args[1]);
|
||||
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更新缓存!");
|
||||
} else {
|
||||
sender.sendMessage("§6仓库: §c源地址未找到!");
|
||||
@ -69,23 +69,23 @@ public class CommandRepo extends BaseCommand {
|
||||
}
|
||||
break;
|
||||
case "delall":
|
||||
YumAPI.repo.getRepoCache().getRepos().clear();
|
||||
YumAPI.getRepo().getRepoCache().getRepos().clear();
|
||||
sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!");
|
||||
break;
|
||||
case "list":
|
||||
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
|
||||
StringUtil.sendStringArray(sender, YumAPI.repo.getAllPluginsInfo());
|
||||
StringUtil.sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo());
|
||||
break;
|
||||
case "all":
|
||||
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
|
||||
StringUtil.sendStringArray(sender, YumAPI.repo.getRepoCache().getAllRepoInfo());
|
||||
StringUtil.sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo());
|
||||
break;
|
||||
case "clean":
|
||||
YumAPI.repo.clean();
|
||||
YumAPI.getRepo().clean();
|
||||
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
|
||||
break;
|
||||
case "update":
|
||||
YumAPI.repo.updateRepositories(sender);
|
||||
YumAPI.getRepo().updateRepositories(sender);
|
||||
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
|
||||
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>());
|
||||
}
|
||||
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;
|
||||
|
@ -37,7 +37,7 @@ public class CommandUnload extends BaseCommand {
|
||||
final String pluginname = args[0];
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin != null) {
|
||||
YumAPI.plugman.unload(sender, plugin);
|
||||
YumAPI.getPlugman().unload(sender, plugin);
|
||||
} else {
|
||||
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
|
||||
}
|
||||
|
@ -19,9 +19,6 @@ import cn.citycraft.Yum.api.YumAPI;
|
||||
public class CommandUpdate extends BaseCommand {
|
||||
Yum main;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandUpdate(final Yum main) {
|
||||
super();
|
||||
this.main = main;
|
||||
|
@ -18,9 +18,6 @@ import cn.citycraft.Yum.api.YumAPI;
|
||||
public class CommandUpdateAll extends BaseCommand {
|
||||
Yum main;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandUpdateAll(final Yum main) {
|
||||
super();
|
||||
this.main = main;
|
||||
|
@ -35,7 +35,7 @@ public class CommandUpgrade extends BaseCommand {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.length == 0) {
|
||||
YumAPI.plugman.upgrade(sender);
|
||||
YumAPI.getPlugman().upgrade(sender);
|
||||
} else {
|
||||
final String pluginname = args[0];
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
|
22
src/main/java/cn/citycraft/Yum/commands/YumCommand.java
Normal file
22
src/main/java/cn/citycraft/Yum/commands/YumCommand.java
Normal 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));
|
||||
}
|
||||
}
|
3
src/main/resources/config.yml
Normal file
3
src/main/resources/config.yml
Normal file
@ -0,0 +1,3 @@
|
||||
Version: 1.0
|
||||
#是否只允许控制台执行插件命令
|
||||
onlyCommandConsole: false
|
Loading…
Reference in New Issue
Block a user