mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-11-22 07:28:47 +00:00
项目初始化,随框架更新
This commit is contained in:
parent
3a920f5df0
commit
8fd9e9774d
24
pom.xml
24
pom.xml
@ -31,7 +31,7 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>PermissionsTime</finalName>
|
||||
<finalName>PermissionsTime-${project.version}</finalName>
|
||||
<sourceDirectory>${basedir}/src/main</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
@ -50,11 +50,33 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</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>
|
||||
</build>
|
||||
<ciManagement>
|
||||
|
8
src/main/gg/frog/mc/permissionstime/Main.java
Normal file
8
src/main/gg/frog/mc/permissionstime/Main.java
Normal 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");
|
||||
}
|
||||
}
|
@ -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"));
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
* 配置文件管理
|
||||
@ -17,16 +28,22 @@ public class ConfigManager {
|
||||
private PluginMain pm = PluginMain.getInstance();
|
||||
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());
|
||||
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<String, PluginConfig> 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());
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -11,10 +11,9 @@ 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");
|
||||
}
|
||||
|
||||
}
|
||||
|
46
src/main/gg/frog/mc/permissionstime/utils/FileUtil.java
Normal file
46
src/main/gg/frog/mc/permissionstime/utils/FileUtil.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1 +1 @@
|
||||
pluginPrefix: '&b[&4插件前缀&b]&r'
|
||||
pluginPrefix: '&b[&4权限限时&b]&r'
|
||||
|
2
src/resources/lang/en.yml
Normal file
2
src/resources/lang/en.yml
Normal file
@ -0,0 +1,2 @@
|
||||
nopermission: '&4You do not have permission to that.'
|
||||
configReloaded: '&aComplete configuration reload.'
|
@ -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
|
Loading…
Reference in New Issue
Block a user