精简大量代码 服务器启动后自动检查可更新插件 优化检测流程...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2016-02-23 20:52:45 +08:00
parent b8d7bfc25e
commit 6999117880
27 changed files with 548 additions and 1030 deletions

View File

@ -21,5 +21,11 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cn.citycraft</groupId>
<artifactId>Yum</artifactId>
<version>1.9.7</version>
<version>2.0</version>
<name>Yum</name>
<description>Minecraft 服务器插件管理系统</description>
<build>
@ -54,8 +54,9 @@
</plugins>
</build>
<properties>
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
<update.description>&amp;c去除离线缓存 修复版本更新模块...</update.description>
<jenkins.url>http://hs.yumc.pw:8080</jenkins.url>
<update.description>&amp;a全新 2.0 版本 震撼发布...</update.description>
<update.changes>&amp;a精简大量代码...;&amp;a服务器启动后自动检查可更新插件...;&amp;a优化检测流程...</update.changes>
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

View File

@ -3,13 +3,14 @@
*/
package cn.citycraft.Yum;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.utils.VersionChecker;
import cn.citycraft.Yum.api.YumAPI;
import cn.citycraft.Yum.commands.FileCommand;
import cn.citycraft.Yum.commands.YumCommand;
import cn.citycraft.Yum.file.commands.FileCommand;
/**
* MC插件仓库
@ -26,12 +27,12 @@ public class Yum extends JavaPlugin {
new YumCommand(this);
new FileCommand(this);
new VersionChecker(this);
YumAPI.updaterepo();
YumAPI.updaterepo(Bukkit.getConsoleSender());
YumAPI.updatecheck(Bukkit.getConsoleSender());
}
@Override
public void onLoad() {
config = new FileConfig(this);
}
}

View File

@ -25,11 +25,8 @@ import cn.citycraft.Yum.manager.RepositoryManager;
*/
public class YumAPI {
private static DownloadManager download;
private static Plugin main;
private static PluginsManager plugman;
private static RepositoryManager repo;
/**
@ -82,6 +79,26 @@ public class YumAPI {
return repo;
}
public static List<Plugin> getUpdateList(final CommandSender sender) {
final List<Plugin> ulist = new ArrayList<>();
try {
for (final Entry<String, Plugin> updateplugin : UpdatePlugin.getUpdateList().entrySet()) {
ulist.add(updateplugin.getValue());
}
UpdatePlugin.clearList();
} catch (final Exception | Error e) {
try {
final Map<Plugin, String> updatelist = UpdatePlugin.getList();
ulist.addAll(updatelist.keySet());
UpdatePlugin.getList().clear();
} catch (final Exception | Error e2) {
sender.sendMessage("§4错误: §c无法检索全体更新列表!");
sender.sendMessage("§4异常: §c" + e2.getMessage());
}
}
return ulist;
}
/**
* 安装新插件
*
@ -226,32 +243,40 @@ public class YumAPI {
* 命令发送者
*/
public static void updateall(final CommandSender sender) {
final List<Plugin> ulist = new ArrayList<>();
try {
for (final Entry<String, Plugin> updateplugin : UpdatePlugin.getUpdateList().entrySet()) {
ulist.add(updateplugin.getValue());
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
final List<Plugin> ulist = getUpdateList(sender);
if (ulist.size() > 0) {
for (final Plugin updateplugin : ulist) {
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getName() + "!");
updatefromyum(sender, updateplugin, null, true);
}
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
sender.sendMessage("§d一键更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
} else {
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
}
}
UpdatePlugin.clearList();
} catch (final Exception | Error e) {
try {
final Map<Plugin, String> updatelist = UpdatePlugin.getList();
ulist.addAll(updatelist.keySet());
UpdatePlugin.getList().clear();
} catch (final Exception | Error e2) {
sender.sendMessage("§4错误: §c无法检索全体更新列表!");
sender.sendMessage("§4异常: §c" + e2.getMessage());
});
}
/**
* 检查是否有可更新插件
*
* @param sender
* 命令发送者
*/
public static void updatecheck(final CommandSender sender) {
main.getServer().getScheduler().runTaskLaterAsynchronously(main, new Runnable() {
@Override
public void run() {
final List<Plugin> ulist = getUpdateList(sender);
if (ulist.size() > 0) {
sender.sendMessage("§6[§bYum§6]§e自动更新: §a发现" + ulist.size() + " 个可更新插件 请使用 §b/yum ua §a更新所有插件!");
}
}
}
if (ulist.size() > 0) {
for (final Plugin updateplugin : ulist) {
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getName() + "!");
updatefromyum(sender, updateplugin, null, true);
}
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
sender.sendMessage("§d一键更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
} else {
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
}
}, 100);
}
/**
@ -300,7 +325,6 @@ public class YumAPI {
if (pi != null) {
final File pFile = new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName());
if (download.run(sender, pi.getUrl(sender, version), pFile)) {
if (!oneKeyUpdate) {
sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹");
sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
@ -316,11 +340,11 @@ public class YumAPI {
/**
* 更新Yum源数据
*/
public static void updaterepo() {
public static void updaterepo(final CommandSender sender) {
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
repo.updateRepositories(Bukkit.getConsoleSender());
repo.updateRepositories(sender);
}
});
}

