mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 22:38:46 +00:00
add load unload and reload command...
This commit is contained in:
parent
8f0ce09497
commit
abfdd97a28
@ -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();
|
||||
}
|
||||
|
54
src/main/java/cn/citycraft/Yum/commands/CommandLoad.java
Normal file
54
src/main/java/cn/citycraft/Yum/commands/CommandLoad.java
Normal 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;
|
||||
}
|
||||
}
|
58
src/main/java/cn/citycraft/Yum/commands/CommandReload.java
Normal file
58
src/main/java/cn/citycraft/Yum/commands/CommandReload.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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缓存的插件信息已清理!");
|
||||
}
|
||||
};
|
||||
|
||||
|
54
src/main/java/cn/citycraft/Yum/commands/CommandUnload.java
Normal file
54
src/main/java/cn/citycraft/Yum/commands/CommandUnload.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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 + " 不存在 创建新文件...");
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载所有插件
|
||||
*/
|
||||
|
@ -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<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) {
|
||||
List<PluginInfo> li = new ArrayList<PluginInfo>();
|
||||
for (Entry<String, PluginInfo> plugin : plugins.entrySet()) {
|
||||
|
Loading…
Reference in New Issue
Block a user