1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

feat: 添加文件释放方法

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-01-21 18:38:02 +08:00
parent 82ea829a73
commit 2da6fda3cb

View File

@ -1,9 +1,14 @@
package pw.yumc.YumCore.bukkit; package pw.yumc.YumCore.bukkit;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
@ -118,4 +123,33 @@ public class P {
return instance.isEnabled(); return instance.isEnabled();
} }
/**
* 保存文件
*
* @param dirs
* 目录
*/
public static void saveFile(final String... dirs) {
try {
final URL url = instance.getClass().getClassLoader().getResource("plugin.yml");
if (url == null) { return; }
final String upath = url.getFile().substring(url.getFile().indexOf("/") + 1);
final String jarPath = upath.substring(0, upath.indexOf('!'));
JarFile jar = new JarFile(jarPath);
final Enumeration<JarEntry> jes = jar.entries();
for (JarEntry je = jes.nextElement(); jes.hasMoreElements();) {
if (!je.isDirectory()) {
for (final String dir : dirs) {
if (je.getName().startsWith(dir)) {
if (!new File(getDataFolder(), je.getName()).exists()) {
instance.saveResource(je.getName(), false);
}
}
}
}
}
jar.close();
} catch (IOException ignored) {
}
}
} }