View File

@ -1,49 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandDelete extends BaseCommand {
Yum main;
public CommandDelete(final Yum main) {
super("del");
this.main = main;
setMinimumArguments(1);
setDescription("删除插件");
setPossibleArguments("<插件名称>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
final String version = StringUtils.substring(plugin.getDescription().getVersion(), 0, 15);
if (YumAPI.getPlugman().deletePlugin(sender, plugin)) {
sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!");
} else {
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
}
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
}
}

View File

@ -1,49 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandFullDelete extends BaseCommand {
Yum main;
public CommandFullDelete(final Yum main) {
super("fdel");
this.main = main;
setMinimumArguments(1);
setDescription("删除插件以及数据文件夹");
setPossibleArguments("<插件名称>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
final String version = StringUtils.substring(plugin.getDescription().getVersion(), 0, 15);
if (YumAPI.getPlugman().fullDeletePlugin(sender, plugin)) {
sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!");
} else {
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
}
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
}
}

View File

@ -1,82 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.PluginHelper.utils.StringUtil;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandInfo extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandInfo(final Yum main) {
super();
this.main = main;
setMinimumArguments(1);
setDescription("查看插件详情");
setPossibleArguments("<插件名称>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0];
final Plugin plugin = main.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
final PluginDescriptionFile desc = plugin.getDescription();
sender.sendMessage("§6插件名称: §3" + plugin.getName());
sender.sendMessage("§6插件版本: §3" + StringUtils.substring(plugin.getDescription().getVersion(), 0, 15));
sender.sendMessage("§6插件作者: §3" + StringUtils.join(desc.getAuthors(), " "));
sender.sendMessage("§6插件描述: §3" + (desc.getDescription() == null ? "" : desc.getDescription()));
sender.sendMessage("§6插件依赖: §3" + (desc.getDepend().isEmpty() ? "" : ""));
StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a");
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().isEmpty() ? "" : ""));
StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a");
final Map<String, Map<String, Object>> clist = desc.getCommands();
if (clist != null) {
sender.sendMessage("§6插件注册命令: §3" + (clist.isEmpty() ? "" : ""));
StringUtil.sendStringArray(sender, clist.keySet(), "§6 - §a");
}
final List<Permission> plist = desc.getPermissions();
if (plist != null) {
sender.sendMessage("§6插件注册权限: " + (plist.isEmpty() ? "" : ""));
for (final Permission perm : plist) {
sender.sendMessage("§6 - §a" + perm.getName() + "§6 - §e" + (perm.getDescription().isEmpty() ? "无描述" : perm.getDescription()));
}
}
sender.sendMessage("§6插件物理路径: §3" + YumAPI.getPlugman().getPluginFile(plugin).getAbsolutePath());
} else {
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
}
}
@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.getPlugman().getPluginNames(false), new ArrayList<String>());
}
return null;
}
}

View File

@ -1,67 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.PluginHelper.utils.StringUtil;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* 插件安装命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandInstall extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandInstall(final Yum main) {
super("i");
this.main = main;
setMinimumArguments(1);
setDescription("安装插件");
setPossibleArguments("<插件名称>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin == null) {
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
if (args.length < 2) {
YumAPI.installfromyum(sender, pluginname);
} else {
YumAPI.installfromyum(sender, pluginname, args[1]);
}
}
});
} else {
sender.sendMessage("§c插件" + pluginname + "已安装在服务器 需要更新请使用yum update " + pluginname + "!");
}
}
@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.getRepo().getAllPluginName(), new ArrayList<String>());
}
return null;
}
}

View File

@ -1,41 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* 插件查看命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandList extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandList(final Yum main) {
super("l");
this.main = main;
setDescription("列出已安装插件列表");
}
@Override
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.getPlugman().getFormattedName(plugin, true));
}
};
}

View File

@ -1,46 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandLoad extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandLoad(final Yum main) {
super();
this.main = main;
setMinimumArguments(1);
setDescription("载入插件");
setPossibleArguments("<插件名称>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin == null) {
YumAPI.getPlugman().load(sender, pluginname);
} else {
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
}
};
}

