add load unload and reload command...

This commit is contained in:
502647092 2015-09-01 08:37:18 +08:00
parent 8f0ce09497
commit abfdd97a28
8 changed files with 206 additions and 4 deletions

View File

@ -66,6 +66,9 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
registerCommand(new CommandDelete(yum)); registerCommand(new CommandDelete(yum));
registerCommand(new CommandInfo(yum)); registerCommand(new CommandInfo(yum));
registerCommand(new CommandRepo(yum)); registerCommand(new CommandRepo(yum));
registerCommand(new CommandReload(yum));
registerCommand(new CommandLoad(yum));
registerCommand(new CommandUnload(yum));
RegisterCommandList = getRegisterCommands(); RegisterCommandList = getRegisterCommands();
} }

View File

@ -0,0 +1,54 @@
/**
*
*/
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;
/**
* 插件删除命令类
*
* @author 蒋天蓓 2015年8月12日下午2:04:05
*/
public class CommandLoad extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandLoad(Yum main) {
super("load");
this.main = main;
}
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
String pluginname = args[0];
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
main.plugman.load(sender, pluginname);
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
};
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public String getPossibleArguments() {
return "<插件名称>";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
}

View File

@ -0,0 +1,58 @@
/**
*
*/
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;
/**
* 插件删除命令类
*
* @author 蒋天蓓 2015年8月12日下午2:04:05
*/
public class CommandReload extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandReload(Yum main) {
super("reload");
this.main = main;
}
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
String pluginname = args[0];
if (pluginname.equalsIgnoreCase("all") || pluginname.equalsIgnoreCase("*")) {
main.plugman.reloadAll(sender);
return;
}
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
main.plugman.reload(sender, plugin);
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
};
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public String getPossibleArguments() {
return "<插件名称|all|*>";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
}

View File

@ -7,6 +7,7 @@ import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import cn.citycraft.Yum.Yum; import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.utils.StringUtil;
/** /**
* 插件删除命令类 * 插件删除命令类
@ -20,7 +21,7 @@ public class CommandRepo extends BaseCommand {
* @param name * @param name
*/ */
public CommandRepo(Yum main) { public CommandRepo(Yum main) {
super("delete"); super("repo");
this.main = main; this.main = main;
} }
@ -32,9 +33,13 @@ public class CommandRepo extends BaseCommand {
if (args.length == 2) { if (args.length == 2) {
main.repo.addRepositories(args[1]); main.repo.addRepositories(args[1]);
} }
sender.sendMessage("§6仓库: §a插件信息已缓存!");
case "list": case "list":
sender.sendMessage("§6仓库: §b缓存的插件信息如下 ");
StringUtil.sendStringArray(sender, main.repo.getAllPluginString());
case "clean": case "clean":
main.repo.clean(); main.repo.clean();
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
} }
}; };

View File

@ -0,0 +1,54 @@
/**
*
*/
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;
/**
* 插件删除命令类
*
* @author 蒋天蓓 2015年8月12日下午2:04:05
*/
public class CommandUnload extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandUnload(Yum main) {
super("unload");
this.main = main;
}
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
String pluginname = args[0];
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
if (plugin != null) {
main.plugman.unload(sender, plugin);
} else {
sender.sendMessage("§c插件 " + pluginname + " 不存在或已卸载!");
}
};
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public String getPossibleArguments() {
return "<插件名称>";
}
@Override
public boolean isOnlyPlayerExecutable() {
return false;
}
}

View File

@ -75,7 +75,7 @@ public class FileConfig extends YamlConfiguration {
InputStream stream = plugin.getResource(filename); InputStream stream = plugin.getResource(filename);
try { try {
if (!file.exists()) { if (!file.exists()) {
file.mkdirs(); file.getParentFile().mkdirs();
if (stream == null) { if (stream == null) {
file.createNewFile(); file.createNewFile();
loger.info("配置文件 " + filename + " 不存在 创建新文件..."); loger.info("配置文件 " + filename + " 不存在 创建新文件...");

View File

@ -360,6 +360,17 @@ public class PluginsManager {
return reload(Bukkit.getConsoleSender(), plugin); return reload(Bukkit.getConsoleSender(), plugin);
} }
/**
* 重载所有插件
*/
public void reloadAll(CommandSender sender) {
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (!isIgnored(plugin)) {
reload(sender, plugin);
}
}
}
/** /**
* 重载所有插件 * 重载所有插件
*/ */

View File

@ -43,7 +43,7 @@ public class RepositoryManager {
PluginInfo pi = new PluginInfo(); PluginInfo pi = new PluginInfo();
pi.plugin = plugin; pi.plugin = plugin;
pi.url = pkg.url; pi.url = pkg.url;
plugins.put(plugin.groupId + plugin.artifactId, pi); plugins.put(plugin.groupId + "." + plugin.artifactId, pi);
} }
} }
@ -108,7 +108,7 @@ public class RepositoryManager {
} }
public PluginInfo getPluginInfo(String groupId, String artifactId) { public PluginInfo getPluginInfo(String groupId, String artifactId) {
return plugins.get(groupId + artifactId); return plugins.get(groupId + "." + artifactId);
} }
public PluginInfo getPlugin(String name) { public PluginInfo getPlugin(String name) {
@ -119,6 +119,23 @@ public class RepositoryManager {
return null; return null;
} }
public List<PluginInfo> getAllPlugin() {
List<PluginInfo> li = new ArrayList<PluginInfo>();
for (Entry<String, PluginInfo> plugin : plugins.entrySet()) {
li.add(plugin.getValue());
}
return li;
}
public List<String> getAllPluginString() {
List<String> li = new ArrayList<String>();
for (Entry<String, PluginInfo> plugin : plugins.entrySet()) {
Plugin pl = plugin.getValue().plugin;
li.add(String.format("%s %s(%s)", pl.groupId, pl.artifactId, pl.version));
}
return li;
}
public List<PluginInfo> getPluginInfo(String name) { public List<PluginInfo> getPluginInfo(String name) {
List<PluginInfo> li = new ArrayList<PluginInfo>(); List<PluginInfo> li = new ArrayList<PluginInfo>();
for (Entry<String, PluginInfo> plugin : plugins.entrySet()) { for (Entry<String, PluginInfo> plugin : plugins.entrySet()) {