From 6aa80bd2905f79cdb886c156acfcd1695a8f4971 Mon Sep 17 00:00:00 2001 From: GeekFrog Date: Sun, 24 Jun 2018 11:22:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B6=85=E5=A4=9ABUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/gg/frog/mc/base/PluginMain.java | 22 +- .../gg/frog/mc/base/config/ConfigManager.java | 117 +++--- src/main/gg/frog/mc/base/config/LangCfg.java | 10 +- .../gg/frog/mc/base/config/PluginCfg.java | 4 +- .../mc/base/utils/config/PluginConfig.java | 353 +++++++++--------- .../frog/mc/nametags/config/TagNameCfg.java | 15 +- .../frog/mc/nametags/gui/PlayerTagShow.java | 2 +- .../mc/nametags/listener/TagsListener.java | 2 +- .../frog/mc/nametags/model/PlayerTagBean.java | 3 +- .../mc/permissionstime/command/PtCommand.java | 4 +- .../permissionstime/config/PackagesCfg.java | 195 +++++----- .../gui/PlayerPermissionShow.java | 2 +- .../{MainListener.java => PtListener.java} | 6 +- 13 files changed, 388 insertions(+), 347 deletions(-) rename src/main/gg/frog/mc/permissionstime/listener/{MainListener.java => PtListener.java} (94%) diff --git a/src/main/gg/frog/mc/base/PluginMain.java b/src/main/gg/frog/mc/base/PluginMain.java index 8ee9b87..46b6806 100644 --- a/src/main/gg/frog/mc/base/PluginMain.java +++ b/src/main/gg/frog/mc/base/PluginMain.java @@ -21,7 +21,7 @@ import gg.frog.mc.nametags.listener.TagsListener; import gg.frog.mc.nametags.placeholder.TagPlaceholder; import gg.frog.mc.permissionstime.command.PtCommand; import gg.frog.mc.permissionstime.database.SqlManager; -import gg.frog.mc.permissionstime.listener.MainListener; +import gg.frog.mc.permissionstime.listener.PtListener; import net.milkbowl.vault.permission.Permission; public class PluginMain extends JavaPlugin { @@ -57,17 +57,17 @@ public class PluginMain extends JavaPlugin { getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ ")); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX)); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "===============================")); + if (!checkPluginDepends()) { + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§4Startup failure!")); + getServer().getPluginManager().disablePlugin(pm); + } else { + cm.initConfig(); + registerListeners(); + registerCommands(); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§2Startup successful!")); + } getServer().getScheduler().runTask(pm, new Runnable() { - public void run() { - if (!checkPluginDepends()) { - getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§4Startup failure!")); - getServer().getPluginManager().disablePlugin(pm); - } else { - registerListeners(); - registerCommands(); - getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§2Startup successful!")); - } if (PluginCfg.IS_METRICS) { try { new Metrics(pm); @@ -85,7 +85,7 @@ public class PluginMain extends JavaPlugin { * 这里可以注册多个 */ private void registerListeners() { - pm.getServer().getPluginManager().registerEvents(new MainListener(pm), pm); + pm.getServer().getPluginManager().registerEvents(new PtListener(pm), pm); pm.getServer().getPluginManager().registerEvents(new TagsListener(pm), pm); } diff --git a/src/main/gg/frog/mc/base/config/ConfigManager.java b/src/main/gg/frog/mc/base/config/ConfigManager.java index 5ef5778..acb059f 100644 --- a/src/main/gg/frog/mc/base/config/ConfigManager.java +++ b/src/main/gg/frog/mc/base/config/ConfigManager.java @@ -8,6 +8,8 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; +import org.bukkit.command.CommandSender; + import gg.frog.mc.base.PluginMain; import gg.frog.mc.base.config.LangCfg; import gg.frog.mc.base.config.PluginCfg; @@ -25,66 +27,69 @@ import gg.frog.mc.permissionstime.config.PackagesCfg; */ public class ConfigManager { - private PluginMain pm; - private Map cfgMap = new LinkedHashMap<>(); + private PluginMain pm; + private Map cfgMap = new LinkedHashMap<>(); - public ConfigManager(PluginMain pm) { - this.pm = pm; - copyLangFilesFromJar(); - // 添加到配置列表 - cfgMap.put("plugin", new PluginCfg(pm)); - cfgMap.put("lang", new LangCfg("lang/" + PluginCfg.LANG + ".yml", pm)); - cfgMap.put("packages", new PackagesCfg("packages.yml", pm)); - cfgMap.put("tagNames", new TagNameCfg("tagNames.yml", pm)); - } + public ConfigManager(PluginMain pm) { + this.pm = pm; + copyLangFilesFromJar(); + // 添加到配置列表 + cfgMap.put("plugin", new PluginCfg(pm)); + } - public void reloadConfig() { - for (Entry entry : cfgMap.entrySet()) { - if ("lang".equals(entry.getKey())) { - entry.setValue(new LangCfg("lang/" + PluginCfg.LANG + ".yml", pm)); - } - entry.getValue().reloadConfig(); - } - } + public void initConfig() { + cfgMap.put("lang", new LangCfg("lang/" + PluginCfg.LANG + ".yml", pm)); + cfgMap.put("packages", new PackagesCfg("packages.yml", pm)); + cfgMap.put("tagNames", new TagNameCfg("tagNames.yml", pm)); + } - public Map getCfgMap() { - return cfgMap; - } + public void reloadConfig(CommandSender sender) { + for (Entry entry : cfgMap.entrySet()) { + if ("lang".equals(entry.getKey())) { + entry.setValue(new LangCfg("lang/" + PluginCfg.LANG + ".yml", pm)); + } + entry.getValue().reloadConfig(sender); + } + } - private void copyLangFilesFromJar() { - FileUtil.findFilesFromJar(new FindFilesDo() { + public Map getCfgMap() { + return cfgMap; + } - @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 (Exception e) { - e.printStackTrace(); - } - } + private void copyLangFilesFromJar() { + FileUtil.findFilesFromJar(new FindFilesDo() { - @Override - public boolean isProcess(String fileName) { - if (fileName.matches("lang/.+\\.yml") || "config.yml".equals(fileName) || "packages.yml".equals(fileName) || "tagNames.yml".equals(fileName)) { - File f = new File(pm.getDataFolder(), fileName); - if (!f.exists()) { - return true; - } - } - return false; - } - }, this.getClass()); - } + @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 (Exception e) { + e.printStackTrace(); + } + } + + @Override + public boolean isProcess(String fileName) { + if (fileName.matches("lang/.+\\.yml") || "config.yml".equals(fileName) || "packages.yml".equals(fileName) || "tagNames.yml".equals(fileName)) { + File f = new File(pm.getDataFolder(), fileName); + if (!f.exists()) { + return true; + } + } + return false; + } + }, this.getClass()); + } } diff --git a/src/main/gg/frog/mc/base/config/LangCfg.java b/src/main/gg/frog/mc/base/config/LangCfg.java index 25c1120..c59159d 100644 --- a/src/main/gg/frog/mc/base/config/LangCfg.java +++ b/src/main/gg/frog/mc/base/config/LangCfg.java @@ -1,5 +1,7 @@ package gg.frog.mc.base.config; +import org.bukkit.command.CommandSender; + import gg.frog.mc.base.PluginMain; import gg.frog.mc.base.utils.config.PluginConfig; @@ -77,7 +79,7 @@ public class LangCfg extends PluginConfig { } @Override - protected void loadToDo() { + protected void loadToDo(CommandSender sender) { INVENTORY_NAME = getConfig().getString("inventoryName", "&4===Permissions Packages==="); TAG_INVENTORY_NAME = getConfig().getString("tagInventoryName", "&4===Tag Packages==="); EXPIRATION_TIME = getConfig().getString("expirationTime", "&4Expiration time: {0}"); @@ -87,9 +89,9 @@ public class LangCfg extends PluginConfig { TIME_UNIT_M = getConfig().getString("timeUnitM", "minute(s)"); TIME_FOREVER = getConfig().getString("timeForever", "Forever"); TAG = getConfig().getString("tag", "Tag/Prefix"); - TAG_COLOR_ITEM_NAME = getConfig().getString("tag", "&6&lName Style"); - TAG_PREFIX_ITEM_NAME = getConfig().getString("tag", "&6&lTag Prefix"); - TAG_SUFFIX_ITEM_NAME = getConfig().getString("tag", "&6&lTag Suffix"); + TAG_COLOR_ITEM_NAME = getConfig().getString("tagColorItemName", "&6&lName Style"); + TAG_PREFIX_ITEM_NAME = getConfig().getString("tagPrefixItemName", "&6&lTag Prefix"); + TAG_SUFFIX_ITEM_NAME = getConfig().getString("tagSuffixItemName", "&6&lTag Suffix"); MSG_PARAMETER_MISMATCH = getConfig().getString("msg.parameterMismatch", "&4Parameter mismatch."); MSG_TIME_PARAMETER_INCORRECT = getConfig().getString("msg.timeParameterIncorrect", "&4The number of time is incorrect. Please enter a nonzero integer."); diff --git a/src/main/gg/frog/mc/base/config/PluginCfg.java b/src/main/gg/frog/mc/base/config/PluginCfg.java index 337354a..8625a49 100644 --- a/src/main/gg/frog/mc/base/config/PluginCfg.java +++ b/src/main/gg/frog/mc/base/config/PluginCfg.java @@ -1,5 +1,7 @@ package gg.frog.mc.base.config; +import org.bukkit.command.CommandSender; + import gg.frog.mc.base.PluginMain; import gg.frog.mc.base.utils.config.PluginConfig; @@ -33,7 +35,7 @@ public class PluginCfg extends PluginConfig { protected void init() {} @Override - protected void loadToDo() { + protected void loadToDo(CommandSender sender) { PLUGIN_PREFIX = setGetDefault("pluginPrefix", "§b[" + pm.PLUGIN_NAME + "] ") + "§r"; IS_DEBUG = setGetDefault("debug", false); IS_METRICS = setGetDefault("metrics", true); diff --git a/src/main/gg/frog/mc/base/utils/config/PluginConfig.java b/src/main/gg/frog/mc/base/utils/config/PluginConfig.java index 07b9a6a..90ac457 100644 --- a/src/main/gg/frog/mc/base/utils/config/PluginConfig.java +++ b/src/main/gg/frog/mc/base/utils/config/PluginConfig.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.logging.Level; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.FileConfiguration; @@ -29,192 +30,206 @@ import gg.frog.mc.base.utils.StrUtil; */ public abstract class PluginConfig { - protected PluginMain pm; - private FileConfiguration config = null; - private File folder = null; - private String fileName = null; - private File configFile = null; + protected PluginMain pm; + private FileConfiguration config = null; + private File folder = null; + private String fileName = null; + private File configFile = null; - protected PluginConfig(PluginMain pm) { - this.pm = pm; - initConfig(pm.getDataFolder(), "config.yml"); - } + protected PluginConfig(PluginMain pm) { + this.pm = pm; + initConfig(pm.getDataFolder(), "config.yml"); + } - protected PluginConfig(String fileName, PluginMain pm) { - this.pm = pm; - initConfig(pm.getDataFolder(), fileName); - } + protected PluginConfig(String fileName, PluginMain pm) { + this.pm = pm; + initConfig(pm.getDataFolder(), fileName); + } - protected PluginConfig(File folder, String fileName, PluginMain pm) { - this.pm = pm; - initConfig(folder, fileName); - } + protected PluginConfig(File folder, String fileName, PluginMain pm) { + this.pm = pm; + initConfig(folder, fileName); + } - /** - * 初始化 - * - * @param folder - * @param fileName - */ - private void initConfig(File folder, String fileName) { - this.folder = folder; - this.fileName = fileName; - configFile = new File(folder, fileName); - if (!configFile.exists()) { - getConfig(folder, fileName).options().copyDefaults(true); - init(); - saveAndReloadConfig(); - } else { - reloadConfig(); - } - } + /** + * 初始化 + * + * @param folder + * @param fileName + */ + private void initConfig(File folder, String fileName) { + this.folder = folder; + this.fileName = fileName; + configFile = new File(folder, fileName); + if (!configFile.exists()) { + getConfig(folder, fileName).options().copyDefaults(true); + init(); + saveAndReloadConfig(); + } else { + reloadConfig(); + } + } - /** - * 首次生成文件调用 - */ - protected abstract void init(); + /** + * 首次生成文件调用 + */ + protected abstract void init(); + + /** + * 加载配置后调用 + */ + protected abstract void loadToDo(CommandSender sender); - /** - * 加载配置后调用 - */ - protected abstract void loadToDo(); + /** + * 获取配置(首次) + * + * @return + */ + private FileConfiguration getConfig(File folder, String fileName) { + if (config == null) { + reloadConfig(folder, fileName, true); + } + return config; + } - /** - * 获取配置(首次) - * - * @return - */ - private FileConfiguration getConfig(File folder, String fileName) { - if (config == null) { - reloadConfig(folder, fileName, true); - } - return config; - } + /** + * 获取配置 + * + * @return + */ + protected FileConfiguration getConfig() { + return config; + } - /** - * 获取配置 - * - * @return - */ - protected FileConfiguration getConfig() { - return config; - } + /** + * 保存配置 + */ + public void saveConfig() { + try { + getConfig().save(configFile); + } catch (IOException ex) { + PluginMain.LOG.log(Level.SEVERE, StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Could not save config to " + configFile), ex); + } + } - /** - * 保存配置 - */ - public void saveConfig() { - try { - getConfig().save(configFile); - } catch (IOException ex) { - PluginMain.LOG.log(Level.SEVERE, StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Could not save config to " + configFile), ex); - } - } + public void saveAndReloadConfig() { + try { + getConfig().save(configFile); + reloadConfig(); + } catch (IOException ex) { + PluginMain.LOG.log(Level.SEVERE, StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Could not save config to " + configFile), ex); + } + } - public void saveAndReloadConfig() { - try { - getConfig().save(configFile); - reloadConfig(); - } catch (IOException ex) { - PluginMain.LOG.log(Level.SEVERE, StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Could not save config to " + configFile), ex); - } - } + /** + * 配置重载 + */ + public void reloadConfig() { + reloadConfig(folder, fileName, false); + } - /** - * 配置重载 - */ - public void reloadConfig() { - reloadConfig(folder, fileName, false); - } + /** + * 配置重载 + */ + public void reloadConfig(CommandSender sender) { + reloadConfig(folder, fileName, false, sender); + } - /** - * 配置重载 - */ - private void reloadConfig(File folder, String fileName, boolean useRes) { - YamlConfiguration tempConfig = new YamlConfiguration(); - try { - tempConfig.load(configFile); - config = tempConfig; - } catch (FileNotFoundException e) { - } catch (IOException | InvalidConfigurationException e1) { - tempConfig = null; - e1.printStackTrace(); - } - if (config == null) { - config = new YamlConfiguration(); - } - if (useRes) { - final InputStream defConfigStream = pm.getResource(fileName); - if (defConfigStream == null) { - return; - } - config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8))); - } - loadToDo(); -// if (tempConfig != null) { -// saveConfig(); -// } - } + /** + * 配置重载 + */ + private void reloadConfig(File folder, String fileName, boolean useRes) { + reloadConfig(folder, fileName, useRes, null); + } - protected void setObj(String path, Map o) { - for (Entry configBean : o.entrySet()) { - setObj(path + "." + configBean.getKey(), configBean.getValue()); - } - } + /** + * 配置重载 + */ + private void reloadConfig(File folder, String fileName, boolean useRes, CommandSender sender) { + YamlConfiguration tempConfig = new YamlConfiguration(); + try { + tempConfig.load(configFile); + config = tempConfig; + } catch (FileNotFoundException e) { + } catch (IOException | InvalidConfigurationException e1) { + tempConfig = null; + e1.printStackTrace(); + } + if (config == null) { + config = new YamlConfiguration(); + } + if (useRes) { + final InputStream defConfigStream = pm.getResource(fileName); + if (defConfigStream == null) { + return; + } + config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8))); + } + loadToDo(sender); + // if (tempConfig != null) { + // saveConfig(); + // } + } - protected void setObj(String path, IConfigBean o) { - getConfig().set(path, o.toConfig()); - } + protected void setObj(String path, Map o) { + for (Entry configBean : o.entrySet()) { + setObj(path + "." + configBean.getKey(), configBean.getValue()); + } + } - 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)) { - T bean = getObj(path + "." + key, clazz); - if (bean != null) { - map.put(key, bean); - } - } - } - return map; - } + protected void setObj(String path, IConfigBean o) { + getConfig().set(path, o.toConfig()); + } - protected T getObj(String path, Class clazz) { - Object beanConfig = getConfig().get(path); - if (beanConfig != null && beanConfig instanceof MemorySection) { - try { - T bean = clazz.newInstance(); - bean.toConfigBean((MemorySection) beanConfig); - return bean; - } catch (Exception e) { - e.printStackTrace(); - } - } - return null; - } + 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)) { + T bean = getObj(path + "." + key, clazz); + if (bean != null) { + map.put(key, bean); + } + } + } + return map; + } - protected String setGetDefault(String path, String def) { - if (!getConfig().contains(path)) { - getConfig().set(path, def); - return def; - } - return getConfig().getString(path); - } + protected T getObj(String path, Class clazz) { + Object beanConfig = getConfig().get(path); + if (beanConfig != null && beanConfig instanceof MemorySection) { + try { + T bean = clazz.newInstance(); + bean.toConfigBean((MemorySection) beanConfig); + return bean; + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } - protected int setGetDefault(String path, int def) { - if (!getConfig().contains(path)) { - getConfig().set(path, def); - return def; - } - return getConfig().getInt(path); - } + protected String setGetDefault(String path, String def) { + if (!getConfig().contains(path)) { + getConfig().set(path, def); + return def; + } + return getConfig().getString(path); + } - protected boolean setGetDefault(String path, boolean def) { - if (!getConfig().contains(path)) { - getConfig().set(path, def); - return def; - } - return getConfig().getBoolean(path); - } + protected int setGetDefault(String path, int def) { + if (!getConfig().contains(path)) { + getConfig().set(path, def); + return def; + } + return getConfig().getInt(path); + } + + protected boolean setGetDefault(String path, boolean def) { + if (!getConfig().contains(path)) { + getConfig().set(path, def); + return def; + } + return getConfig().getBoolean(path); + } } diff --git a/src/main/gg/frog/mc/nametags/config/TagNameCfg.java b/src/main/gg/frog/mc/nametags/config/TagNameCfg.java index 8599d39..20b67af 100644 --- a/src/main/gg/frog/mc/nametags/config/TagNameCfg.java +++ b/src/main/gg/frog/mc/nametags/config/TagNameCfg.java @@ -8,6 +8,7 @@ import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Material; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -62,12 +63,22 @@ public class TagNameCfg extends PluginConfig { } @Override - protected void loadToDo() { + protected void loadToDo(CommandSender sender) { DEFAULT_NAMECOLOR = setGetDefault("defaultNamecolor", ""); DEFAULT_PREFIX = setGetDefault("defaultPrefix", ""); DEFAULT_SUFFIX = setGetDefault("defaultSuffix", ""); CHANGE_DISPLAYNAME = setGetDefault("changeDisplayname", true); USE_HD_PLUGIN = setGetDefault("useHdPlugin", false); + if (USE_HD_PLUGIN && !PluginMain.enabledHdPlugin) { + USE_HD_PLUGIN = false; + if (sender != null) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§eHolographicDisplays is not installed or not enabled. ")); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§eBut you enabled some func need HolographicDisplays.")); + } else { + pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§eHolographicDisplays is not installed or not enabled. ")); + pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§eBut you enabled some func need HolographicDisplays.")); + } + } ONE_LINE_DISPLAY = setGetDefault("oneLineDisplay", true); REFRESH_TAG_TIME = setGetDefault("refreshTagTime", -1); PACKAGES = getObjMap("packages", TagPackageBean.class); @@ -114,7 +125,7 @@ public class TagNameCfg extends PluginConfig { SUFFIX_ITEMS.put(e.getValue().getPermissions(), items); } } - + if (task != null) { task.cancel(); } diff --git a/src/main/gg/frog/mc/nametags/gui/PlayerTagShow.java b/src/main/gg/frog/mc/nametags/gui/PlayerTagShow.java index a4ffdc5..fc35ae4 100644 --- a/src/main/gg/frog/mc/nametags/gui/PlayerTagShow.java +++ b/src/main/gg/frog/mc/nametags/gui/PlayerTagShow.java @@ -22,7 +22,7 @@ public class PlayerTagShow { Inventory inventory = null; int size = 0; if (itemList.size() > 0) { - inventory = Bukkit.createInventory(null, ((itemList.size() + disItemList.size()) % 9 == 0 ? (itemList.size() + disItemList.size()) : ((itemList.size() + disItemList.size()) / 9 + 1) * 9), StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "§r§5§9§2§0§r")); + inventory = Bukkit.createInventory(null, ((itemList.size() + disItemList.size()) % 9 == 0 ? (itemList.size() + disItemList.size()) : ((itemList.size() + disItemList.size()) / 9 + 1) * 9), StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "§r§5§9§2§0§2§r")); String uuid = player.getUniqueId().toString(); PlayerTagBean playerTag = null; if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) { diff --git a/src/main/gg/frog/mc/nametags/listener/TagsListener.java b/src/main/gg/frog/mc/nametags/listener/TagsListener.java index dad3253..2fada16 100644 --- a/src/main/gg/frog/mc/nametags/listener/TagsListener.java +++ b/src/main/gg/frog/mc/nametags/listener/TagsListener.java @@ -65,7 +65,7 @@ public class TagsListener implements Listener { @EventHandler public void onPlayerClick(InventoryClickEvent event) { - if (StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "§r§5§9§2§0§r").equals(event.getInventory().getName())) { + if (StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "§r§5§9§2§0§2§r").equals(event.getInventory().getName())) { if (event.getCurrentItem() != null && event.getCurrentItem().getItemMeta() != null && event.getCurrentItem().getItemMeta().hasLore()) { List lores = event.getCurrentItem().getItemMeta().getLore(); if (lores.size() > 1) { diff --git a/src/main/gg/frog/mc/nametags/model/PlayerTagBean.java b/src/main/gg/frog/mc/nametags/model/PlayerTagBean.java index 91895aa..e3744a4 100644 --- a/src/main/gg/frog/mc/nametags/model/PlayerTagBean.java +++ b/src/main/gg/frog/mc/nametags/model/PlayerTagBean.java @@ -1,6 +1,7 @@ package gg.frog.mc.nametags.model; import org.bukkit.Location; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -54,7 +55,7 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl } @Override - protected void loadToDo() { + protected void loadToDo(CommandSender sender) { namecolor = getConfig().getString("namecolor", TagNameCfg.DEFAULT_NAMECOLOR); prefix = getConfig().getString("prefix", TagNameCfg.DEFAULT_PREFIX); suffix = getConfig().getString("suffix", TagNameCfg.DEFAULT_SUFFIX); diff --git a/src/main/gg/frog/mc/permissionstime/command/PtCommand.java b/src/main/gg/frog/mc/permissionstime/command/PtCommand.java index f67e7ad..1c73e49 100644 --- a/src/main/gg/frog/mc/permissionstime/command/PtCommand.java +++ b/src/main/gg/frog/mc/permissionstime/command/PtCommand.java @@ -58,7 +58,7 @@ public class PtCommand implements CommandExecutor, TabCompleter { inventory.close(); } } - pm.getConfigManager().reloadConfig(); + pm.getConfigManager().reloadConfig(sender); if (!sm.updateDatabase()) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§4Database exceptions.")); } @@ -74,7 +74,7 @@ public class PtCommand implements CommandExecutor, TabCompleter { inventory.close(); } } - pm.getConfigManager().reloadConfig(); + pm.getConfigManager().reloadConfig(sender); if (!sm.updateDatabase()) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§4Database exceptions.")); } diff --git a/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java b/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java index 272411e..82a1c5f 100644 --- a/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java +++ b/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java @@ -12,6 +12,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import org.bukkit.Material; +import org.bukkit.command.CommandSender; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -24,103 +25,107 @@ import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean; public class PackagesCfg extends PluginConfig { - public static String PACKAGES_VERSION = null; - public static String DEFAULT_GROUP = null; - public static Map PACKAGES = new ConcurrentHashMap<>(); - public static Map PACKAGE_ITEMS = new ConcurrentHashMap<>(); - public static Set allPermissions = Collections.synchronizedSet(new HashSet()); - public static Set allGroups = Collections.synchronizedSet(new HashSet()); + public static String PACKAGES_VERSION = null; + public static String DEFAULT_GROUP = null; + public static Map PACKAGES = new ConcurrentHashMap<>(); + public static Map PACKAGE_ITEMS = new ConcurrentHashMap<>(); + public static Set allPermissions = Collections.synchronizedSet(new HashSet()); + public static Set allGroups = Collections.synchronizedSet(new HashSet()); - public PackagesCfg(String fileName, PluginMain pm) { - super(fileName, pm); - } + public PackagesCfg(String fileName, PluginMain pm) { + super(fileName, pm); + } - @Override - protected void init() {} + @Override + protected void init() { + } - @Override - protected void loadToDo() { - PACKAGES_VERSION = setGetDefault("version", "1.00"); - DEFAULT_GROUP = setGetDefault("defaultGroup", "Default"); - PACKAGES = getObjMap("packages", PermissionPackageBean.class); - setObj("packages", PACKAGES); - 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.getKey() + ":" + p.getValue()); - } - } - PACKAGE_ITEMS.clear(); - for (Entry e : PACKAGES.entrySet()) { - ItemStack item = getPackageItem(e.getKey(), e.getValue()); - if (item != null) { - PACKAGE_ITEMS.put(e.getKey(), item); - } else { - PluginMain.LOG.log(Level.SEVERE, "Packages of " + e.getKey() + " has problem."); - } - allPermissions.addAll(e.getValue().getPermissions()); - allGroups.addAll(e.getValue().getGroups()); - } - } + @Override + protected void loadToDo(CommandSender sender) { + PACKAGES_VERSION = setGetDefault("version", "1.00"); + DEFAULT_GROUP = setGetDefault("defaultGroup", "Default"); + PACKAGES = getObjMap("packages", PermissionPackageBean.class); + setObj("packages", PACKAGES); + 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.getKey() + ":" + p.getValue()); + } + } + PACKAGE_ITEMS.clear(); + for (Entry e : PACKAGES.entrySet()) { + ItemStack item = getPackageItem(e.getKey(), e.getValue()); + if (item != null) { + PACKAGE_ITEMS.put(e.getKey(), item); + } else { + PluginMain.LOG.log(Level.SEVERE, "Packages of " + e.getKey() + " has problem."); + if (sender != null) { + sender.sendMessage("Packages of " + e.getKey() + " has problem."); + } + } + allPermissions.addAll(e.getValue().getPermissions()); + allGroups.addAll(e.getValue().getGroups()); + } + } - private ItemStack getPackageItem(String name, PermissionPackageBean ppb) { - if (ppb != null) { - Material type = null; - int exid = 0; - String skullOwner = null; - if (ppb.getType() != null) { - String[] args = ppb.getType().split(":"); - type = Material.getMaterial(args[0].toUpperCase(Locale.ENGLISH)); - if (args.length == 2) { - try { - exid = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - if (Material.SKULL_ITEM.equals(type)) { - exid = 3; - skullOwner = args[1]; - } else { - e.printStackTrace(); - } - } - } - } else if (ppb.getId() != null) { - String[] args = ppb.getId().split(":"); - int id = Integer.parseInt(args[0]); - type = Material.getMaterial(id); - if (args.length == 2) { - try { - exid = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - if (Material.SKULL_ITEM.equals(type)) { - exid = 3; - skullOwner = args[1]; - } else { - e.printStackTrace(); - } - } - } - } - if (type != null) { - ItemStack item = new ItemStack(type, 1, (short) 0, (byte) exid); - ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(StrUtil.messageFormat(ppb.getDisplayName() + "§r(" + name + ")")); - List lores = new ArrayList(); - for (String lore : ppb.getLores()) { - lores.add(StrUtil.messageFormat(lore)); - } - lores.add(""); - meta.setLore(lores); - item.setItemMeta(meta); - if (ppb.getGlowing() && !meta.hasEnchants()) { - item = ItemUtil.addEnchantLight(item); - } - if (skullOwner != null) { - item = ItemUtil.addSkullOwner(item, skullOwner); - } - return item; - } - } - return null; - } + private ItemStack getPackageItem(String name, PermissionPackageBean ppb) { + if (ppb != null) { + Material type = null; + int exid = 0; + String skullOwner = null; + if (ppb.getType() != null) { + String[] args = ppb.getType().split(":"); + type = Material.getMaterial(args[0].toUpperCase(Locale.ENGLISH)); + if (args.length == 2) { + try { + exid = Integer.parseInt(args[1]); + } catch (NumberFormatException e) { + if (Material.SKULL_ITEM.equals(type)) { + exid = 3; + skullOwner = args[1]; + } else { + e.printStackTrace(); + } + } + } + } else if (ppb.getId() != null) { + String[] args = ppb.getId().split(":"); + int id = Integer.parseInt(args[0]); + type = Material.getMaterial(id); + if (args.length == 2) { + try { + exid = Integer.parseInt(args[1]); + } catch (NumberFormatException e) { + if (Material.SKULL_ITEM.equals(type)) { + exid = 3; + skullOwner = args[1]; + } else { + e.printStackTrace(); + } + } + } + } + if (type != null) { + ItemStack item = new ItemStack(type, 1, (short) 0, (byte) exid); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(StrUtil.messageFormat(ppb.getDisplayName() + "§r(" + name + ")")); + List lores = new ArrayList(); + for (String lore : ppb.getLores()) { + lores.add(StrUtil.messageFormat(lore)); + } + lores.add(""); + meta.setLore(lores); + item.setItemMeta(meta); + if (ppb.getGlowing() && !meta.hasEnchants()) { + item = ItemUtil.addEnchantLight(item); + } + if (skullOwner != null) { + item = ItemUtil.addSkullOwner(item, skullOwner); + } + return item; + } + } + return null; + } } diff --git a/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java b/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java index b17e68d..8e91355 100644 --- a/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java +++ b/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java @@ -21,7 +21,7 @@ public class PlayerPermissionShow { Inventory inventory = null; int size = 0; if (pdbList.size() > 0) { - inventory = Bukkit.createInventory(null, (pdbList.size() % 9 == 0 ? pdbList.size() : (pdbList.size() / 9 + 1) * 9), StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "§r§5§9§2§0§r")); + inventory = Bukkit.createInventory(null, (pdbList.size() % 9 == 0 ? pdbList.size() : (pdbList.size() / 9 + 1) * 9), StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "§r§5§9§2§0§1§r")); for (PlayerDataBean pdb : pdbList) { PermissionPackageBean ppb = PackagesCfg.PACKAGES.get(pdb.getPackageName()); if (ppb != null && pdb.getGlobal() == ppb.getGlobal()) { diff --git a/src/main/gg/frog/mc/permissionstime/listener/MainListener.java b/src/main/gg/frog/mc/permissionstime/listener/PtListener.java similarity index 94% rename from src/main/gg/frog/mc/permissionstime/listener/MainListener.java rename to src/main/gg/frog/mc/permissionstime/listener/PtListener.java index 38c43b4..d69665a 100644 --- a/src/main/gg/frog/mc/permissionstime/listener/MainListener.java +++ b/src/main/gg/frog/mc/permissionstime/listener/PtListener.java @@ -17,11 +17,11 @@ import gg.frog.mc.base.utils.StrUtil; import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean; import gg.frog.mc.permissionstime.model.db.PlayerDataBean; -public class MainListener implements Listener { +public class PtListener implements Listener { private PluginMain pm; - public MainListener(PluginMain pm) { + public PtListener(PluginMain pm) { this.pm = pm; } @@ -74,7 +74,7 @@ public class MainListener implements Listener { @EventHandler public void onPlayerClick(InventoryClickEvent event) { - if (StrUtil.messageFormat(LangCfg.INVENTORY_NAME + "§r§5§9§2§0§r").equals(event.getInventory().getName())) { + if (StrUtil.messageFormat(LangCfg.INVENTORY_NAME + "§r§5§9§2§0§1§r").equals(event.getInventory().getName())) { event.setCancelled(true); } }