View File

@ -1,50 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandReload extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandReload(final Yum main) {
super();
this.main = main;
setMinimumArguments(1);
setDescription("重载插件");
setPossibleArguments("<插件名称|all|*>");
}
@Override
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.getPlugman().reloadAll(sender);
return;
}
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
YumAPI.getPlugman().reload(sender, plugin);
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
};
}

View File

@ -1,109 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.PluginHelper.utils.StringUtil;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
import cn.citycraft.Yum.manager.RepoSerialization.Repositories;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandRepo extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandRepo(final Yum main) {
super("r");
this.main = main;
setMinimumArguments(1);
setDescription("插件源命令");
setPossibleArguments("<add|del|all|clean|list> <仓库名称>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
final String cmd = args[0];
switch (cmd) {
case "add":
if (args.length == 2) {
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源地址未找到仓库信息或当前地址已缓存!");
}
} else {
sender.sendMessage("§6仓库: §c请输入需要添加的源地址!");
}
break;
case "del":
if (args.length == 2) {
final Repositories delrepo = YumAPI.getRepo().getRepoCache(args[1]);
if (delrepo != null) {
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源地址未找到!");
}
} else {
sender.sendMessage("§6仓库: §c请输入需要删除的源地址!");
}
break;
case "delall":
YumAPI.getRepo().getRepoCache().getRepos().clear();
sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!");
break;
case "list":
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
StringUtil.sendStringArray(sender, YumAPI.getRepo().getAllPluginsInfo());
break;
case "all":
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
StringUtil.sendStringArray(sender, YumAPI.getRepo().getRepoCache().getAllRepoInfo());
break;
case "clean":
YumAPI.getRepo().clean();
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
break;
case "update":
YumAPI.getRepo().updateRepositories(sender);
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
break;
}
}
});
}
@Override
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
if (args[0].equalsIgnoreCase("repo")) {
if (args.length == 2) {
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.getRepo().getRepos().keySet(), new ArrayList<String>());
}
}
return null;
}
}

View File

@ -1,46 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandUnload extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandUnload(final Yum main) {
super();
this.main = main;
setMinimumArguments(1);
setDescription("卸载插件");
setPossibleArguments("<插件名称>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
YumAPI.getPlugman().unload(sender, plugin);
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
};
}

View File

@ -1,62 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandUpdate extends BaseCommand {
Yum main;
public CommandUpdate(final Yum main) {
super("u");
this.main = main;
setMinimumArguments(0);
setDescription("更新插件或缓存");
setPossibleArguments("[插件名称] [插件版本]");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
switch (args.length) {
case 0:
YumAPI.getRepo().updateRepositories(sender);
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
break;
case 1:
case 2:
final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
sender.sendMessage("§a开始更新插件: " + pluginname);
if (plugin != null) {
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
if (args.length < 2) {
YumAPI.updatefromyum(sender, plugin);
} else {
YumAPI.updatefromyum(sender, plugin, args[1]);
}
}
});
} else {
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用/yum install " + pluginname + "!");
}
break;
default:
sendHelp(sender, label);
}
}
}

View File

@ -1,38 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandUpdateAll extends BaseCommand {
Yum main;
public CommandUpdateAll(final Yum main) {
super("ua");
this.main = main;
setDescription("更新所有可更新插件");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
sender.sendMessage("§d开始更新服务器可更新插件");
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
YumAPI.updateall(sender);
}
});
};
}

View File

