diff --git a/pom.xml b/pom.xml index 138ad37..7a1969d 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,15 @@ spigotmc-repo https://hub.spigotmc.org/nexus/content/groups/public/ + + dakani + Dakani Nexus Repo + https://repo.dakanilabs.com/repository/public/ + + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases/ + @@ -29,6 +38,18 @@ jar provided + + net.milkbowl.vault + VaultAPI + 1.6 + provided + + + lib.PatPeter.SQLibrary + SQLibrary + 7.1 + + PermissionsTime-${project.version} diff --git a/src/main/gg/frog/mc/permissionstime/PluginMain.java b/src/main/gg/frog/mc/permissionstime/PluginMain.java index 3efa15c..3953684 100644 --- a/src/main/gg/frog/mc/permissionstime/PluginMain.java +++ b/src/main/gg/frog/mc/permissionstime/PluginMain.java @@ -15,22 +15,24 @@ public class PluginMain extends JavaPlugin { public static final String PLUGIN_NAME = "PermissionsTime"; 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 Logger LOG = Logger.getLogger(PluginMain.PLUGIN_NAME); + public static final Logger LOG = Logger.getLogger("Minecraft"); private static PluginMain pm = null; private ConfigManager cm = null; - + @Override public void onEnable() { - PluginMain.pm = this; + pm = this; + cm = new ConfigManager(); registerListeners(); 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 + " " + PluginMain.PLUGIN_NAME + " v" + PluginMain.PLUGIN_VERSION)); - pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " 作者:宅宅蛙 QQ:324747460")); + pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " author:GeekFrog QQ:324747460")); 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 + "===============================")); } public static PluginMain getInstance() { diff --git a/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java b/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java index 0c84c2f..641bfeb 100644 --- a/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java +++ b/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java @@ -11,11 +11,11 @@ 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; +import gg.frog.mc.permissionstime.utils.config.PluginConfig; /** * 配置文件管理 @@ -36,6 +36,7 @@ public class ConfigManager { // 添加到配置列表 cfgMap.put("plugin", new PluginCfg()); cfgMap.put("lang", new LangCfg("lang/" + PluginCfg.LANG + ".yml")); + cfgMap.put("packages", new PackagesCfg("packages.yml")); } public void reloadConfig() { diff --git a/src/main/gg/frog/mc/permissionstime/config/LangCfg.java b/src/main/gg/frog/mc/permissionstime/config/LangCfg.java index f782d6d..2197948 100644 --- a/src/main/gg/frog/mc/permissionstime/config/LangCfg.java +++ b/src/main/gg/frog/mc/permissionstime/config/LangCfg.java @@ -1,6 +1,6 @@ package gg.frog.mc.permissionstime.config; -import gg.frog.mc.permissionstime.utils.PluginConfig; +import gg.frog.mc.permissionstime.utils.config.PluginConfig; /** * 语言支持 diff --git a/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java b/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java new file mode 100644 index 0000000..c494a2c --- /dev/null +++ b/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java @@ -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 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 p : PACKAGES.entrySet()) { + System.out.println(p); + } + } + } + +} diff --git a/src/main/gg/frog/mc/permissionstime/config/PluginCfg.java b/src/main/gg/frog/mc/permissionstime/config/PluginCfg.java index 6d2346c..78453df 100644 --- a/src/main/gg/frog/mc/permissionstime/config/PluginCfg.java +++ b/src/main/gg/frog/mc/permissionstime/config/PluginCfg.java @@ -1,7 +1,7 @@ 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.config.PluginConfig; /** * 插件默认配置 @@ -14,7 +14,11 @@ public class PluginCfg extends PluginConfig { public static String PLUGIN_PREFIX = null; public static Boolean IS_DEBUG = 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() { super(); diff --git a/src/main/gg/frog/mc/permissionstime/model/PermissionPackageBean.java b/src/main/gg/frog/mc/permissionstime/model/PermissionPackageBean.java new file mode 100644 index 0000000..492f709 --- /dev/null +++ b/src/main/gg/frog/mc/permissionstime/model/PermissionPackageBean.java @@ -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 permissions = new ArrayList<>(); + private List groups = new ArrayList<>(); + private List prefixs = new ArrayList<>(); + private List suffixs = new ArrayList<>(); + + public List getPermissions() { + return permissions; + } + + public void setPermissions(List permissions) { + this.permissions = permissions; + } + + public List getGroups() { + return groups; + } + + public void setGroups(List groups) { + this.groups = groups; + } + + public List getPrefixs() { + return prefixs; + } + + public void setPrefixs(List prefixs) { + this.prefixs = prefixs; + } + + public List getSuffixs() { + return suffixs; + } + + public void setSuffixs(List 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 + "]"; + } +} diff --git a/src/main/gg/frog/mc/permissionstime/utils/config/IConfigBean.java b/src/main/gg/frog/mc/permissionstime/utils/config/IConfigBean.java new file mode 100644 index 0000000..18b9e94 --- /dev/null +++ b/src/main/gg/frog/mc/permissionstime/utils/config/IConfigBean.java @@ -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); +} diff --git a/src/main/gg/frog/mc/permissionstime/utils/PluginConfig.java b/src/main/gg/frog/mc/permissionstime/utils/config/PluginConfig.java similarity index 69% rename from src/main/gg/frog/mc/permissionstime/utils/PluginConfig.java rename to src/main/gg/frog/mc/permissionstime/utils/config/PluginConfig.java index 788630b..2fac040 100644 --- a/src/main/gg/frog/mc/permissionstime/utils/PluginConfig.java +++ b/src/main/gg/frog/mc/permissionstime/utils/config/PluginConfig.java @@ -1,11 +1,15 @@ -package gg.frog.mc.permissionstime.utils; +package gg.frog.mc.permissionstime.utils.config; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; import java.util.logging.Level; +import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -57,12 +61,12 @@ public abstract class PluginConfig { reloadConfig(); } } - + /** * 首次生成文件调用 */ protected abstract void init(); - + /** * 加载配置后调用 */ @@ -121,4 +125,30 @@ public abstract class PluginConfig { config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8))); loadToDo(); } + + protected void saveObj(String path, Map o) { + for (Entry configBean : o.entrySet()) { + getConfig().set(path + "." + configBean.getKey(), configBean.getValue().toConfig()); + } + } + + protected Map getObjMap(String path, Class clazz) { + Map 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; + } } diff --git a/src/resources/packages.yml b/src/resources/packages.yml new file mode 100644 index 0000000..3d55a84 --- /dev/null +++ b/src/resources/packages.yml @@ -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: + - '→❤' + - '→★' diff --git a/src/resources/plugin.yml b/src/resources/plugin.yml index 0c7e24e..1c9aa06 100644 --- a/src/resources/plugin.yml +++ b/src/resources/plugin.yml @@ -2,12 +2,17 @@ name: PermissionsTime main: gg.frog.mc.permissionstime.PluginMain version: 0.0.1 author: GeekFrog +softdepend: [SQLibrary, Vault] commands: permissionstime: description: Show all commands. permissions: + permissionstime.*: + description: Gives access to all PermissionsTime commands. + children: + permissionstime.reload: true permissionstime.reload: description: Reloads the config file. - default: false \ No newline at end of file + default: op \ No newline at end of file