diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandHandler.java b/src/main/java/cn/citycraft/Yum/commands/CommandHandler.java index 387a538..fb2c1c9 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandHandler.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandHandler.java @@ -66,6 +66,9 @@ public class CommandHandler implements CommandExecutor, TabCompleter { registerCommand(new CommandDelete(yum)); registerCommand(new CommandInfo(yum)); registerCommand(new CommandRepo(yum)); + registerCommand(new CommandReload(yum)); + registerCommand(new CommandLoad(yum)); + registerCommand(new CommandUnload(yum)); RegisterCommandList = getRegisterCommands(); } diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandLoad.java b/src/main/java/cn/citycraft/Yum/commands/CommandLoad.java new file mode 100644 index 0000000..a37aeaf --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/commands/CommandLoad.java @@ -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; + } +} diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandReload.java b/src/main/java/cn/citycraft/Yum/commands/CommandReload.java new file mode 100644 index 0000000..fe024e3 --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/commands/CommandReload.java @@ -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; + } +} diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java b/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java index d2e74e2..b469b2a 100644 --- a/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java +++ b/src/main/java/cn/citycraft/Yum/commands/CommandRepo.java @@ -7,6 +7,7 @@ import org.bukkit.command.CommandException; import org.bukkit.command.CommandSender; import cn.citycraft.Yum.Yum; +import cn.citycraft.Yum.utils.StringUtil; /** * 插件删除命令类 @@ -20,7 +21,7 @@ public class CommandRepo extends BaseCommand { * @param name */ public CommandRepo(Yum main) { - super("delete"); + super("repo"); this.main = main; } @@ -32,9 +33,13 @@ public class CommandRepo extends BaseCommand { if (args.length == 2) { main.repo.addRepositories(args[1]); } + sender.sendMessage("§6仓库: §a插件信息已缓存!"); case "list": + sender.sendMessage("§6仓库: §b缓存的插件信息如下 "); + StringUtil.sendStringArray(sender, main.repo.getAllPluginString()); case "clean": main.repo.clean(); + sender.sendMessage("§6仓库: §a缓存的插件信息已清理!"); } }; diff --git a/src/main/java/cn/citycraft/Yum/commands/CommandUnload.java b/src/main/java/cn/citycraft/Yum/commands/CommandUnload.java new file mode 100644 index 0000000..9b55254 --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/commands/CommandUnload.java @@ -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; + } +} diff --git a/src/main/java/cn/citycraft/Yum/config/FileConfig.java b/src/main/java/cn/citycraft/Yum/config/FileConfig.java index 1bbd575..21e2c04 100644 --- a/src/main/java/cn/citycraft/Yum/config/FileConfig.java +++ b/src/main/java/cn/citycraft/Yum/config/FileConfig.java @@ -75,7 +75,7 @@ public class FileConfig extends YamlConfiguration { InputStream stream = plugin.getResource(filename); try { if (!file.exists()) { - file.mkdirs(); + file.getParentFile().mkdirs(); if (stream == null) { file.createNewFile(); loger.info("配置文件 " + filename + " 不存在 创建新文件..."); diff --git a/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java b/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java index 82b5f01..f01ce10 100644 --- a/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java @@ -360,6 +360,17 @@ public class PluginsManager { return reload(Bukkit.getConsoleSender(), plugin); } + /** + * 重载所有插件 + */ + public void reloadAll(CommandSender sender) { + for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { + if (!isIgnored(plugin)) { + reload(sender, plugin); + } + } + } + /** * 重载所有插件 */ diff --git a/src/main/java/cn/citycraft/Yum/repository/RepositoryManager.java b/src/main/java/cn/citycraft/Yum/repository/RepositoryManager.java index 40b87ef..b24ef13 100644 --- a/src/main/java/cn/citycraft/Yum/repository/RepositoryManager.java +++ b/src/main/java/cn/citycraft/Yum/repository/RepositoryManager.java @@ -43,7 +43,7 @@ public class RepositoryManager { PluginInfo pi = new PluginInfo(); pi.plugin = plugin; 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) { - return plugins.get(groupId + artifactId); + return plugins.get(groupId + "." + artifactId); } public PluginInfo getPlugin(String name) { @@ -119,6 +119,23 @@ public class RepositoryManager { return null; } + public List getAllPlugin() { + List li = new ArrayList(); + for (Entry plugin : plugins.entrySet()) { + li.add(plugin.getValue()); + } + return li; + } + + public List getAllPluginString() { + List li = new ArrayList(); + for (Entry 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 getPluginInfo(String name) { List li = new ArrayList(); for (Entry plugin : plugins.entrySet()) {