@ -1,53 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
/**
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandUpgrade extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandUpgrade(final Yum main) {
super("ug");
this.main = main;
setDescription("升级插件");
setPossibleArguments("[插件名称]");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
if (args.length == 0) {
YumAPI.getPlugman().upgrade(sender);
} else {
final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
sender.sendMessage("§a开始升级插件: " + pluginname);
if (plugin != null) {
YumAPI.upgrade(sender, plugin);
} else {
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
}
}
}
});
};
}

View File

@ -0,0 +1,149 @@
package cn.citycraft.Yum.commands;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import cn.citycraft.PluginHelper.commands.HandlerCommand;
import cn.citycraft.PluginHelper.commands.HandlerCommands;
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
import cn.citycraft.PluginHelper.utils.FileUtil;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
import cn.citycraft.Yum.manager.DownloadManager;
/**
* File命令基类
*
* @since 2016年1月9日 上午10:02:39
* @author
*/
public class FileCommand implements HandlerCommands {
Yum plugin;
DownloadManager dl;
public FileCommand(final Yum yum) {
plugin = yum;
dl = YumAPI.getDownload();
final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "file");
cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyFileCommandConsole", true));
cmdhandler.registerCommands(this);
}
@HandlerCommand(name = "delete", aliases = { "del" }, minimumArguments = 1, description = "删除文件(服务器JAR为根目录)", possibleArguments = "<文件相对目录>")
public void delete(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
final String fpath = args[0];
final File file = new File(fpath);
final CommandSender sender = e.getSender();
if (!file.exists()) {
sender.sendMessage("§c文件 " + file.getAbsolutePath() + " 不存在!");
} else {
if (file.isDirectory()) {
sender.sendMessage("§e" + file.getAbsolutePath() + " §c是一个目录 请使用file rm!");
return;
}
try {
sender.sendMessage("§d文件 §e" + file.getAbsolutePath() + " " + (file.delete() ? "§a删除成功!" : "§c删除失败!"));
} catch (final Exception ex) {
sender.sendMessage("§d文件 §e" + file.getAbsolutePath() + " 删除失败: " + ex.getMessage());
}
}
}
@HandlerCommand(name = "download", aliases = { "d" }, minimumArguments = 1, description = "下载文件(默认保存到服务器更新文件夹)", possibleArguments = "<下载地址> [保存文件路径]")
public void download(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
String urlstr = args[0];
if (!urlstr.startsWith("http")) {
urlstr = "http://" + urlstr;
}
File file = null;
if (args.length == 2) {
file = new File(args[1]);
} else {
file = new File(Bukkit.getUpdateFolderFile(), dl.getFileName(urlstr));
}
dl.run(e.getSender(), urlstr, file);
}
@HandlerCommand(name = "ls", aliases = { "l" }, minimumArguments = 1, description = "列出当前目录(服务器JAR为根目录)", possibleArguments = "<相对目录>")
public void ls(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
final CommandSender sender = e.getSender();
File dir = new File(".");
if (args.length == 1) {
dir = new File(args[0]);
}
if (!dir.isDirectory()) {
sender.sendMessage("§6路径: §e " + dir.getAbsolutePath() + " §c不是一个目录!");
return;
}
final StringBuffer sb = new StringBuffer();
for (final File file : dir.listFiles()) {
if (file.isDirectory()) {
sb.append("§b");
} else {
sb.append("§a");
}
sb.append(file.getName() + " ");
}
final String filelist = sb.toString();
if (filelist.isEmpty()) {
sender.sendMessage("§6目录: §e" + dir.getAbsolutePath() + " §c下没有文件或文件夹!");
} else {
sender.sendMessage("§6目录: §e" + dir.getAbsolutePath() + " §a存在如下文件!");
sender.sendMessage(sb.toString());
}
}
@HandlerCommand(name = "rename", aliases = { "rn" }, minimumArguments = 2, description = "重命名文件(服务器JAR为根目录)", possibleArguments = "<文件相对路径> <文件名称>")
public void rename(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
final CommandSender sender = e.getSender();
final String fpath = args[0];
final File file = new File(fpath);
if (!file.exists()) {
sender.sendMessage("§c文件 " + file.getAbsolutePath() + " 不存在!");
} else {
try {
final File newFile = new File(file.getParentFile(), args[1]);
file.renameTo(newFile);
sender.sendMessage("§a文件 §e" + file.getAbsolutePath() + " §a重命名为 §d" + newFile.getAbsolutePath());
} catch (final Exception ex) {
sender.sendMessage("§c文件 §e" + file.getAbsolutePath() + " §c重命名失败: " + ex.getMessage());
}
}
}
@HandlerCommand(name = "rm", minimumArguments = 1, description = "删除文件夹(服务器JAR为根目录)", possibleArguments = "<相对目录>")
public void rm(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
final CommandSender sender = e.getSender();
final String fpath = args[0];
final File file = new File(fpath);
if (!file.exists()) {
sender.sendMessage("§c目录 " + file.getAbsolutePath() + " 不存在!");
} else {
if (!file.isDirectory()) {
sender.sendMessage("§d路径 §e" + file.getAbsolutePath() + " §c是一个文件 请使用file delete!");
return;
}
for (final String name : plugin.config.getStringList("blacklist")) {
if (file.getAbsolutePath().toLowerCase().endsWith(name)) {
sender.sendMessage("§d路径 §e" + file.getAbsolutePath() + " §c不允许被删除!");
return;
}
}
if (file.listFiles().length != 0 && !(args.length > 1 && args[1].equalsIgnoreCase("-rf"))) {
sender.sendMessage("§d目录 §e" + file.getAbsolutePath() + " §c不为空!");
sender.sendMessage("§c请使用 §a/file rm " + fpath + " -rf §c强行删除!");
return;
}
sender.sendMessage("§d目录 §e" + file.getAbsolutePath() + " " + (FileUtil.deleteDir(sender, file) ? "§a删除成功!" : "§c删除失败!"));
}
}
}

