From d236296e69f18dce8223df85eb70ecb679396903 Mon Sep 17 00:00:00 2001 From: GeekFrog Date: Sun, 17 Jun 2018 00:29:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=B0=E5=8F=B7=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 + pom.xml | 2 +- .../frog/mc/permissionstime/PluginMain.java | 28 ++- .../permissionstime/command/MainCommand.java | 29 ++- .../mc/permissionstime/command/TagCmd.java | 70 +++++++ .../permissionstime/config/ConfigManager.java | 3 +- .../mc/permissionstime/config/LangCfg.java | 14 +- .../mc/permissionstime/config/PluginCfg.java | 2 + .../mc/permissionstime/config/TagNameCfg.java | 169 ++++++++++++++++ .../gui/PlayerPermissionShow.java | 2 +- .../mc/permissionstime/gui/PlayerTagShow.java | 60 ++++++ .../listener/MainListener.java | 133 ++++++++---- .../model/cfg/PermissionPackageBean.java | 34 ++-- .../model/cfg/PlayerTagBean.java | 191 ++++++++++++++++++ .../model/cfg/TagPackageBean.java | 95 +++++++++ src/resources/config.yml | 5 +- src/resources/lang/en.yml | 8 +- src/resources/lang/zh-cn.yml | 6 + src/resources/plugin.yml | 8 +- src/resources/tagNames.yml | 53 +++++ 20 files changed, 834 insertions(+), 81 deletions(-) create mode 100644 src/main/gg/frog/mc/permissionstime/command/TagCmd.java create mode 100644 src/main/gg/frog/mc/permissionstime/config/TagNameCfg.java create mode 100644 src/main/gg/frog/mc/permissionstime/gui/PlayerTagShow.java create mode 100644 src/main/gg/frog/mc/permissionstime/model/cfg/PlayerTagBean.java create mode 100644 src/main/gg/frog/mc/permissionstime/model/cfg/TagPackageBean.java create mode 100644 src/resources/tagNames.yml diff --git a/README.md b/README.md index e2c0c36..c15e23f 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ 经测试支持大部分1.7.10-1.12的服务器. 其他版本未做测试. +本插件增加了称号管理功能,默认情况下为关闭状态.(2018-06-15) + #### 插件截图: ![image](http://i.imgur.com/cnnd5hb.jpg) ![image](http://i.imgur.com/bqvIVvz.jpg) @@ -52,6 +54,7 @@ - **玩家登录时删除过期的或无效数据** - **提示剩余时间** - **权限包到期可执行自定义命令** +- **增加称号管理功能** - 取消前置插件 diff --git a/pom.xml b/pom.xml index 233727e..a25dcaa 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 gg.frog.mc permissionstime - 0.3.3-SNAPSHOT + 0.4.0-SNAPSHOT jar PermissionsTime 支持跨服的权限限时插件 diff --git a/src/main/gg/frog/mc/permissionstime/PluginMain.java b/src/main/gg/frog/mc/permissionstime/PluginMain.java index c9d43a8..f2c8fbd 100644 --- a/src/main/gg/frog/mc/permissionstime/PluginMain.java +++ b/src/main/gg/frog/mc/permissionstime/PluginMain.java @@ -19,6 +19,7 @@ import gg.frog.mc.permissionstime.listener.MainListener; import gg.frog.mc.permissionstime.utils.FileUtil; import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.UpdateCheck; +import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; public class PluginMain extends JavaPlugin { @@ -33,6 +34,7 @@ public class PluginMain extends JavaPlugin { private PluginMain pm = null; private SqlManager sm = null; private Permission permission = null; + private Chat chat = null; public PluginMain() { PLUGIN_NAME = getDescription().getName(); @@ -51,9 +53,9 @@ 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 + "===============================")); - getServer().getScheduler().runTask(pm, new UpdateCheck(pm)); getServer().getScheduler().runTask(pm, new Runnable() { - public void run() { + + public void run() { if (!checkPluginDepends()) { getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Startup failure!")); getServer().getPluginManager().disablePlugin(pm); @@ -64,12 +66,12 @@ public class PluginMain extends JavaPlugin { } if (PluginCfg.IS_METRICS) { try { - Metrics metrics = new Metrics(pm); -// metrics.addCustomChart(new Metrics.SimplePie("chart_id", () -> "My value")); + new Metrics(pm); } catch (Exception e) { e.printStackTrace(); } } + getServer().getScheduler().runTaskAsynchronously(pm, new UpdateCheck(pm)); } }); } @@ -108,7 +110,11 @@ public class PluginMain extends JavaPlugin { return permission; } - private boolean checkPluginDepends() { + public Chat getChat() { + return chat; + } + + private boolean checkPluginDepends() { boolean needDepend = false; for (String name : DEPEND_PLUGIN.split(",")) { if (getServer().getPluginManager().getPlugin(name) == null) { @@ -120,6 +126,10 @@ public class PluginMain extends JavaPlugin { getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault permission")); needDepend = true; } + if (!needDepend && !setupChat()) { + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault chat")); + needDepend = true; + } if (!needDepend && !setupDatabase()) { getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t setup database")); needDepend = true; @@ -148,6 +158,14 @@ public class PluginMain extends JavaPlugin { return (permission != null); } + private boolean setupChat() { + RegisteredServiceProvider chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class); + if (chatProvider != null) { + chat = chatProvider.getProvider(); + } + return (chat != null); + } + private boolean setupDatabase() { sm = new SqlManager(pm); return sm.updateDatabase(); diff --git a/src/main/gg/frog/mc/permissionstime/command/MainCommand.java b/src/main/gg/frog/mc/permissionstime/command/MainCommand.java index 9672620..b32f30e 100644 --- a/src/main/gg/frog/mc/permissionstime/command/MainCommand.java +++ b/src/main/gg/frog/mc/permissionstime/command/MainCommand.java @@ -46,7 +46,13 @@ public class MainCommand implements CommandExecutor, TabCompleter { if (sender.isOp() || player.hasPermission("permissionstime.reload")) { for (Player p : pm.getServer().getOnlinePlayers()) { InventoryView inventory = p.getOpenInventory(); - if (StrUtil.messageFormat(LangCfg.INVENTORY_NAME + "&r&5&9&2&0&r").equals(inventory.getTitle())) { + if (inventory!=null && + ( + StrUtil.messageFormat(LangCfg.INVENTORY_NAME + "&r&5&9&2&0&r").equals(inventory.getTitle()) + || + StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "&r&5&9&2&0&r").equals(inventory.getTitle()) + ) + ) { inventory.close(); } } @@ -79,6 +85,15 @@ public class MainCommand implements CommandExecutor, TabCompleter { if (hasPermission(sender, isPlayer, "permissionstime.me")) { MeCmd meCmd = new MeCmd(pm, sender, isPlayer, args); new Thread(meCmd).start(); + } + } else if (args[0].equalsIgnoreCase("tag")) { + if (hasPermission(sender, isPlayer, "permissionstime.tag")) { + if(PluginCfg.TAG_SYSTEM) { + TagCmd tagCmd = new TagCmd(pm, sender, isPlayer, args); + new Thread(tagCmd).start(); + }else { + sender.sendMessage(StrUtil.messageFormat(LangCfg.MSG_FUNC_DISABLED, LangCfg.TAG)); + } } } else if (args[0].equalsIgnoreCase("give")) { if (hasPermission(sender, isPlayer, "permissionstime.give")) { @@ -124,6 +139,9 @@ public class MainCommand implements CommandExecutor, TabCompleter { if (isPlayer && (sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) { sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_ME, pm.PLUGIN_NAME_LOWER_CASE)); } + if (isPlayer && (sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) { + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE)); + } if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages")) { sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_PACKAGES, pm.PLUGIN_NAME_LOWER_CASE)); } @@ -171,6 +189,9 @@ public class MainCommand implements CommandExecutor, TabCompleter { if ("me".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) { tipList.add("me"); } + if ("tag".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) { + tipList.add("tag"); + } if ("packages".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages"))) { tipList.add("packages"); } @@ -201,8 +222,10 @@ public class MainCommand implements CommandExecutor, TabCompleter { tipList.add(name); } } - } else if ("give".equalsIgnoreCase(args[0]) || "set".equalsIgnoreCase(args[0]) || "get".equalsIgnoreCase(args[0]) || "remove".equalsIgnoreCase(args[0]) || "removeall".equalsIgnoreCase(args[0])) { - return null; + } else if ("tag".equalsIgnoreCase(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) { + tipList.add("c"); + tipList.add("p"); + tipList.add("s"); } } else if (args.length == 3) { args[0] = args[0].toLowerCase(Locale.ENGLISH); diff --git a/src/main/gg/frog/mc/permissionstime/command/TagCmd.java b/src/main/gg/frog/mc/permissionstime/command/TagCmd.java new file mode 100644 index 0000000..0cba439 --- /dev/null +++ b/src/main/gg/frog/mc/permissionstime/command/TagCmd.java @@ -0,0 +1,70 @@ +package gg.frog.mc.permissionstime.command; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.inventory.ItemStack; + +import gg.frog.mc.permissionstime.PluginMain; +import gg.frog.mc.permissionstime.config.LangCfg; +import gg.frog.mc.permissionstime.config.PluginCfg; +import gg.frog.mc.permissionstime.config.TagNameCfg; +import gg.frog.mc.permissionstime.config.TagNameCfg.TagType; +import gg.frog.mc.permissionstime.gui.PlayerTagShow; +import gg.frog.mc.permissionstime.utils.StrUtil; + +public class TagCmd implements Runnable { + + private PluginMain pm; + private String[] args; + private CommandSender sender; + private boolean isPlayer; + + public TagCmd(PluginMain pm, CommandSender sender, boolean isPlayer, String[] args) { + this.pm = pm; + this.sender = sender; + this.isPlayer = isPlayer; + this.args = args; + } + + @Override + public void run() { + if (isPlayer) { + if (args.length == 2) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); + List itemList = new ArrayList(); + TagType type = null; + Map> p_i_map; + if ("c".equals(args[1])) { + type = TagNameCfg.TagType.NAMECOLOR_TYPE; + p_i_map = TagNameCfg.NAMECOLOR_ITEMS; + } else if ("p".equals(args[1])) { + type = TagNameCfg.TagType.PREFIX_TYPE; + p_i_map = TagNameCfg.PREFIX_ITEMS; + } else if ("s".equals(args[1])) { + type = TagNameCfg.TagType.SUFFIX_TYPE; + p_i_map = TagNameCfg.SUFFIX_ITEMS; + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE)); + return; + } + for (String p : p_i_map.keySet()) { + if ("".equals(p) || sender.hasPermission(p)) { + itemList.addAll(p_i_map.get(p)); + } + } + OfflinePlayer player = pm.getOfflinePlayer(sender.getName()); + PlayerTagShow.show(player.getPlayer(), type, itemList); + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Only player can use this command.")); + } + } +} diff --git a/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java b/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java index 940114e..76e613c 100644 --- a/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java +++ b/src/main/gg/frog/mc/permissionstime/config/ConfigManager.java @@ -33,6 +33,7 @@ public class ConfigManager { 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 void reloadConfig() { @@ -74,7 +75,7 @@ public class ConfigManager { @Override public boolean isProcess(String fileName) { - if (fileName.matches("lang/.+\\.yml") || "config.yml".equals(fileName) || "packages.yml".equals(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; diff --git a/src/main/gg/frog/mc/permissionstime/config/LangCfg.java b/src/main/gg/frog/mc/permissionstime/config/LangCfg.java index 4b88b48..9b71135 100644 --- a/src/main/gg/frog/mc/permissionstime/config/LangCfg.java +++ b/src/main/gg/frog/mc/permissionstime/config/LangCfg.java @@ -12,11 +12,14 @@ import gg.frog.mc.permissionstime.utils.config.PluginConfig; public class LangCfg extends PluginConfig { public static String INVENTORY_NAME = null; + public static String TAG_INVENTORY_NAME = null; public static String EXPIRATION_TIME = null; public static String LEFT_TIME = null; public static String TIME_UNIT_D = null; public static String TIME_UNIT_H = null; public static String TIME_UNIT_M = null; + public static String TIME_FOREVER = null; + public static String TAG = null; public static String MSG_PARAMETER_MISMATCH = null; public static String MSG_TIME_PARAMETER_INCORRECT = null; @@ -47,9 +50,12 @@ public class LangCfg extends PluginConfig { public static String MSG_EXPIRATION_DATE = null; public static String MSG_UNKNOWN_PACKAGE = null; public static String MSG_IS_EXPIRATION_DATE = null; + public static String MSG_FUNC_DISABLED = null; + public static String MSG_TAG_SET_SUCCESS = null; public static String CMD_HELP = null; public static String CMD_ME = null; + public static String CMD_TAG = null; public static String CMD_PACKAGES = null; public static String CMD_GET = null; public static String CMD_GIVE = null; @@ -68,11 +74,14 @@ public class LangCfg extends PluginConfig { @Override protected void loadToDo() { 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}"); LEFT_TIME = getConfig().getString("leftTime", "&4Left time: About {0}{1} {2}{3} {4}{5}"); TIME_UNIT_D = getConfig().getString("timeUnitD", "day(s)"); TIME_UNIT_H = getConfig().getString("timeUnitH", "hour(s)"); TIME_UNIT_M = getConfig().getString("timeUnitM", "minute(s)"); + TIME_FOREVER = getConfig().getString("timeForever", "Forever"); + TAG = getConfig().getString("tag", "Tag/Prefix"); 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."); @@ -103,9 +112,12 @@ public class LangCfg extends PluginConfig { MSG_EXPIRATION_DATE = getConfig().getString("msg.expirationDate", "{0}packages: {1}({2}), Expiration date: {3}, {4}"); MSG_UNKNOWN_PACKAGE = getConfig().getString("msg.unknownPackage", "Unknown Packages"); MSG_IS_EXPIRATION_DATE = getConfig().getString("msg.isExpirationDate", "Your package: {0}({1})&r has expired."); + MSG_FUNC_DISABLED = getConfig().getString("msg.funcDisabled", "{0} functionality disabled."); + MSG_TAG_SET_SUCCESS = getConfig().getString("msg.tagSetSuccess", "&2Tag Set Success."); CMD_HELP = getConfig().getString("cmd.help", "/{0} help \\n&7 - Show commands."); - CMD_ME = getConfig().getString("cmd.me", "&6/{0} me \\n&7 - View self package."); + CMD_ME = getConfig().getString("cmd.me", "&6/{0} me \\n&7 - View your packages."); + CMD_TAG = getConfig().getString("cmd.tag", "&6/{0} tag \\n&7 - View your color/prefix/suffix tags."); CMD_PACKAGES = getConfig().getString("cmd.packages", "&6/{0} packages [packageName] \\n&7 - View packages."); CMD_GET = getConfig().getString("cmd.get", "&6/{0} get \\n&7 - View player packages."); CMD_GIVE = getConfig().getString("cmd.give", "&6/{0} give