1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-22 15:48:51 +00:00

项目初始化,随框架更新

This commit is contained in:
GeekFrog 2017-07-08 09:47:15 +08:00
parent 3a920f5df0
commit 8fd9e9774d
10 changed files with 152 additions and 22 deletions

24
pom.xml
View File

@ -31,7 +31,7 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>PermissionsTime</finalName> <finalName>PermissionsTime-${project.version}</finalName>
<sourceDirectory>${basedir}/src/main</sourceDirectory> <sourceDirectory>${basedir}/src/main</sourceDirectory>
<resources> <resources>
<resource> <resource>
@ -50,11 +50,33 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration> <configuration>
<source>1.8</source> <source>1.8</source>
<target>1.8</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>gg.frog.mc.permissionstime.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- 解决资源文件的编码问题 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<ciManagement> <ciManagement>

View File

@ -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");
}
}

View File

@ -25,7 +25,7 @@ public class PluginMain extends JavaPlugin {
PluginMain.pm = this; PluginMain.pm = this;
registerListeners(); registerListeners();
registerCommands(); 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 + "==============================="));
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 + " " + PluginMain.PLUGIN_NAME + " v" + PluginMain.PLUGIN_VERSION));
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " 作者:宅宅蛙 QQ324747460")); pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " 作者:宅宅蛙 QQ324747460"));

View File

@ -1,10 +1,21 @@
package gg.frog.mc.permissionstime.config; 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.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.utils.PluginConfig; 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;
/** /**
* 配置文件管理 * 配置文件管理
@ -17,16 +28,22 @@ public class ConfigManager {
private PluginMain pm = PluginMain.getInstance(); private PluginMain pm = PluginMain.getInstance();
private Map<String, PluginConfig> cfgMap = new LinkedHashMap<>(); private Map<String, PluginConfig> 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()); cfgMap.put("plugin", new PluginCfg());
this.cfgMap.put("lang", new LangCfg()); cfgMap.put("lang", new LangCfg("lang/" + PluginCfg.LANG + ".yml"));
} }
public void reloadConfig() { public void reloadConfig() {
for (PluginConfig cfg : cfgMap.values()) { for (Entry<String, PluginConfig> entry : cfgMap.entrySet()) {
cfg.reloadConfig(); 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; 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());
}
} }

View File

@ -1,6 +1,5 @@
package gg.frog.mc.permissionstime.config; package gg.frog.mc.permissionstime.config;
import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.utils.PluginConfig; import gg.frog.mc.permissionstime.utils.PluginConfig;
/** /**
@ -11,13 +10,11 @@ import gg.frog.mc.permissionstime.utils.PluginConfig;
*/ */
public class LangCfg extends PluginConfig { public class LangCfg extends PluginConfig {
private PluginMain pm = PluginMain.getInstance();
public static String NO_PERMISSION = null; public static String NO_PERMISSION = null;
public static String CONFIG_RELOADED = null; public static String CONFIG_RELOADED = null;
public LangCfg() { public LangCfg(String fileName) {
super("lang/zh-cn.yml"); super(fileName);
} }
@Override @Override

View File

@ -11,10 +11,9 @@ import gg.frog.mc.permissionstime.utils.PluginConfig;
*/ */
public class PluginCfg extends PluginConfig { public class PluginCfg extends PluginConfig {
private static PluginMain pm = PluginMain.getInstance();
public static String PLUGIN_PREFIX = null; public static String PLUGIN_PREFIX = null;
public static Boolean IS_DEBUG = null; public static Boolean IS_DEBUG = null;
public static String LANG = null;
public PluginCfg() { public PluginCfg() {
@ -23,14 +22,16 @@ public class PluginCfg extends PluginConfig {
@Override @Override
protected void init() { protected void init() {
getConfig().set("lang","zh-cn");
getConfig().set("debug", false); getConfig().set("debug", false);
saveConfig(); saveConfig();
} }
@Override @Override
protected void loadToDo() { 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); IS_DEBUG = getConfig().getBoolean("debug", false);
LANG = getConfig().getString("lang","zh-cn");
} }
} }

View File

@ -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<JarEntry> 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();
}
}
}
}
}

View File

@ -1 +1 @@
pluginPrefix: '&b[&4插件前缀&b]&r' pluginPrefix: '&b[&4权限限时&b]&r'

View File

@ -0,0 +1,2 @@
nopermission: '&4You do not have permission to that.'
configReloaded: '&aComplete configuration reload.'

View File

@ -1,13 +1,13 @@
name: QuickDevDemo name: PermissionsTime
main: gg.frog.mc.quickdevdemo.PluginMain main: gg.frog.mc.permissionstime.PluginMain
version: 0.0.1 version: 0.0.1
author: GeekFrog author: GeekFrog
commands: commands:
quickdevdemo: permissionstime:
description: Show all commands. description: Show all commands.
permissions: permissions:
quickdevdemo.reload: permissionstime.reload:
description: Reloads the config file. description: Reloads the config file.
default: false default: false