View File

@ -1,29 +1,333 @@
package cn.citycraft.Yum.commands;
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import cn.citycraft.PluginHelper.commands.HandlerCommand;
import cn.citycraft.PluginHelper.commands.HandlerCommands;
import cn.citycraft.PluginHelper.commands.HandlerTabComplete;
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
import cn.citycraft.PluginHelper.utils.StringUtil;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
import cn.citycraft.Yum.manager.PluginsManager;
import cn.citycraft.Yum.manager.RepoSerialization.Repositories;
import cn.citycraft.Yum.manager.RepositoryManager;
/**
* Yum命令基类
*
*
* @since 2016年1月9日 上午10:02:24
* @author
*/
public class YumCommand {
public class YumCommand implements HandlerCommands {
Yum main;
RepositoryManager repo;
PluginsManager plugman;
public YumCommand(final Yum yum) {
final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "yum");
main = yum;
repo = YumAPI.getRepo();
plugman = YumAPI.getPlugman();
final InvokeSubCommand cmdhandler = new InvokeSubCommand(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 CommandFullDelete(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));
cmdhandler.registerCommands(this);
}
@HandlerCommand(name = "delete", aliases = { "del" }, minimumArguments = 1, description = "删除插件", possibleArguments = "<插件名称>")
public void delete(final InvokeCommandEvent e) {
final String pluginname = e.getArgs()[0];
final CommandSender sender = e.getSender();
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
final String version = StringUtils.substring(plugin.getDescription().getVersion(), 0, 15);
if (plugman.deletePlugin(sender, plugin)) {
sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!");
} else {
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
}
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
}
@HandlerCommand(name = "fulldelete", aliases = { "fdel" }, minimumArguments = 1, description = "删除插件以及数据文件夹", possibleArguments = "<插件名称>")
public void fulldelete(final InvokeCommandEvent e) {
final String pluginname = e.getArgs()[0];
final CommandSender sender = e.getSender();
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
final String version = StringUtils.substring(plugin.getDescription().getVersion(), 0, 15);
if (plugman.fullDeletePlugin(sender, plugin)) {
sender.sendMessage("§c删除: §a插件 §6" + pluginname + " §a版本 §d" + version + " §a已从服务器卸载并删除!");
} else {
sender.sendMessage("§c删除: §c插件 " + pluginname + " 卸载或删除时发生错误 删除失败!");
}
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
}
@HandlerCommand(name = "info", minimumArguments = 1, description = "查看插件详情", possibleArguments = "<插件名称>")
public void info(final InvokeCommandEvent e) {
final String pluginname = e.getArgs()[0];
final CommandSender sender = e.getSender();
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
final PluginDescriptionFile desc = plugin.getDescription();
sender.sendMessage("§6插件名称: §3" + plugin.getName());
sender.sendMessage("§6插件版本: §3" + StringUtils.substring(plugin.getDescription().getVersion(), 0, 15));
sender.sendMessage("§6插件作者: §3" + StringUtils.join(desc.getAuthors(), " "));
sender.sendMessage("§6插件描述: §3" + (desc.getDescription() == null ? "" : desc.getDescription()));
sender.sendMessage("§6插件依赖: §3" + (desc.getDepend().isEmpty() ? "" : ""));
StringUtil.sendStringArray(sender, desc.getDepend(), "§6 - §a");
sender.sendMessage("§6插件软依赖: §3" + (desc.getSoftDepend().isEmpty() ? "" : ""));
StringUtil.sendStringArray(sender, desc.getSoftDepend(), "§6 - §a");
final Map<String, Map<String, Object>> clist = desc.getCommands();
if (clist != null) {
sender.sendMessage("§6插件注册命令: §3" + (clist.isEmpty() ? "" : ""));
StringUtil.sendStringArray(sender, clist.keySet(), "§6 - §a");
}
final List<Permission> plist = desc.getPermissions();
if (plist != null) {
sender.sendMessage("§6插件注册权限: " + (plist.isEmpty() ? "" : ""));
for (final Permission perm : plist) {
sender.sendMessage("§6 - §a" + perm.getName() + "§6 - §e" + (perm.getDescription().isEmpty() ? "无描述" : perm.getDescription()));
}
}
sender.sendMessage("§6插件物理路径: §3" + plugman.getPluginFile(plugin).getAbsolutePath());
} else {
sender.sendMessage("§4错误: §c插件 " + pluginname + " 不存在或已卸载!");
}
}
@HandlerCommand(name = "install", aliases = { "i" }, minimumArguments = 1, description = "安装插件", possibleArguments = "<插件名称>")
public void install(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
final CommandSender sender = e.getSender();
final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin == null) {
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
if (args.length < 2) {
YumAPI.installfromyum(sender, pluginname);
} else {
YumAPI.installfromyum(sender, pluginname, args[1]);
}
}
});
} else {
sender.sendMessage("§c插件" + pluginname + "已安装在服务器 需要更新请使用yum update " + pluginname + "!");
}
}
@HandlerCommand(name = "list", aliases = { "l" }, description = "列出已安装插件列表")
public void list(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
sender.sendMessage("§6[Yum仓库]§3服务器已安装插件: ");
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
sender.sendMessage("§6- " + plugman.getFormattedName(plugin, true));
}
}
@HandlerTabComplete()
public List<String> listtab(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
if (!args[0].equalsIgnoreCase("install") && !args[0].equalsIgnoreCase("repo")) {
return StringUtil.copyPartialMatches(args[1], plugman.getPluginNames(false), new ArrayList<String>());
}
if (args[0].equalsIgnoreCase("install")) {
return StringUtil.copyPartialMatches(args[1], repo.getAllPluginName(), new ArrayList<String>());
}
if (args[0].equalsIgnoreCase("repo")) {
if (args.length == 2) {
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], repo.getRepos().keySet(), new ArrayList<String>());
}
}
return null;
}
@HandlerCommand(name = "load", minimumArguments = 1, description = "载入插件", possibleArguments = "<插件名称>")
public void load(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
final String pluginname = e.getArgs()[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin == null) {
plugman.load(sender, pluginname);
} else {
sender.sendMessage("§c错误: 插件 " + pluginname + " 已加载到服务器!");
}
}
@HandlerCommand(name = "reload", aliases = { "re" }, minimumArguments = 1, description = "重载插件", possibleArguments = "<插件名称|all|*>")
public void reload(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
final String pluginname = e.getArgs()[0];
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
plugman.reloadAll(sender);
return;
}
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
plugman.reload(sender, plugin);
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
}
@HandlerCommand(name = "repo", aliases = { "r" }, minimumArguments = 1, description = "插件源命令", possibleArguments = "<add|del|all|clean|list> <仓库名称>")
public void repo(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
final CommandSender sender = e.getSender();
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
final String cmd = args[0];
switch (cmd) {
case "add":
if (args.length == 2) {
if (repo.addRepositories(sender, args[1])) {
final String reponame = repo.getRepoCache(args[1]).name;
sender.sendMessage("§6仓库: §a源仓库 §e" + reponame + " §a的插件信息已缓存!");
} else {
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或当前地址已缓存!");
}
} else {
sender.sendMessage("§6仓库: §c请输入需要添加的源地址!");
}
break;
case "del":
if (args.length == 2) {
final Repositories delrepo = repo.getRepoCache(args[1]);
if (delrepo != null) {
repo.delRepositories(sender, args[1]);
sender.sendMessage("§6仓库: §a源仓库 §e" + delrepo.name + " §c已删除 §a请使用 §b/yum repo update §a更新缓存!");
} else {
sender.sendMessage("§6仓库: §c源地址未找到!");
}
} else {
sender.sendMessage("§6仓库: §c请输入需要删除的源地址!");
}
break;
case "delall":
repo.getRepoCache().getRepos().clear();
sender.sendMessage("§6仓库: §a缓存的仓库信息已清理!");
break;
case "list":
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
StringUtil.sendStringArray(sender, repo.getAllPluginsInfo());
break;
case "all":
sender.sendMessage("§6仓库: §b缓存的仓库信息如下 ");
StringUtil.sendStringArray(sender, repo.getRepoCache().getAllRepoInfo());
break;
case "clean":
repo.clean();
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
break;
case "update":
repo.updateRepositories(sender);
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
break;
}
}
});
}
@HandlerCommand(name = "unload", minimumArguments = 1, description = "卸载插件", possibleArguments = "<插件名称>")
public void unload(final InvokeCommandEvent e) {
final String pluginname = e.getArgs()[0];
final CommandSender sender = e.getSender();
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
plugman.unload(sender, plugin);
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
}
@HandlerCommand(name = "update", aliases = { "u" }, description = "更新插件或缓存", possibleArguments = "[插件名称] [插件版本]")
public void update(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
final CommandSender sender = e.getSender();
final String pluginname = args[0];
switch (args.length) {
case 0:
repo.updateRepositories(sender);
sender.sendMessage("§6仓库: §a仓库缓存数据已更新!");
break;
case 1:
case 2:
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
sender.sendMessage("§a开始更新插件: " + pluginname);
if (plugin != null) {
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
if (args.length < 2) {
YumAPI.updatefromyum(sender, plugin);
} else {
YumAPI.updatefromyum(sender, plugin, args[1]);
}
}
});
} else {
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用/yum install " + pluginname + "!");
}
break;
default:
sender.sendMessage("§c命令参数错误!");
}
}
@HandlerCommand(name = "updateall", aliases = { "ua" }, description = "更新所有可更新插件")
public void updateall(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
sender.sendMessage("§d开始更新服务器可更新插件");
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
YumAPI.updateall(sender);
}
});
}
@HandlerCommand(name = "upgrade", aliases = { "ug" }, description = "升级或载入插件", possibleArguments = "[插件名称]")
public void upgrade(final InvokeCommandEvent e) {
final String[] args = e.getArgs();
final CommandSender sender = e.getSender();
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
if (args.length == 0) {
plugman.upgrade(sender);
} else {
final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
sender.sendMessage("§a开始升级插件: " + pluginname);
if (plugin != null) {
YumAPI.upgrade(sender, plugin);
} else {
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
}
}
}
});
}
}

