From 6cdc5a41d39f8ecd1d68b6345394ae1767f20703 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 7 Feb 2017 16:02:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9B=BF=E6=8D=A2=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- src/main/java/pw/yumc/YumCore/bukkit/P.java | 26 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/pw/yumc/YumCore/bukkit/P.java b/src/main/java/pw/yumc/YumCore/bukkit/P.java index 1506338..a3b819d 100644 --- a/src/main/java/pw/yumc/YumCore/bukkit/P.java +++ b/src/main/java/pw/yumc/YumCore/bukkit/P.java @@ -6,6 +6,7 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; +import java.net.URLDecoder; import java.util.jar.JarFile; import java.util.logging.Logger; @@ -128,10 +129,22 @@ public class P { * 目录 */ public static void saveFile(final String... dirs) { + saveFile(false, dirs); + } + + /** + * 保存文件 + * + * @param replace + * 是否替换 + * @param dirs + * 目录 + */ + public static void saveFile(boolean replace, final String... dirs) { URL url = instance.getClass().getClassLoader().getResource("plugin.yml"); if (url == null) { return; } String upath = url.getFile().substring(url.getFile().indexOf("/") + 1); - String jarPath = upath.substring(0, upath.indexOf('!')); + String jarPath = URLDecoder.decode(upath.substring(0, upath.indexOf('!'))); if (!new File(jarPath).exists()) { jarPath = "/" + jarPath; } @@ -139,8 +152,15 @@ public class P { jar.stream().forEach(je -> { if (!je.isDirectory()) { for (final String dir : dirs) { - if (je.getName().startsWith(dir) && !new File(getDataFolder(), je.getName()).exists()) { - instance.saveResource(je.getName(), false); + if (je.getName().startsWith(dir)) { + if (!replace) { + // 不替换 并且文件不存在 + if (!new File(getDataFolder(), je.getName()).exists()) { + instance.saveResource(je.getName(), false); + } + } else { + instance.saveResource(je.getName(), true); + } } } }