1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-22 07:28:47 +00:00

读取权限包配置

This commit is contained in:
GeekFrog 2017-07-10 10:45:18 +08:00
parent 8fd9e9774d
commit 75d0f202fb
11 changed files with 228 additions and 13 deletions

21
pom.xml
View File

@ -20,6 +20,15 @@
<id>spigotmc-repo</id> <id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url> <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository> </repository>
<repository>
<id>dakani</id>
<name>Dakani Nexus Repo</name>
<url>https://repo.dakanilabs.com/repository/public/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
@ -29,6 +38,18 @@
<type>jar</type> <type>jar</type>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>lib.PatPeter.SQLibrary</groupId>
<artifactId>SQLibrary</artifactId>
<version>7.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>PermissionsTime-${project.version}</finalName> <finalName>PermissionsTime-${project.version}</finalName>

View File

@ -15,22 +15,24 @@ public class PluginMain extends JavaPlugin {
public static final String PLUGIN_NAME = "PermissionsTime"; public static final String PLUGIN_NAME = "PermissionsTime";
public static final String PLUGIN_VERSION = "0.0.1"; public static final String PLUGIN_VERSION = "0.0.1";
public static final String PLUGIN_NAME_LOWER_CASE = PLUGIN_NAME.toLowerCase(Locale.ENGLISH); public static final String PLUGIN_NAME_LOWER_CASE = PLUGIN_NAME.toLowerCase(Locale.ENGLISH);
public static final Logger LOG = Logger.getLogger(PluginMain.PLUGIN_NAME); public static final Logger LOG = Logger.getLogger("Minecraft");
private static PluginMain pm = null; private static PluginMain pm = null;
private ConfigManager cm = null; private ConfigManager cm = null;
@Override @Override
public void onEnable() { public void onEnable() {
PluginMain.pm = this; pm = this;
cm = new ConfigManager();
registerListeners(); registerListeners();
registerCommands(); registerCommands();
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));
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 + " authorGeekFrog QQ324747460"));
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ ")); pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ "));
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 + "==============================="));
} }
public static PluginMain getInstance() { public static PluginMain getInstance() {

View File

@ -11,11 +11,11 @@ import java.util.Map;
import java.util.Map.Entry; 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.config.LangCfg; import gg.frog.mc.permissionstime.config.LangCfg;
import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.utils.FileUtil; import gg.frog.mc.permissionstime.utils.FileUtil;
import gg.frog.mc.permissionstime.utils.FileUtil.FindFilesDo; import gg.frog.mc.permissionstime.utils.FileUtil.FindFilesDo;
import gg.frog.mc.permissionstime.utils.config.PluginConfig;
/** /**
* 配置文件管理 * 配置文件管理
@ -36,6 +36,7 @@ public class ConfigManager {
// 添加到配置列表 // 添加到配置列表
cfgMap.put("plugin", new PluginCfg()); cfgMap.put("plugin", new PluginCfg());
cfgMap.put("lang", new LangCfg("lang/" + PluginCfg.LANG + ".yml")); cfgMap.put("lang", new LangCfg("lang/" + PluginCfg.LANG + ".yml"));
cfgMap.put("packages", new PackagesCfg("packages.yml"));
} }
public void reloadConfig() { public void reloadConfig() {

View File

@ -1,6 +1,6 @@
package gg.frog.mc.permissionstime.config; package gg.frog.mc.permissionstime.config;
import gg.frog.mc.permissionstime.utils.PluginConfig; import gg.frog.mc.permissionstime.utils.config.PluginConfig;
/** /**
* 语言支持 * 语言支持

View File

@ -0,0 +1,42 @@
package gg.frog.mc.permissionstime.config;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.model.PermissionPackageBean;
import gg.frog.mc.permissionstime.utils.config.PluginConfig;
public class PackagesCfg extends PluginConfig {
public static String PACKAGES_VERSION = null;
public static String DEFAULT_GROUP = null;
public static Map<String, PermissionPackageBean> PACKAGES = new HashMap<>();
public PackagesCfg(String fileName) {
super(fileName);
}
@Override
protected void init() {
getConfig().set("version", PluginMain.PLUGIN_VERSION);
getConfig().set("defaultGroup", "Default");
saveConfig();
}
@Override
protected void loadToDo() {
PACKAGES_VERSION = getConfig().getString("version", "?");
DEFAULT_GROUP = getConfig().getString("defaultGroup", "Default");
PACKAGES = getObjMap("packages", PermissionPackageBean.class);
if (PluginCfg.IS_DEBUG) {
System.out.println("packages vresion:" + PACKAGES_VERSION);
System.out.println("defaultGroup:" + DEFAULT_GROUP);
for (Entry<String, PermissionPackageBean> p : PACKAGES.entrySet()) {
System.out.println(p);
}
}
}
}

View File

@ -1,7 +1,7 @@
package gg.frog.mc.permissionstime.config; package gg.frog.mc.permissionstime.config;
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.config.PluginConfig;
/** /**
* 插件默认配置 * 插件默认配置
@ -14,7 +14,11 @@ public class PluginCfg extends PluginConfig {
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 static String LANG = null;
public static String SQL_HOSTNAME;
public static int SQL_PORT;
public static String SQL_DATABASE;
public static String SQL_USERNAME;
public static String SQL_PASSWORD;
public PluginCfg() { public PluginCfg() {
super(); super();

View File

@ -0,0 +1,78 @@
package gg.frog.mc.permissionstime.model;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration;
import gg.frog.mc.permissionstime.utils.config.IConfigBean;
/**
* 权限包实体类
*
* @author QiaoPengyu
*
*/
public class PermissionPackageBean implements IConfigBean {
private List<String> permissions = new ArrayList<>();
private List<String> groups = new ArrayList<>();
private List<String> prefixs = new ArrayList<>();
private List<String> suffixs = new ArrayList<>();
public List<String> getPermissions() {
return permissions;
}
public void setPermissions(List<String> permissions) {
this.permissions = permissions;
}
public List<String> getGroups() {
return groups;
}
public void setGroups(List<String> groups) {
this.groups = groups;
}
public List<String> getPrefixs() {
return prefixs;
}
public void setPrefixs(List<String> prefixs) {
this.prefixs = prefixs;
}
public List<String> getSuffixs() {
return suffixs;
}
public void setSuffixs(List<String> suffixs) {
this.suffixs = suffixs;
}
@Override
public YamlConfiguration toConfig() {
YamlConfiguration config = new YamlConfiguration();
config.set("permissions", permissions);
config.set("groups", groups);
config.set("prefixs", prefixs);
config.set("suffixs", suffixs);
return config;
}
@Override
public void toConfigBean(MemorySection config) {
permissions = config.getStringList("permissions");
groups = config.getStringList("groups");
prefixs = config.getStringList("prefixs");
suffixs = config.getStringList("suffixs");
}
@Override
public String toString() {
return "PermissionPackageBean [permissions=" + permissions + ", groups=" + groups + ", prefixs=" + prefixs + ", suffixs=" + suffixs + "]";
}
}

View File

@ -0,0 +1,11 @@
package gg.frog.mc.permissionstime.utils.config;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration;
public interface IConfigBean {
YamlConfiguration toConfig();
void toConfigBean(MemorySection config);
}

View File

@ -1,11 +1,15 @@
package gg.frog.mc.permissionstime.utils; package gg.frog.mc.permissionstime.utils.config;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -57,12 +61,12 @@ public abstract class PluginConfig {
reloadConfig(); reloadConfig();
} }
} }
/** /**
* 首次生成文件调用 * 首次生成文件调用
*/ */
protected abstract void init(); protected abstract void init();
/** /**
* 加载配置后调用 * 加载配置后调用
*/ */
@ -121,4 +125,30 @@ public abstract class PluginConfig {
config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8))); config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
loadToDo(); loadToDo();
} }
protected void saveObj(String path, Map<String, ? extends IConfigBean> o) {
for (Entry<String, ? extends IConfigBean> configBean : o.entrySet()) {
getConfig().set(path + "." + configBean.getKey(), configBean.getValue().toConfig());
}
}
protected <T extends IConfigBean> Map<String, T> getObjMap(String path, Class<T> clazz) {
Map<String, T> map = new HashMap<>();
MemorySection configMap = (MemorySection) getConfig().get(path);
if (configMap != null) {
for (String key : configMap.getKeys(false)) {
MemorySection beanConfig = (MemorySection) configMap.get(key);
if (beanConfig != null) {
try {
T bean = clazz.newInstance();
bean.toConfigBean(beanConfig);
map.put(key, bean);
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
return map;
}
} }

View File

@ -0,0 +1,21 @@
version: 0.0.1
defaultGroup: Default
packages:
#权限包名称
example1:
#权限包含有的权限
permissions:
- permission1
- permission2
#权限包含有的权限组
groups:
- group1
- group2
#权限包含有的前缀
prefixs:
- '&2[Player]&3'
- '&2[VIP]&3'
#权限包含有的后缀
suffixs:
- '→❤'
- '→★'

View File

@ -2,12 +2,17 @@ name: PermissionsTime
main: gg.frog.mc.permissionstime.PluginMain main: gg.frog.mc.permissionstime.PluginMain
version: 0.0.1 version: 0.0.1
author: GeekFrog author: GeekFrog
softdepend: [SQLibrary, Vault]
commands: commands:
permissionstime: permissionstime:
description: Show all commands. description: Show all commands.
permissions: permissions:
permissionstime.*:
description: Gives access to all PermissionsTime commands.
children:
permissionstime.reload: true
permissionstime.reload: permissionstime.reload:
description: Reloads the config file. description: Reloads the config file.
default: false default: op