View File

@ -1,47 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.file.commands;
import java.io.File;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandDelete extends BaseCommand {
public CommandDelete(final Yum main) {
super("del");
setMinimumArguments(1);
setDescription("删除文件(服务器JAR为根目录)");
setPossibleArguments("<文件相对目录>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String fpath = args[0];
final File file = new File(fpath);
if (!file.exists()) {
sendMessage(sender, "§c文件 " + file.getAbsolutePath() + " 不存在!");
} else {
if (file.isDirectory()) {
sendMessage(sender, "§e" + file.getAbsolutePath() + " §c是一个目录 请使用file rm!");
return;
}
try {
sendMessage(sender, "§d文件 §e" + file.getAbsolutePath() + " " + (file.delete() ? "§a删除成功!" : "§c删除失败!"));
} catch (final Exception e) {
sendMessage(sender, "§d文件 §e" + file.getAbsolutePath() + " 删除失败: " + e.getMessage());
}
}
}
}

View File

@ -1,51 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.file.commands;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.api.YumAPI;
import cn.citycraft.Yum.manager.DownloadManager;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandDownLoad extends BaseCommand {
Yum main;
DownloadManager dl;
public CommandDownLoad(final Yum main) {
super("d");
this.main = main;
dl = YumAPI.getDownload();
setMinimumArguments(1);
setDescription("下载文件(默认保存到服务器更新文件夹)");
setPossibleArguments("<下载地址> [保存文件路径]");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
String urlstr = args[0];
if (!urlstr.startsWith("http")) {
urlstr = "http://" + urlstr;
}
File file = null;
if (args.length == 2) {
file = new File(args[1]);
} else {
file = new File(Bukkit.getUpdateFolderFile(), dl.getFileName(urlstr));
}
dl.run(sender, urlstr, file);
}
}

View File

@ -1,56 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.file.commands;
import java.io.File;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandLs extends BaseCommand {
public CommandLs(final Yum main) {
super("l");
setDescription("列出当前目录(服务器JAR为根目录)");
setPossibleArguments("<相对目录>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
File dir = new File(".");
if (args.length == 1) {
dir = new File(args[0]);
}
if (!dir.isDirectory()) {
sendMessage(sender, "§6路径: §e " + dir.getAbsolutePath() + " §c不是一个目录!");
return;
}
final StringBuffer sb = new StringBuffer();
for (final File file : dir.listFiles()) {
if (file.isDirectory()) {
sb.append("§b");
} else {
sb.append("§a");
}
sb.append(file.getName() + " ");
}
final String filelist = sb.toString();
if (filelist.isEmpty()) {
sendMessage(sender, "§6目录: §e" + dir.getAbsolutePath() + " §c下没有文件或文件夹!");
} else {
sendMessage(sender, "§6目录: §e" + dir.getAbsolutePath() + " §a存在如下文件!");
sendMessage(sender, sb.toString());
}
}
}

View File

@ -1,45 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.file.commands;
import java.io.File;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandRename extends BaseCommand {
public CommandRename(final Yum main) {
super("rn");
setMinimumArguments(2);
setDescription("重命名文件(服务器JAR为根目录)");
setPossibleArguments("<文件相对目录> <文件名称>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String fpath = args[0];
final File file = new File(fpath);
if (!file.exists()) {
sendMessage(sender, "§c文件 " + file.getAbsolutePath() + " 不存在!");
} else {
try {
final File newFile = new File(file.getParentFile(), args[1]);
file.renameTo(newFile);
sendMessage(sender, "§a文件 §e" + file.getAbsolutePath() + " §a重命名为 §d" + newFile.getAbsolutePath());
} catch (final Exception e) {
sendMessage(sender, "§c文件 §e" + file.getAbsolutePath() + " §c重命名失败: " + e.getMessage());
}
}
}
}

View File

@ -1,58 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.file.commands;
import java.io.File;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.PluginHelper.utils.FileUtil;
import cn.citycraft.Yum.Yum;
/**
* 插件删除命令类
*
* @author
* @since 2015年8月12日下午2:04:05
*/
public class CommandRm extends BaseCommand {
Yum plugin;
public CommandRm(final Yum main) {
super();
plugin = main;
setMinimumArguments(1);
setDescription("删除文件夹(服务器JAR为根目录)");
setPossibleArguments("<文件相对目录>");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String fpath = args[0];
final File file = new File(fpath);
if (!file.exists()) {
sendMessage(sender, "§c目录 " + file.getAbsolutePath() + " 不存在!");
} else {
if (!file.isDirectory()) {
sendMessage(sender, "§d路径 §e" + file.getAbsolutePath() + " §c是一个文件 请使用file delete!");
return;
}
for (final String name : plugin.config.getStringList("blacklist")) {
if (file.getAbsolutePath().toLowerCase().endsWith(name)) {
sendMessage(sender, "§d路径 §e" + file.getAbsolutePath() + " §c不允许被删除!");
return;
}
}
if (file.listFiles().length != 0 && !(args.length > 1 && args[1].equalsIgnoreCase("-rf"))) {
sendMessage(sender, "§d目录 §e" + file.getAbsolutePath() + " §c不为空!");
sendMessage(sender, "§c请使用 §a/file rm " + fpath + " -rf §c强行删除!");
return;
}
sendMessage(sender, "§d目录 §e" + file.getAbsolutePath() + " " + (FileUtil.deleteDir(sender, file) ? "§a删除成功!" : "§c删除失败!"));
}
}
}

View File

@ -1,22 +0,0 @@
package cn.citycraft.Yum.file.commands;
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
import cn.citycraft.Yum.Yum;
/**
* File命令基类
*
* @since 2016年1月9日 上午10:02:39
* @author
*/
public class FileCommand {
public FileCommand(final Yum yum) {
final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "file");
cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyFileCommandConsole", true));
cmdhandler.registerCommand(new CommandDownLoad(yum));
cmdhandler.registerCommand(new CommandDelete(yum));
cmdhandler.registerCommand(new CommandRename(yum));
cmdhandler.registerCommand(new CommandRm(yum));
cmdhandler.registerCommand(new CommandLs(yum));
}
}

View File

@ -1,5 +1,7 @@
package cn.citycraft.Yum.manager;
import java.io.Serializable;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -9,7 +11,7 @@ import cn.citycraft.Yum.manager.RepoSerialization.Plugin;
import cn.citycraft.Yum.manager.RepoSerialization.TagInfo;
import cn.citycraft.Yum.manager.RepoSerialization.URLType;
public class PluginInfo {
public class PluginInfo implements Serializable {
public static final String NMSVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
public String branch;

View File

@ -1,5 +1,6 @@
package cn.citycraft.Yum.manager;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -11,7 +12,7 @@ import cn.citycraft.PluginHelper.jsonresult.JsonHandle;
import cn.citycraft.PluginHelper.utils.IOUtil;
import cn.citycraft.Yum.manager.RepoSerialization.Repositories;
public class RepoCache {
public class RepoCache implements Serializable {
PluginHelperLogger logger = PluginHelperLogger.getLogger();
Map<String, PluginInfo> plugins = new HashMap<String, PluginInfo>();
Map<String, Repositories> repos = new HashMap<String, Repositories>();

View File

@ -3,6 +3,7 @@
*/
package cn.citycraft.Yum.manager;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@ -13,7 +14,7 @@ import java.util.List;
* @since 2015年8月31日下午7:41:53
*/
public class RepoSerialization {
public class PackageInfo {
public class PackageInfo implements Serializable {
public String name;
public List<Plugin> plugins = new ArrayList<>();
public String pom;
@ -21,7 +22,7 @@ public class RepoSerialization {
public URLType type;
}
public class Plugin {
public class Plugin implements Serializable {
public String artifactId;
public String branch;
public String description;
@ -34,18 +35,18 @@ public class RepoSerialization {
public URLType type;
}
public class Repositories {
public class Repositories implements Serializable {
public String name;
public List<Repository> repos;
}
public class Repository {
public class Repository implements Serializable {
public String id;
public URLType type;
public String url;
}
public class TagInfo {
public class TagInfo implements Serializable {
public String tag;
public String version;
public URLType type;