diff --git a/pom.xml b/pom.xml
index 954cb5d..138ad37 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
- PermissionsTime
+ PermissionsTime-${project.version}
${basedir}/src/main
@@ -50,11 +50,33 @@
org.apache.maven.plugins
maven-compiler-plugin
+ 3.6.1
1.8
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.0.2
+
+
+
+ gg.frog.mc.permissionstime.Main
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 3.0.2
+
+ UTF-8
+
+
diff --git a/src/main/gg/frog/mc/permissionstime/Main.java b/src/main/gg/frog/mc/permissionstime/Main.java
new file mode 100644
index 0000000..a15af2b
--- /dev/null
+++ b/src/main/gg/frog/mc/permissionstime/Main.java
@@ -0,0 +1,8 @@
+package gg.frog.mc.permissionstime;
+
+public class Main {
+
+ public static void main(String[] args) {
+ System.out.println("Put jar file in 'plugins' folder And Reload / Restart your server");
+ }
+}
diff --git a/src/main/gg/frog/mc/permissionstime/PluginMain.java b/src/main/gg/frog/mc/permissionstime/PluginMain.java
index b4e6f47..3efa15c 100644
--- a/src/main/gg/frog/mc/permissionstime/PluginMain.java
+++ b/src/main/gg/frog/mc/permissionstime/PluginMain.java
@@ -25,7 +25,7 @@ public class PluginMain extends JavaPlugin {
PluginMain.pm = this;
registerListeners();
registerCommands();
- cm = new ConfigManager(this);
+ cm = new ConfigManager();
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " " + PluginMain.PLUGIN_NAME + " v" + PluginMain.PLUGIN_VERSION));
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " 作者:宅宅蛙 QQ:324747460"));
diff --git a/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java b/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java
index e3c022c..0c84c2f 100644
--- a/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java
+++ b/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java
@@ -1,10 +1,21 @@
package gg.frog.mc.permissionstime.config;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Map.Entry;
import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.utils.PluginConfig;
+import gg.frog.mc.permissionstime.config.LangCfg;
+import gg.frog.mc.permissionstime.config.PluginCfg;
+import gg.frog.mc.permissionstime.utils.FileUtil;
+import gg.frog.mc.permissionstime.utils.FileUtil.FindFilesDo;
/**
* 配置文件管理
@@ -13,20 +24,26 @@ import gg.frog.mc.permissionstime.utils.PluginConfig;
*
*/
public class ConfigManager {
-
+
private PluginMain pm = PluginMain.getInstance();
private Map cfgMap = new LinkedHashMap<>();
- public ConfigManager(PluginMain pm) {
-
+ public ConfigManager() {
+ File langFolder = new File(pm.getDataFolder(), "lang/");
+ if (!langFolder.exists()) {
+ copyLangFilesFromJar();
+ }
// 添加到配置列表
- this.cfgMap.put("plugin", new PluginCfg());
- this.cfgMap.put("lang", new LangCfg());
+ cfgMap.put("plugin", new PluginCfg());
+ cfgMap.put("lang", new LangCfg("lang/" + PluginCfg.LANG + ".yml"));
}
public void reloadConfig() {
- for (PluginConfig cfg : cfgMap.values()) {
- cfg.reloadConfig();
+ for (Entry entry : cfgMap.entrySet()) {
+ if ("lang".equals(entry.getKey())) {
+ entry.setValue(new LangCfg("lang/" + PluginCfg.LANG + ".yml"));
+ }
+ entry.getValue().reloadConfig();
}
}
@@ -34,4 +51,41 @@ public class ConfigManager {
return cfgMap;
}
+ private void copyLangFilesFromJar() {
+ FileUtil.findFilesFromJar(new FindFilesDo() {
+
+ @Override
+ public void process(String fileName, InputStream is) {
+ File f = new File(pm.getDataFolder(),fileName);
+ File parentFolder = f.getParentFile();
+ if (!parentFolder.exists()) {
+ parentFolder.mkdirs();
+ }
+ try {
+ OutputStream os = new FileOutputStream(f);
+ int bytesRead = 0;
+ byte[] buffer = new byte[8192];
+ while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+ os.close();
+ is.close();
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public boolean isProcess(String fileName) {
+ if (fileName.matches("lang/.+\\.yml")) {
+ return true;
+ }
+ return false;
+ }
+ }, this.getClass());
+ }
}
diff --git a/src/main/gg/frog/mc/permissionstime/config/LangCfg.java b/src/main/gg/frog/mc/permissionstime/config/LangCfg.java
index bc6f8a3..f782d6d 100644
--- a/src/main/gg/frog/mc/permissionstime/config/LangCfg.java
+++ b/src/main/gg/frog/mc/permissionstime/config/LangCfg.java
@@ -1,6 +1,5 @@
package gg.frog.mc.permissionstime.config;
-import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.utils.PluginConfig;
/**
@@ -11,13 +10,11 @@ import gg.frog.mc.permissionstime.utils.PluginConfig;
*/
public class LangCfg extends PluginConfig {
- private PluginMain pm = PluginMain.getInstance();
-
public static String NO_PERMISSION = null;
public static String CONFIG_RELOADED = null;
- public LangCfg() {
- super("lang/zh-cn.yml");
+ public LangCfg(String fileName) {
+ super(fileName);
}
@Override
diff --git a/src/main/gg/frog/mc/permissionstime/config/PluginCfg.java b/src/main/gg/frog/mc/permissionstime/config/PluginCfg.java
index 1ecbdd2..6d2346c 100644
--- a/src/main/gg/frog/mc/permissionstime/config/PluginCfg.java
+++ b/src/main/gg/frog/mc/permissionstime/config/PluginCfg.java
@@ -10,11 +10,10 @@ import gg.frog.mc.permissionstime.utils.PluginConfig;
*
*/
public class PluginCfg extends PluginConfig {
-
- private static PluginMain pm = PluginMain.getInstance();
public static String PLUGIN_PREFIX = null;
public static Boolean IS_DEBUG = null;
+ public static String LANG = null;
public PluginCfg() {
@@ -23,14 +22,16 @@ public class PluginCfg extends PluginConfig {
@Override
protected void init() {
+ getConfig().set("lang","zh-cn");
getConfig().set("debug", false);
saveConfig();
}
@Override
protected void loadToDo() {
- PLUGIN_PREFIX = (String)getConfig().get("pluginPrefix","&b["+PluginMain.PLUGIN_NAME+"]&r");
+ PLUGIN_PREFIX = getConfig().getString("pluginPrefix","&b["+PluginMain.PLUGIN_NAME+"]&r");
IS_DEBUG = getConfig().getBoolean("debug", false);
+ LANG = getConfig().getString("lang","zh-cn");
}
}
diff --git a/src/main/gg/frog/mc/permissionstime/utils/FileUtil.java b/src/main/gg/frog/mc/permissionstime/utils/FileUtil.java
new file mode 100644
index 0000000..30a582b
--- /dev/null
+++ b/src/main/gg/frog/mc/permissionstime/utils/FileUtil.java
@@ -0,0 +1,46 @@
+package gg.frog.mc.permissionstime.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+public class FileUtil {
+
+ public interface FindFilesDo {
+ boolean isProcess(String fileName);
+ void process(String fileName, InputStream is);
+ }
+
+ public static void findFilesFromJar(FindFilesDo ffd, Class> jarClazz){
+ JarFile jarFile = null;
+ try {
+ String jarFilePath = jarClazz.getProtectionDomain().getCodeSource().getLocation().getFile();
+ jarFile = new JarFile(jarFilePath);
+ Enumeration entries = jarFile.entries();
+ while (entries.hasMoreElements()) {
+ JarEntry e = entries.nextElement();
+ if(ffd.isProcess(e.getName())){
+ InputStream is = jarFile.getInputStream(e);
+ ffd.process(e.getName(), is);
+ try {
+ is.close();
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (jarFile != null) {
+ try {
+ jarFile.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
diff --git a/src/resources/config.yml b/src/resources/config.yml
index ac1561d..a81c92f 100644
--- a/src/resources/config.yml
+++ b/src/resources/config.yml
@@ -1 +1 @@
-pluginPrefix: '&b[&4插件前缀&b]&r'
+pluginPrefix: '&b[&4权限限时&b]&r'
diff --git a/src/resources/lang/en.yml b/src/resources/lang/en.yml
new file mode 100644
index 0000000..093f83e
--- /dev/null
+++ b/src/resources/lang/en.yml
@@ -0,0 +1,2 @@
+nopermission: '&4You do not have permission to that.'
+configReloaded: '&aComplete configuration reload.'
diff --git a/src/resources/plugin.yml b/src/resources/plugin.yml
index 3941c89..0c7e24e 100644
--- a/src/resources/plugin.yml
+++ b/src/resources/plugin.yml
@@ -1,13 +1,13 @@
-name: QuickDevDemo
-main: gg.frog.mc.quickdevdemo.PluginMain
+name: PermissionsTime
+main: gg.frog.mc.permissionstime.PluginMain
version: 0.0.1
author: GeekFrog
commands:
- quickdevdemo:
+ permissionstime:
description: Show all commands.
permissions:
- quickdevdemo.reload:
+ permissionstime.reload:
description: Reloads the config file.
default: false
\ No newline at end of file