mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 14:28:46 +00:00
添加File文件操作命令...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
8819fe6ad2
commit
3f52c0462a
4
pom.xml
4
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>cn.citycraft</groupId>
|
<groupId>cn.citycraft</groupId>
|
||||||
<artifactId>Yum</artifactId>
|
<artifactId>Yum</artifactId>
|
||||||
<version>1.8.9</version>
|
<version>1.9</version>
|
||||||
<name>Yum</name>
|
<name>Yum</name>
|
||||||
<description>Minecraft 服务器插件管理系统</description>
|
<description>Minecraft 服务器插件管理系统</description>
|
||||||
<build>
|
<build>
|
||||||
@ -55,7 +55,7 @@
|
|||||||
</build>
|
</build>
|
||||||
<properties>
|
<properties>
|
||||||
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
||||||
<update.description>&a通过检测NMS版本实现多端兼容处理...</update.description>
|
<update.description>&c添加File文件操作命令...</update.description>
|
||||||
<env.BUILD_NUMBER>Debug</env.BUILD_NUMBER>
|
<env.BUILD_NUMBER>Debug</env.BUILD_NUMBER>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -9,6 +9,7 @@ import cn.citycraft.PluginHelper.config.FileConfig;
|
|||||||
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||||
import cn.citycraft.Yum.api.YumAPI;
|
import cn.citycraft.Yum.api.YumAPI;
|
||||||
import cn.citycraft.Yum.commands.YumCommand;
|
import cn.citycraft.Yum.commands.YumCommand;
|
||||||
|
import cn.citycraft.Yum.file.commands.FileCommand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MC插件仓库
|
* MC插件仓库
|
||||||
@ -25,8 +26,9 @@ public class Yum extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
new YumCommand(this);
|
|
||||||
new YumAPI(this);
|
new YumAPI(this);
|
||||||
|
new YumCommand(this);
|
||||||
|
new FileCommand(this);
|
||||||
YumAPI.getRepo().jsonToCache(config);
|
YumAPI.getRepo().jsonToCache(config);
|
||||||
YumAPI.updaterepo();
|
YumAPI.updaterepo();
|
||||||
new VersionChecker(this);
|
new VersionChecker(this);
|
||||||
|
@ -2,6 +2,8 @@ package cn.citycraft.Yum.api;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@ -34,7 +36,7 @@ public class YumAPI {
|
|||||||
* 初始化Yum管理中心
|
* 初始化Yum管理中心
|
||||||
*
|
*
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* - 插件实体
|
* 插件实体
|
||||||
*/
|
*/
|
||||||
public YumAPI(final Plugin plugin) {
|
public YumAPI(final Plugin plugin) {
|
||||||
YumAPI.main = plugin;
|
YumAPI.main = plugin;
|
||||||
@ -47,7 +49,7 @@ public class YumAPI {
|
|||||||
* 删除插件
|
* 删除插件
|
||||||
*
|
*
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* - 插件实体
|
* 插件实体
|
||||||
*/
|
*/
|
||||||
public static void delete(final Plugin plugin) {
|
public static void delete(final Plugin plugin) {
|
||||||
plugman.deletePlugin(plugin);
|
plugman.deletePlugin(plugin);
|
||||||
@ -84,11 +86,11 @@ public class YumAPI {
|
|||||||
* 安装新插件
|
* 安装新插件
|
||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* - 命令发送者
|
* 命令发送者
|
||||||
* @param pluginname
|
* @param pluginname
|
||||||
* - 插件名称
|
* 插件名称
|
||||||
* @param version
|
* @param version
|
||||||
* - 插件版本
|
* 插件版本
|
||||||
* @return 是否安装成功
|
* @return 是否安装成功
|
||||||
*/
|
*/
|
||||||
public static boolean install(final CommandSender sender, final String pluginname, final String url) {
|
public static boolean install(final CommandSender sender, final String pluginname, final String url) {
|
||||||
@ -103,9 +105,9 @@ public class YumAPI {
|
|||||||
* 安装新插件
|
* 安装新插件
|
||||||
*
|
*
|
||||||
* @param pluginname
|
* @param pluginname
|
||||||
* - 插件名称
|
* 插件名称
|
||||||
* @param version
|
* @param version
|
||||||
* - 插件版本
|
* 插件版本
|
||||||
* @return 是否安装成功
|
* @return 是否安装成功
|
||||||
*/
|
*/
|
||||||
public static boolean install(final String pluginname, final String url) {
|
public static boolean install(final String pluginname, final String url) {
|
||||||
@ -116,9 +118,9 @@ public class YumAPI {
|
|||||||
* 安装新插件
|
* 安装新插件
|
||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* - 命令发送者
|
* 命令发送者
|
||||||
* @param pluginname
|
* @param pluginname
|
||||||
* - 插件名称
|
* 插件名称
|
||||||
* @return 是否安装成功
|
* @return 是否安装成功
|
||||||
*/
|
*/
|
||||||
public static boolean installfromyum(final CommandSender sender, final String pluginname) {
|
public static boolean installfromyum(final CommandSender sender, final String pluginname) {
|
||||||
@ -129,11 +131,11 @@ public class YumAPI {
|
|||||||
* 安装新插件
|
* 安装新插件
|
||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* - 命令发送者
|
* 命令发送者
|
||||||
* @param pluginname
|
* @param pluginname
|
||||||
* - 插件名称
|
* 插件名称
|
||||||
* @param version
|
* @param version
|
||||||
* - 插件版本
|
* 插件版本
|
||||||
* @return 是否安装成功
|
* @return 是否安装成功
|
||||||
*/
|
*/
|
||||||
public static boolean installfromyum(final CommandSender sender, final String pluginname, final String version) {
|
public static boolean installfromyum(final CommandSender sender, final String pluginname, final String version) {
|
||||||
@ -148,7 +150,7 @@ public class YumAPI {
|
|||||||
* 载入插件
|
* 载入插件
|
||||||
*
|
*
|
||||||
* @param pluginname
|
* @param pluginname
|
||||||
* - 插件名称
|
* 插件名称
|
||||||
*/
|
*/
|
||||||
public static void load(final File pluginFile) {
|
public static void load(final File pluginFile) {
|
||||||
plugman.load(pluginFile);
|
plugman.load(pluginFile);
|
||||||
@ -158,7 +160,7 @@ public class YumAPI {
|
|||||||
* 载入插件
|
* 载入插件
|
||||||
*
|
*
|
||||||
* @param pluginname
|
* @param pluginname
|
||||||
* - 插件名称
|
* 插件名称
|
||||||
*/
|
*/
|
||||||
public static void load(final String pluginname) {
|
public static void load(final String pluginname) {
|
||||||
plugman.load(pluginname);
|
plugman.load(pluginname);
|
||||||
@ -168,7 +170,7 @@ public class YumAPI {
|
|||||||
* 重载插件
|
* 重载插件
|
||||||
*
|
*
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* - 插件实体
|
* 插件实体
|
||||||
*/
|
*/
|
||||||
public static void reload(final Plugin plugin) {
|
public static void reload(final Plugin plugin) {
|
||||||
plugman.reload(plugin);
|
plugman.reload(plugin);
|
||||||
@ -178,7 +180,7 @@ public class YumAPI {
|
|||||||
* 卸载插件
|
* 卸载插件
|
||||||
*
|
*
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* - 插件实体
|
* 插件实体
|
||||||
*/
|
*/
|
||||||
public static void unload(final Plugin plugin) {
|
public static void unload(final Plugin plugin) {
|
||||||
plugman.unload(plugin);
|
plugman.unload(plugin);
|
||||||
@ -188,11 +190,11 @@ public class YumAPI {
|
|||||||
* 更新插件
|
* 更新插件
|
||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* - 命令发送者
|
* 命令发送者
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* - 插件实体
|
* 插件实体
|
||||||
* @param url
|
* @param url
|
||||||
* - 新插件的下载地址
|
* 新插件的下载地址
|
||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
public static boolean update(final CommandSender sender, final Plugin plugin, final URL url) {
|
public static boolean update(final CommandSender sender, final Plugin plugin, final URL url) {
|
||||||
@ -208,9 +210,9 @@ public class YumAPI {
|
|||||||
* 更新插件
|
* 更新插件
|
||||||
*
|
*
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* - 插件实体
|
* 插件实体
|
||||||
* @param url
|
* @param url
|
||||||
* - 新插件的下载地址
|
* 新插件的下载地址
|
||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
public static boolean update(final Plugin plugin, final URL url) {
|
public static boolean update(final Plugin plugin, final URL url) {
|
||||||
@ -221,30 +223,29 @@ public class YumAPI {
|
|||||||
* 更新支持Yum的插件
|
* 更新支持Yum的插件
|
||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* - 命令发送者
|
* 命令发送者
|
||||||
*/
|
*/
|
||||||
public static void updateall(final CommandSender sender) {
|
public static void updateall(final CommandSender sender) {
|
||||||
|
final List<Plugin> ulist = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final Map<String, Plugin> updatelist = UpdatePlugin.getUpdateList();
|
|
||||||
if (updatelist.size() > 0) {
|
|
||||||
for (final Entry<String, Plugin> updateplugin : UpdatePlugin.getUpdateList().entrySet()) {
|
for (final Entry<String, Plugin> updateplugin : UpdatePlugin.getUpdateList().entrySet()) {
|
||||||
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getKey() + "!");
|
ulist.add(updateplugin.getValue());
|
||||||
updatefromyum(sender, updateplugin.getValue(), null);
|
|
||||||
}
|
}
|
||||||
UpdatePlugin.clearList();
|
UpdatePlugin.clearList();
|
||||||
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
|
|
||||||
sender.sendMessage("§d一键更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
|
|
||||||
}
|
|
||||||
} catch (final Exception | Error e) {
|
} catch (final Exception | Error e) {
|
||||||
try {
|
try {
|
||||||
final Map<Plugin, String> updatelist = UpdatePlugin.getList();
|
final Map<Plugin, String> updatelist = UpdatePlugin.getList();
|
||||||
if (updatelist.size() > 0) {
|
ulist.addAll(updatelist.keySet());
|
||||||
for (final Entry<Plugin, String> updateplugin : UpdatePlugin.getList().entrySet()) {
|
UpdatePlugin.getList().clear();
|
||||||
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getKey().getName() + "!");
|
} catch (final Exception | Error e2) {
|
||||||
updatefromyum(sender, updateplugin.getKey(), null);
|
sender.sendMessage("§4错误: §c无法检索全体更新列表!");
|
||||||
|
sender.sendMessage("§4异常: §c" + e2.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ulist.size() > 0) {
|
||||||
|
for (final Plugin updateplugin : ulist) {
|
||||||
|
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getName() + "!");
|
||||||
|
updatefromyum(sender, updateplugin, null, true);
|
||||||
}
|
}
|
||||||
UpdatePlugin.getList().clear();
|
UpdatePlugin.getList().clear();
|
||||||
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
|
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
|
||||||
@ -252,20 +253,15 @@ public class YumAPI {
|
|||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
|
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
|
||||||
}
|
}
|
||||||
} catch (final Exception | Error e2) {
|
|
||||||
sender.sendMessage("§4错误: §c无法检索全体更新列表!");
|
|
||||||
sender.sendMessage("§4异常: §c" + e2.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新插件
|
* 更新插件
|
||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* - 命令发送者
|
* 命令发送者
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* - 插件实体
|
* 插件实体
|
||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin) {
|
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin) {
|
||||||
@ -276,19 +272,38 @@ public class YumAPI {
|
|||||||
* 从Yum内部更新插件
|
* 从Yum内部更新插件
|
||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* - 命令发送者
|
* 命令发送者
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* - 插件实体
|
* 插件实体
|
||||||
* @param version
|
* @param version
|
||||||
* - 插件版本(null则自动获取)
|
* 插件版本(null则自动获取)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version) {
|
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version) {
|
||||||
|
return updatefromyum(sender, plugin, version, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从Yum内部更新插件
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
* 命令发送者
|
||||||
|
* @param plugin
|
||||||
|
* 插件实体
|
||||||
|
* @param version
|
||||||
|
* 插件版本(null则自动获取)
|
||||||
|
* @param oneKeyUpdate
|
||||||
|
* 是否一键更新
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version, final boolean oneKeyUpdate) {
|
||||||
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
||||||
if (pi != null) {
|
if (pi != null) {
|
||||||
if (download.run(sender, pi.getUrl(sender, version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) {
|
if (download.run(sender, pi.getUrl(sender, version), new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName()))) {
|
||||||
|
if (!oneKeyUpdate) {
|
||||||
sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹");
|
sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹");
|
||||||
sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
|
sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -311,9 +326,9 @@ public class YumAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sender
|
* @param sender
|
||||||
* - 命令发送者
|
* 命令发送者
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* - 插件实体
|
* 插件实体
|
||||||
*/
|
*/
|
||||||
public static void upgrade(final CommandSender sender, final Plugin plugin) {
|
public static void upgrade(final CommandSender sender, final Plugin plugin) {
|
||||||
plugman.upgrade(sender, plugin);
|
plugman.upgrade(sender, plugin);
|
||||||
|
@ -22,7 +22,7 @@ public class CommandDelete extends BaseCommand {
|
|||||||
Yum main;
|
Yum main;
|
||||||
|
|
||||||
public CommandDelete(final Yum main) {
|
public CommandDelete(final Yum main) {
|
||||||
super("d");
|
super("del");
|
||||||
this.main = main;
|
this.main = main;
|
||||||
setMinimumArguments(1);
|
setMinimumArguments(1);
|
||||||
setDescription("删除插件");
|
setDescription("删除插件");
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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 蒋天蓓 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("删除文件(服务器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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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 蒋天蓓 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));
|
||||||
|
}
|
||||||
|
if (args.length == 1) {
|
||||||
|
dl.run(sender, urlstr, file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
src/main/java/cn/citycraft/Yum/file/commands/CommandLs.java
Normal file
55
src/main/java/cn/citycraft/Yum/file/commands/CommandLs.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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 蒋天蓓 2015年8月12日下午2:04:05
|
||||||
|
*/
|
||||||
|
public class CommandLs extends BaseCommand {
|
||||||
|
|
||||||
|
public CommandLs(final Yum main) {
|
||||||
|
super();
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
src/main/java/cn/citycraft/Yum/file/commands/CommandRm.java
Normal file
53
src/main/java/cn/citycraft/Yum/file/commands/CommandRm.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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 蒋天蓓 2015年8月12日下午2:04:05
|
||||||
|
*/
|
||||||
|
public class CommandRm extends BaseCommand {
|
||||||
|
|
||||||
|
public CommandRm(final Yum main) {
|
||||||
|
super();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
if (file.getAbsolutePath().toLowerCase().endsWith("plugins") || file.getAbsolutePath().toLowerCase().endsWith("world")) {
|
||||||
|
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删除失败!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package cn.citycraft.Yum.file.commands;
|
||||||
|
|
||||||
|
import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
|
||||||
|
import cn.citycraft.Yum.Yum;
|
||||||
|
|
||||||
|
public class FileCommand {
|
||||||
|
public FileCommand(final Yum yum) {
|
||||||
|
final HandlerSubCommand cmdhandler = new HandlerSubCommand(yum, "file");
|
||||||
|
cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyCommandConsole", false));
|
||||||
|
cmdhandler.registerCommand(new CommandDownLoad(yum));
|
||||||
|
cmdhandler.registerCommand(new CommandDelete(yum));
|
||||||
|
cmdhandler.registerCommand(new CommandRm(yum));
|
||||||
|
cmdhandler.registerCommand(new CommandLs(yum));
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,11 @@ commands:
|
|||||||
usage: §6使用§a/yum help§6查看帮助!
|
usage: §6使用§a/yum help§6查看帮助!
|
||||||
permission: yum.use
|
permission: yum.use
|
||||||
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
||||||
|
file:
|
||||||
|
description: MC文件管理命令
|
||||||
|
usage: §6使用§a/yum help§6查看帮助!
|
||||||
|
permission: yum.use
|
||||||
|
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
||||||
permissions:
|
permissions:
|
||||||
yum.use:
|
yum.use:
|
||||||
description: 插件管理系统使用权限!
|
description: 插件管理系统使用权限!
|
||||||
|
Loading…
Reference in New Issue
Block a user