mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 14:28:46 +00:00
modify plugin frame...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
d1b0792fcf
commit
cc092d6e0c
@ -66,7 +66,6 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
registerCommand(new CommandUpdate(yum));
|
||||
registerCommand(new CommandDelete(yum));
|
||||
registerCommand(new CommandInfo(yum));
|
||||
registerCommand(new CommandReinstall(yum));
|
||||
|
||||
RegisterCommandList = getRegisterCommands();
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.utils.PluginsManager;
|
||||
|
||||
/**
|
||||
* 插件安装命令类
|
||||
@ -35,9 +34,7 @@ public class CommandInstall extends BaseCommand {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(yum, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (yum.download.install(sender, pluginname)) {
|
||||
PluginsManager.load(sender, pluginname);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -1,64 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.Yum.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.utils.PluginsManager;
|
||||
|
||||
/**
|
||||
* 插件安装命令类
|
||||
*
|
||||
* @author 蒋天蓓 2015年8月12日下午2:04:05
|
||||
*/
|
||||
public class CommandReinstall extends BaseCommand {
|
||||
Yum yum;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandReinstall(Yum main) {
|
||||
super("reinstall");
|
||||
this.yum = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, String label, String[] args) throws CommandException {
|
||||
final String pluginname = args[0];
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
sender.sendMessage("§a开始重装插件: " + pluginname);
|
||||
if (plugin != null) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(yum, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (yum.download.yum(sender, plugin.getName())) {
|
||||
PluginsManager.deletePlugin(sender, plugin);
|
||||
PluginsManager.installFromYum(sender, plugin.getName());
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "<插件名称>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -33,9 +33,7 @@ public class CommandUpdate extends BaseCommand {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(yum, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (yum.download.update(sender, plugin)) {
|
||||
sender.sendMessage("§6更新: §a插件 " + pluginname + " 已下载到update文件夹 重启后生效!");
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -1,69 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.Yum.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.Yum.Yum;
|
||||
import cn.citycraft.Yum.utils.PluginsManager;
|
||||
|
||||
/**
|
||||
* 插件安装命令类
|
||||
*
|
||||
* @author 蒋天蓓 2015年8月12日下午2:04:05
|
||||
*/
|
||||
public class CommandUrlInstall extends BaseCommand {
|
||||
Yum yum;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public CommandUrlInstall(Yum main) {
|
||||
super("urlinstall");
|
||||
this.yum = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, String label, final String[] args) throws CommandException {
|
||||
final String url = args[0];
|
||||
final String pluginname = args[1];
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
if (plugin == null) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(yum, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
yum.download.yumdl(sender, url);
|
||||
break;
|
||||
case 2:
|
||||
yum.download.yumdl(sender, url, pluginname);
|
||||
break;
|
||||
}
|
||||
PluginsManager.installFromYum(sender, pluginname);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sender.sendMessage("§c插件已安装在服务器 需要更新请使用yum update " + pluginname + "!");
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int getMinimumArguments() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPossibleArguments() {
|
||||
return "<插件名称>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyPlayerExecutable() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -29,8 +29,7 @@ import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
/**
|
||||
* An implementation of {@link Configuration} which saves all files in Yaml.
|
||||
* Note that this
|
||||
* An implementation of {@link Configuration} which saves all files in Yaml. Note that this
|
||||
* implementation is not synchronized.
|
||||
*/
|
||||
public class FileConfig extends YamlConfiguration {
|
||||
@ -80,14 +79,15 @@ public class FileConfig extends YamlConfiguration {
|
||||
loger.info("配置文件 " + filename + " 创建失败...");
|
||||
} else {
|
||||
plugin.saveResource(filename, true);
|
||||
loger.info("配置文件 " + filename + " 不存在 从插件释放...");
|
||||
}
|
||||
} else {
|
||||
FileConfig newcfg = new FileConfig(stream);
|
||||
FileConfig oldcfg = new FileConfig(file);
|
||||
String newver = newcfg.getString("version");
|
||||
String oldver = oldcfg.getString("version");
|
||||
if (newver != null && oldver != null && newver != oldver) {
|
||||
loger.warning("配置文件: " + filename + " 版本过低 正在升级...");
|
||||
if (newver != null && newver != oldver) {
|
||||
loger.warning("配置文件: " + filename + " 版本 " + oldver + " 过低 正在升级到 " + newver + " ...");
|
||||
try {
|
||||
oldcfg.save(new File(file.getParent(), filename + ".backup"));
|
||||
loger.warning("配置文件: " + filename + " 已备份为 " + filename + ".backup !");
|
||||
@ -105,24 +105,19 @@ public class FileConfig extends YamlConfiguration {
|
||||
|
||||
private void init(File file) {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
FileInputStream stream;
|
||||
try {
|
||||
this.load(file);
|
||||
} catch (FileNotFoundException ex) {
|
||||
stream = new FileInputStream(file);
|
||||
init(stream);
|
||||
} catch (FileNotFoundException e) {
|
||||
loger.info("配置文件 " + file.getName() + " 不存在...");
|
||||
} catch (IOException ex) {
|
||||
loger.info("配置文件 " + file.getName() + " 读取错误...");
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
loger.info("配置文件 " + file.getName() + " 格式错误...");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void init(InputStream stream) {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
Validate.notNull(stream, "Stream cannot be null");
|
||||
try {
|
||||
this.load(stream);
|
||||
} catch (FileNotFoundException ex) {
|
||||
loger.info("配置文件 " + file.getName() + " 不存在...");
|
||||
this.load(new InputStreamReader(stream, Charsets.UTF_8));
|
||||
} catch (IOException ex) {
|
||||
loger.info("配置文件 " + file.getName() + " 读取错误...");
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
@ -153,6 +148,10 @@ public class FileConfig extends YamlConfiguration {
|
||||
loadFromString(builder.toString());
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
init(file);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (file == null) {
|
||||
loger.info("未定义配置文件路径 保存失败!");
|
||||
|
@ -17,23 +17,22 @@ import org.bukkit.plugin.Plugin;
|
||||
* @author 蒋天蓓 2015年8月21日下午6:08:09 TODO
|
||||
*/
|
||||
public class DownloadManager {
|
||||
String yumurl = "http://ci.citycraft.cn:8800/jenkins/job/%1$s/lastSuccessfulBuild/artifact/target/%1$s.jar";
|
||||
Plugin plugin;
|
||||
|
||||
public DownloadManager(Plugin main) {
|
||||
this.plugin = main;
|
||||
}
|
||||
|
||||
public String getFileName(URL url) {
|
||||
int end = url.getFile().lastIndexOf('/');
|
||||
return url.getFile().substring(end + 1);
|
||||
}
|
||||
|
||||
public String getFileName(String url) {
|
||||
int end = url.lastIndexOf('/');
|
||||
return url.substring(end + 1);
|
||||
}
|
||||
|
||||
public String getFileName(URL url) {
|
||||
int end = url.getFile().lastIndexOf('/');
|
||||
return url.getFile().substring(end + 1);
|
||||
}
|
||||
|
||||
private String getPer(int per) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 11; i++) {
|
||||
@ -48,18 +47,17 @@ public class DownloadManager {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public URL getUrl(String pluginname) {
|
||||
public boolean run(CommandSender sender, String urlstring, File file) {
|
||||
URL url;
|
||||
try {
|
||||
return new URL(String.format(yumurl, pluginname));
|
||||
url = new URL(urlstring);
|
||||
return run(sender, url, file);
|
||||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
sender.sendMessage("§4错误: §c无法识别的URL地址...");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean install(CommandSender sender, String pluginname) {
|
||||
return run(sender, getUrl(pluginname), new File("plugins", pluginname + ".jar"));
|
||||
}
|
||||
|
||||
public boolean run(CommandSender sender, URL url, File file) {
|
||||
BufferedInputStream in = null;
|
||||
FileOutputStream fout = null;
|
||||
@ -110,46 +108,12 @@ public class DownloadManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean run(String urlstring, File file) {
|
||||
return run(null, urlstring, file);
|
||||
}
|
||||
|
||||
public boolean run(URL url, File file) {
|
||||
return run(null, url, file);
|
||||
}
|
||||
|
||||
public boolean update(CommandSender sender, Plugin plugin) {
|
||||
String pluginname = plugin.getName();
|
||||
String filename = PluginsManager.getPluginFile(plugin).getName();
|
||||
URL url = getUrl(pluginname);
|
||||
if (url == null) {
|
||||
sender.sendMessage("§4错误: §cURL地址解析失败!");
|
||||
return false;
|
||||
}
|
||||
return run(sender, url, new File("plugins/update", filename));
|
||||
}
|
||||
|
||||
public boolean yumdl(CommandSender sender, String address, String pluginname) {
|
||||
try {
|
||||
URL url = new URL(address);
|
||||
File yumplugin = new File("plugins/YumCenter", pluginname + ".jar");
|
||||
if (yumplugin.exists()) {
|
||||
sender.sendMessage("§6更新: §e仓库已存在插件 " + pluginname + " 开始更新...");
|
||||
yumplugin.delete();
|
||||
}
|
||||
return run(sender, url, yumplugin);
|
||||
} catch (MalformedURLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean yumdl(CommandSender sender, String address) {
|
||||
String pluginname = getFileName(address);
|
||||
return yumdl(sender, pluginname, address);
|
||||
}
|
||||
|
||||
public boolean yum(CommandSender sender, String pluginname) {
|
||||
File yumplugin = new File("plugins/YumCenter", pluginname + ".jar");
|
||||
if (yumplugin.exists()) {
|
||||
sender.sendMessage("§6更新: §e仓库已存在插件 " + pluginname + " 开始更新...");
|
||||
yumplugin.delete();
|
||||
}
|
||||
return run(sender, getUrl(pluginname), yumplugin);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user