mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-11-21 23:08:48 +00:00
增加称号系统
This commit is contained in:
parent
24003ed771
commit
d236296e69
@ -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 @@
|
||||
- **玩家登录时删除过期的或无效数据**
|
||||
- **提示剩余时间**
|
||||
- **权限包到期可执行自定义命令**
|
||||
- **增加称号管理功能**
|
||||
- 取消前置插件
|
||||
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>gg.frog.mc</groupId>
|
||||
<artifactId>permissionstime</artifactId>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<version>0.4.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>PermissionsTime</name>
|
||||
<description>支持跨服的权限限时插件</description>
|
||||
|
@ -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<Chat> 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();
|
||||
|
@ -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);
|
||||
|
70
src/main/gg/frog/mc/permissionstime/command/TagCmd.java
Normal file
70
src/main/gg/frog/mc/permissionstime/command/TagCmd.java
Normal file
@ -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<ItemStack> itemList = new ArrayList<ItemStack>();
|
||||
TagType type = null;
|
||||
Map<String, List<ItemStack>> 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."));
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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 <c/p/s> \\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 <playerName> \\n&7 - View player packages.");
|
||||
CMD_GIVE = getConfig().getString("cmd.give", "&6/{0} give <playerName> <packageName> <time> <timeUnit:d/h/m> \\n&7 - Give player package some time. (Time accumulation.) \\n&7 timeUnit: d=day, h=hour, m=minute");
|
||||
|
@ -14,6 +14,7 @@ public class PluginCfg extends PluginConfig {
|
||||
public static String PLUGIN_PREFIX;
|
||||
public static boolean IS_METRICS = true;
|
||||
public static boolean IS_DEBUG = false;
|
||||
public static boolean TAG_SYSTEM = false;
|
||||
public static String LANG;
|
||||
public static boolean USE_MYSQL = false;
|
||||
public static String SQL_SERVER_ID;
|
||||
@ -36,6 +37,7 @@ public class PluginCfg extends PluginConfig {
|
||||
PLUGIN_PREFIX = setGetDefault("pluginPrefix", "&b[" + pm.PLUGIN_NAME + "] ") + "&r";
|
||||
IS_DEBUG = setGetDefault("debug", false);
|
||||
IS_METRICS = setGetDefault("metrics", true);
|
||||
TAG_SYSTEM = setGetDefault("tagSystem", false);
|
||||
LANG = setGetDefault("lang", "en");
|
||||
USE_MYSQL = setGetDefault("mysql.enable", false);
|
||||
SQL_SERVER_ID = setGetDefault("mysql.serverId", "default");
|
||||
|
169
src/main/gg/frog/mc/permissionstime/config/TagNameCfg.java
Normal file
169
src/main/gg/frog/mc/permissionstime/config/TagNameCfg.java
Normal file
@ -0,0 +1,169 @@
|
||||
package gg.frog.mc.permissionstime.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.model.cfg.PlayerTagBean;
|
||||
import gg.frog.mc.permissionstime.model.cfg.TagPackageBean;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
import gg.frog.mc.permissionstime.utils.config.PluginConfig;
|
||||
import gg.frog.mc.permissionstime.utils.nms.ItemUtil;
|
||||
|
||||
public class TagNameCfg extends PluginConfig {
|
||||
|
||||
public static String DEFAULT_NAMECOLOR = null;
|
||||
public static String DEFAULT_PREFIX = null;
|
||||
public static String DEFAULT_SUFFIX = null;
|
||||
public static Map<String, TagPackageBean> PACKAGES = new ConcurrentHashMap<>();
|
||||
|
||||
public static Map<String, List<ItemStack>> NAMECOLOR_ITEMS = new ConcurrentHashMap<>();
|
||||
public static Map<String, List<ItemStack>> PREFIX_ITEMS = new ConcurrentHashMap<>();
|
||||
public static Map<String, List<ItemStack>> SUFFIX_ITEMS = new ConcurrentHashMap<>();
|
||||
|
||||
public static Map<String, List<String>> NAMECOLOR_PERMISSIONS = new ConcurrentHashMap<>();
|
||||
public static Map<String, List<String>> PREFIX_PERMISSIONS = new ConcurrentHashMap<>();
|
||||
public static Map<String, List<String>> SUFFIX_PERMISSIONS = new ConcurrentHashMap<>();
|
||||
|
||||
public static Map<String, PlayerTagBean> PLAYER_TAG = new ConcurrentHashMap<>();
|
||||
|
||||
public enum TagType {
|
||||
NAMECOLOR_TYPE, PREFIX_TYPE, SUFFIX_TYPE
|
||||
}
|
||||
|
||||
public TagNameCfg(String fileName, PluginMain pm) {
|
||||
super(fileName, pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadToDo() {
|
||||
DEFAULT_NAMECOLOR = setGetDefault("defaultNamecolor", "");
|
||||
DEFAULT_PREFIX = setGetDefault("defaultPrefix", "");
|
||||
DEFAULT_SUFFIX = setGetDefault("defaultSuffix", "");
|
||||
PACKAGES = getObjMap("packages", TagPackageBean.class);
|
||||
saveObj("packages", PACKAGES);
|
||||
if (PluginCfg.IS_DEBUG) {
|
||||
System.out.println("defaultNamecolor:" + DEFAULT_NAMECOLOR);
|
||||
System.out.println("defaultPrefix:" + DEFAULT_PREFIX);
|
||||
System.out.println("defaultSuffix:" + DEFAULT_SUFFIX);
|
||||
for (Entry<String, TagPackageBean> p : PACKAGES.entrySet()) {
|
||||
System.out.println(p.getKey() + ":" + p.getValue());
|
||||
}
|
||||
}
|
||||
NAMECOLOR_ITEMS.clear();
|
||||
PREFIX_ITEMS.clear();
|
||||
SUFFIX_ITEMS.clear();
|
||||
|
||||
NAMECOLOR_PERMISSIONS.clear();
|
||||
PREFIX_PERMISSIONS.clear();
|
||||
SUFFIX_PERMISSIONS.clear();
|
||||
|
||||
for (Entry<String, TagPackageBean> e : PACKAGES.entrySet()) {
|
||||
List<ItemStack> items = getTagItem(TagType.NAMECOLOR_TYPE, e.getValue());
|
||||
if (NAMECOLOR_ITEMS.containsKey(e.getValue().getPermissions())) {
|
||||
NAMECOLOR_ITEMS.get(e.getValue().getPermissions()).addAll(items);
|
||||
} else {
|
||||
NAMECOLOR_ITEMS.put(e.getValue().getPermissions(), items);
|
||||
}
|
||||
items = getTagItem(TagType.PREFIX_TYPE, e.getValue());
|
||||
if (PREFIX_ITEMS.containsKey(e.getValue().getPermissions())) {
|
||||
PREFIX_ITEMS.get(e.getValue().getPermissions()).addAll(items);
|
||||
} else {
|
||||
PREFIX_ITEMS.put(e.getValue().getPermissions(), items);
|
||||
}
|
||||
items = getTagItem(TagType.SUFFIX_TYPE, e.getValue());
|
||||
if (SUFFIX_ITEMS.containsKey(e.getValue().getPermissions())) {
|
||||
SUFFIX_ITEMS.get(e.getValue().getPermissions()).addAll(items);
|
||||
} else {
|
||||
SUFFIX_ITEMS.put(e.getValue().getPermissions(), items);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<ItemStack> getTagItem(TagType tagType, TagPackageBean tpb) {
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
if (tpb != null) {
|
||||
List<String> tags = null;
|
||||
String itemDisplayName = "";
|
||||
Map<String, List<String>> tagPermissions = null;
|
||||
if (tagType == TagType.NAMECOLOR_TYPE) {
|
||||
tags = tpb.getNamecolor();
|
||||
itemDisplayName = "&6&l昵称效果 &r";
|
||||
tagPermissions = NAMECOLOR_PERMISSIONS;
|
||||
} else if (tagType == TagType.PREFIX_TYPE) {
|
||||
tags = tpb.getPrefix();
|
||||
itemDisplayName = "&6&l昵称前缀 &r";
|
||||
tagPermissions = PREFIX_PERMISSIONS;
|
||||
} else if (tagType == TagType.SUFFIX_TYPE) {
|
||||
tags = tpb.getSuffix();
|
||||
itemDisplayName = "&6&l昵称后缀 &r";
|
||||
tagPermissions = SUFFIX_PERMISSIONS;
|
||||
}
|
||||
if (tags != null) {
|
||||
for (String tag : tags) {
|
||||
String[] args = tag.split(":");
|
||||
tag = args[0];
|
||||
Material type = null;
|
||||
int exid = 0;
|
||||
String skullOwner = null;
|
||||
if (args.length > 1) {
|
||||
type = Material.getMaterial(args[1].toUpperCase(Locale.ENGLISH));
|
||||
if (type == null) {
|
||||
int id = Integer.parseInt(args[1]);
|
||||
type = Material.getMaterial(id);
|
||||
}
|
||||
if (args.length > 2) {
|
||||
try {
|
||||
exid = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
if (Material.SKULL_ITEM.equals(type)) {
|
||||
exid = 3;
|
||||
skullOwner = args[2];
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
type = Material.getMaterial("NAME_TAG");
|
||||
}
|
||||
if (type != null) {
|
||||
ItemStack item = new ItemStack(type, 1, (short) 0, (byte) exid);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(StrUtil.messageFormat(itemDisplayName + tag));
|
||||
List<String> lores = new ArrayList<String>();
|
||||
lores.add("");
|
||||
lores.add("");// 效果展示
|
||||
lores.add("");
|
||||
lores.add(StrUtil.messageFormat(tpb.getDescription()));// 描述
|
||||
lores.add("");
|
||||
lores.add(tag);// 称号
|
||||
meta.setLore(lores);
|
||||
item.setItemMeta(meta);
|
||||
if (skullOwner != null) {
|
||||
item = ItemUtil.addSkullOwner(item, skullOwner);
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
if (!tagPermissions.containsKey(tag)) {
|
||||
tagPermissions.put(tag, new ArrayList<>());
|
||||
}
|
||||
tagPermissions.get(tag).add(tpb.getPermissions());
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ public class PlayerPermissionShow {
|
||||
if (pdbList.size() > 0) {
|
||||
inventory = Bukkit.createInventory(null,
|
||||
(pdbList.size() % 9 == 0 ? pdbList.size() : (pdbList.size() / 9 + 1) * 9),
|
||||
StrUtil.messageFormat(LangCfg.INVENTORY_NAME + "&r&5&9&2&0&r"));
|
||||
StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "&r&5&9&2&0&r"));
|
||||
for (PlayerDataBean pdb : pdbList) {
|
||||
PermissionPackageBean ppb = PackagesCfg.PACKAGES.get(pdb.getPackageName());
|
||||
if (ppb != null && pdb.getGlobal() == ppb.getGlobal()) {
|
||||
|
60
src/main/gg/frog/mc/permissionstime/gui/PlayerTagShow.java
Normal file
60
src/main/gg/frog/mc/permissionstime/gui/PlayerTagShow.java
Normal file
@ -0,0 +1,60 @@
|
||||
package gg.frog.mc.permissionstime.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
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.model.cfg.PlayerTagBean;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
|
||||
public class PlayerTagShow {
|
||||
|
||||
public static void show(Player p, TagType tagType, List<ItemStack> itemList) {
|
||||
Inventory inventory = null;
|
||||
int size = 0;
|
||||
if (itemList.size() > 0) {
|
||||
inventory = Bukkit.createInventory(null,
|
||||
(itemList.size() % 9 == 0 ? itemList.size() : (itemList.size() / 9 + 1) * 9),
|
||||
StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "&r&5&9&2&0&r"));
|
||||
String uuid = p.getUniqueId().toString();
|
||||
PlayerTagBean playerTag = null;
|
||||
if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) {
|
||||
playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
|
||||
playerTag = playerTag.clone();
|
||||
if(playerTag != null) {
|
||||
for (ItemStack item : itemList) {
|
||||
ItemStack tItem = item.clone();
|
||||
ItemMeta meta = tItem.getItemMeta();
|
||||
List<String> lores = meta.getLore();
|
||||
String tag = lores.get(5);
|
||||
if(tagType == TagType.NAMECOLOR_TYPE) {
|
||||
playerTag.setNamecolor(tag);
|
||||
}else if(tagType == TagType.PREFIX_TYPE) {
|
||||
playerTag.setPrefix(tag);
|
||||
}else if(tagType == TagType.SUFFIX_TYPE) {
|
||||
playerTag.setSuffix(tag);
|
||||
}
|
||||
lores.set(1,"效果展示: "+playerTag.getDisplayNameStr(p));
|
||||
meta.setLore(lores);
|
||||
tItem.setItemMeta(meta);
|
||||
inventory.addItem(tItem);
|
||||
size++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inventory != null && size > 0) {
|
||||
p.openInventory(inventory);
|
||||
} else {
|
||||
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_DATA));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package gg.frog.mc.permissionstime.listener;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -13,59 +15,102 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
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.model.cfg.PermissionPackageBean;
|
||||
import gg.frog.mc.permissionstime.model.cfg.PlayerTagBean;
|
||||
import gg.frog.mc.permissionstime.model.db.PlayerDataBean;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
|
||||
public class MainListener implements Listener {
|
||||
|
||||
private PluginMain pm;
|
||||
private PluginMain pm;
|
||||
|
||||
public MainListener(PluginMain pm) {
|
||||
this.pm = pm;
|
||||
}
|
||||
public MainListener(PluginMain pm) {
|
||||
this.pm = pm;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onJoin(PlayerLoginEvent event) {
|
||||
try {
|
||||
List<PlayerDataBean> pdbList = pm.getSqlManager().getTime(event.getPlayer().getUniqueId().toString());
|
||||
PermissionPackageBean.reloadPlayerPermissions(event.getPlayer(), pdbList, pm, false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
event.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onJoin(PlayerLoginEvent event) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<PlayerDataBean> pdbList = pm.getSqlManager().getTime(event.getPlayer().getUniqueId().toString());
|
||||
PermissionPackageBean.reloadPlayerPermissions(event.getPlayer(), pdbList, pm, false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
event.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
|
||||
}
|
||||
if (PluginCfg.TAG_SYSTEM) {
|
||||
String uuid = event.getPlayer().getUniqueId().toString();
|
||||
PlayerTagBean playerTag = null;
|
||||
if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) {
|
||||
playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
|
||||
playerTag.setPlayerDisplayName(event.getPlayer());
|
||||
} else {
|
||||
playerTag = new PlayerTagBean("playerTag/" + uuid + ".yml", pm);
|
||||
playerTag.setPlayerDisplayName(event.getPlayer(), true);
|
||||
}
|
||||
TagNameCfg.PLAYER_TAG.put(uuid, playerTag);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PermissionPackageBean.delPlayerAllPermissions(event.getPlayer(), pm);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PermissionPackageBean.delPlayerAllPermissions(event.getPlayer(), pm);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void onKick(PlayerKickEvent event) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PermissionPackageBean.delPlayerAllPermissions(event.getPlayer(), pm);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
public void onKick(PlayerKickEvent event) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PermissionPackageBean.delPlayerAllPermissions(event.getPlayer(), pm);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerClick(InventoryClickEvent event) {
|
||||
if (StrUtil.messageFormat(LangCfg.INVENTORY_NAME + "&r&5&9&2&0&r").equals(event.getInventory().getName())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerClick(InventoryClickEvent event) {
|
||||
if (StrUtil.messageFormat(LangCfg.INVENTORY_NAME + "&r&5&9&2&0&r").equals(event.getInventory().getName())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "&r&5&9&2&0&r").equals(event.getInventory().getName())) {
|
||||
OfflinePlayer player = this.pm.getOfflinePlayer(event.getWhoClicked().getName());
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (TagNameCfg.PLAYER_TAG.containsKey(uuid.toString()) && event.getCurrentItem() != null) {
|
||||
List<String> lores = event.getCurrentItem().getItemMeta().getLore();
|
||||
if (lores.size() == 6) {
|
||||
String itemName = event.getCurrentItem().getItemMeta().getDisplayName();
|
||||
PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid.toString());
|
||||
if (itemName.startsWith(StrUtil.messageFormat("&6&l昵称效果 &r"))) {
|
||||
playerTag.setNamecolor(lores.get(5));
|
||||
} else if (itemName.startsWith(StrUtil.messageFormat("&6&l昵称前缀 &r"))) {
|
||||
playerTag.setPrefix(lores.get(5));
|
||||
} else if (itemName.startsWith(StrUtil.messageFormat("&6&l昵称后缀 &r"))) {
|
||||
playerTag.setSuffix(lores.get(5));
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
playerTag.setPlayerDisplayName(player.getPlayer(), true);
|
||||
playerTag.saveConfig();
|
||||
event.getWhoClicked().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TAG_SET_SUCCESS));
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,9 +150,7 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PermissionPackageBean [displayName=" + displayName + ", id=" + id + ", type=" + type + ", glowing="
|
||||
+ glowing + ", lores=" + lores + ", global=" + global + ", permissions=" + permissions + ", groups="
|
||||
+ groups + ", expireCommands=" + expireCommands + "]";
|
||||
return "PermissionPackageBean [displayName=" + displayName + ", id=" + id + ", type=" + type + ", glowing=" + glowing + ", lores=" + lores + ", global=" + global + ", permissions=" + permissions + ", groups=" + groups + ", expireCommands=" + expireCommands + "]";
|
||||
}
|
||||
|
||||
private void givePlayer(OfflinePlayer player, Server server, Permission permission) {
|
||||
@ -227,8 +225,7 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
reloadPlayerPermissions(player, pdbList, plugin, true);
|
||||
}
|
||||
|
||||
public static void reloadPlayerPermissions(OfflinePlayer player, List<PlayerDataBean> pdbList, PluginMain plugin,
|
||||
boolean async) {
|
||||
public static void reloadPlayerPermissions(OfflinePlayer player, List<PlayerDataBean> pdbList, PluginMain plugin, boolean async) {
|
||||
long delay = -1;
|
||||
long now = new Date().getTime();
|
||||
PermissionPackageBean addPpb = new PermissionPackageBean();
|
||||
@ -262,8 +259,7 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
addPpb.givePlayer(player, plugin.getServer(), plugin.getPermission());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
player.getPlayer().sendMessage(
|
||||
StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
|
||||
player.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -308,25 +304,21 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
for (PlayerDataBean playerData : playerDataList) {
|
||||
if (playerData.getExpire() < now) {
|
||||
PermissionPackageBean packageBean = PackagesCfg.PACKAGES.get(playerData.getPackageName());
|
||||
if ((packageBean == null && !playerData.getGlobal())
|
||||
|| (packageBean != null && playerData.getGlobal() == packageBean.getGlobal())) {
|
||||
if ((packageBean == null && !playerData.getGlobal()) || (packageBean != null && playerData.getGlobal() == packageBean.getGlobal())) {
|
||||
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Player p = player.getPlayer();
|
||||
if (p != null) {
|
||||
p.sendMessage(
|
||||
StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_IS_EXPIRATION_DATE,
|
||||
packageBean != null ? packageBean.getDisplayName()
|
||||
: LangCfg.MSG_UNKNOWN_PACKAGE,
|
||||
playerData.getPackageName()));
|
||||
for (String commands : packageBean.getExpireCommands()) {
|
||||
try {
|
||||
commands = StrUtil.messageFormat(player.getPlayer(), commands);
|
||||
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(),
|
||||
commands);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_IS_EXPIRATION_DATE, packageBean != null ? packageBean.getDisplayName() : LangCfg.MSG_UNKNOWN_PACKAGE, playerData.getPackageName()));
|
||||
if(packageBean !=null) {
|
||||
for (String commands : packageBean.getExpireCommands()) {
|
||||
try {
|
||||
commands = StrUtil.messageFormat(player.getPlayer(), commands);
|
||||
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commands);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
191
src/main/gg/frog/mc/permissionstime/model/cfg/PlayerTagBean.java
Normal file
191
src/main/gg/frog/mc/permissionstime/model/cfg/PlayerTagBean.java
Normal file
@ -0,0 +1,191 @@
|
||||
package gg.frog.mc.permissionstime.model.cfg;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||
import gg.frog.mc.permissionstime.config.TagNameCfg;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
import gg.frog.mc.permissionstime.utils.config.IConfigBean;
|
||||
import gg.frog.mc.permissionstime.utils.config.PluginConfig;
|
||||
|
||||
/**
|
||||
* 玩家标签包实体类
|
||||
*
|
||||
* @author QiaoPengyu
|
||||
*
|
||||
*/
|
||||
public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneable {
|
||||
|
||||
// 名称颜色
|
||||
private String namecolor;
|
||||
// 前缀
|
||||
private String prefix;
|
||||
// 后缀
|
||||
private String suffix;
|
||||
|
||||
public PlayerTagBean(String fileName, PluginMain pm) {
|
||||
super(fileName, pm);
|
||||
if (PluginCfg.IS_DEBUG) {
|
||||
System.out.println("Player Tag File:" + fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadToDo() {
|
||||
namecolor = getConfig().getString("namecolor", TagNameCfg.DEFAULT_NAMECOLOR);
|
||||
prefix = getConfig().getString("prefix", TagNameCfg.DEFAULT_PREFIX);
|
||||
suffix = getConfig().getString("suffix", TagNameCfg.DEFAULT_SUFFIX);
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
getConfig().set("namecolor", namecolor);
|
||||
getConfig().set("prefix", prefix);
|
||||
getConfig().set("suffix", suffix);
|
||||
super.saveConfig();
|
||||
}
|
||||
|
||||
public void setPlayerDisplayName(Player player) {
|
||||
setPlayerDisplayName(player, false);
|
||||
}
|
||||
|
||||
public void setPlayerDisplayName(Player player, boolean forceSet) {
|
||||
PlayerTagBean playerTag = this;
|
||||
pm.getServer().getScheduler().runTask(pm, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean namecolor_flag = true;
|
||||
boolean prefix_flag = true;
|
||||
boolean suffix_flag = true;
|
||||
if (!(namecolor.equals(TagNameCfg.DEFAULT_NAMECOLOR) && prefix.equals(TagNameCfg.DEFAULT_PREFIX) && suffix.equals(TagNameCfg.DEFAULT_SUFFIX))) {
|
||||
if (TagNameCfg.NAMECOLOR_PERMISSIONS.containsKey(namecolor)) {
|
||||
for (String p : TagNameCfg.NAMECOLOR_PERMISSIONS.get(namecolor)) {
|
||||
if (p == null || p.length() == 0 || player.hasPermission(p)) {
|
||||
namecolor_flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (namecolor_flag) {
|
||||
namecolor = TagNameCfg.DEFAULT_NAMECOLOR;
|
||||
}
|
||||
if (TagNameCfg.PREFIX_PERMISSIONS.containsKey(prefix)) {
|
||||
for (String p : TagNameCfg.PREFIX_PERMISSIONS.get(prefix)) {
|
||||
if (p == null || p.length() == 0 || player.hasPermission(p)) {
|
||||
prefix_flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prefix_flag) {
|
||||
prefix = TagNameCfg.DEFAULT_PREFIX;
|
||||
}
|
||||
if (TagNameCfg.SUFFIX_PERMISSIONS.containsKey(suffix)) {
|
||||
for (String p : TagNameCfg.SUFFIX_PERMISSIONS.get(suffix)) {
|
||||
if (p == null || p.length() == 0 || player.hasPermission(p)) {
|
||||
suffix_flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (suffix_flag) {
|
||||
suffix = TagNameCfg.DEFAULT_SUFFIX;
|
||||
}
|
||||
}
|
||||
if (forceSet || namecolor_flag || prefix_flag || suffix_flag) {
|
||||
Scoreboard scoreboard = pm.getServer().getScoreboardManager().getNewScoreboard();
|
||||
Team team = scoreboard.getTeam(player.getName());
|
||||
if (team == null) {
|
||||
team = scoreboard.registerNewTeam(player.getName());
|
||||
}
|
||||
team.setPrefix(StrUtil.messageFormat(player, "&r" + prefix + "&r" + namecolor + "&r"));
|
||||
team.setSuffix(StrUtil.messageFormat(player, "&r" + suffix + "&r"));
|
||||
team.addEntry(player.getName());
|
||||
player.setScoreboard(scoreboard);
|
||||
List<World> worlds = pm.getServer().getWorlds();
|
||||
for (World world : worlds) {
|
||||
pm.getChat().setPlayerInfoString(world.getName(), player, "prefix", StrUtil.messageFormat(player, "&r" + prefix + "&r" + namecolor + "&r"));
|
||||
pm.getChat().setPlayerInfoString(world.getName(), player, "suffix", StrUtil.messageFormat(player, "&r" + suffix + "&r"));
|
||||
}
|
||||
player.setDisplayName(getDisplayNameStr(player));
|
||||
if (PluginCfg.IS_DEBUG) {
|
||||
System.out.println("PlayerTagBean:" + playerTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getDisplayNameStr(Player player) {
|
||||
return StrUtil.messageFormat(player, prefix + namecolor + player.getName() + suffix + "&r");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerTagBean clone() {
|
||||
PlayerTagBean t = null;
|
||||
try {
|
||||
t = (PlayerTagBean) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public String getNamecolor() {
|
||||
return namecolor;
|
||||
}
|
||||
|
||||
public void setNamecolor(String namecolor) {
|
||||
this.namecolor = namecolor;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getSuffix() {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
public void setSuffix(String suffix) {
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlConfiguration toConfig() {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
config.set("namecolor", namecolor);
|
||||
config.set("prefix", prefix);
|
||||
config.set("suffix", suffix);
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toConfigBean(MemorySection config) {
|
||||
namecolor = config.getString("namecolor");
|
||||
prefix = config.getString("prefix");
|
||||
suffix = config.getString("suffix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PlayerTagBean [namecolor=" + namecolor + ", prefix=" + prefix + ", suffix=" + suffix + "]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package gg.frog.mc.permissionstime.model.cfg;
|
||||
|
||||
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 TagPackageBean implements IConfigBean {
|
||||
|
||||
//所需权限
|
||||
private String permissions;
|
||||
//名称颜色
|
||||
private List<String> namecolor = new ArrayList<>();
|
||||
//前缀
|
||||
private List<String> prefix = new ArrayList<>();
|
||||
//后缀
|
||||
private List<String> suffix = new ArrayList<>();
|
||||
//说明
|
||||
private String description;
|
||||
|
||||
public String getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(String permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public List<String> getNamecolor() {
|
||||
return namecolor;
|
||||
}
|
||||
|
||||
public void setNamecolor(List<String> namecolor) {
|
||||
this.namecolor = namecolor;
|
||||
}
|
||||
|
||||
public List<String> getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(List<String> prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public List<String> getSuffix() {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
public void setSuffix(List<String> suffix) {
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlConfiguration toConfig() {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
config.set("permissions", permissions);
|
||||
config.set("namecolor", namecolor);
|
||||
config.set("prefix", prefix);
|
||||
config.set("suffix", suffix);
|
||||
config.set("description", description);
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toConfigBean(MemorySection config) {
|
||||
permissions = config.getString("permissions");
|
||||
namecolor = config.getStringList("namecolor");
|
||||
prefix = config.getStringList("prefix");
|
||||
suffix = config.getStringList("suffix");
|
||||
description = config.getString("description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PermissionPackageBean [permissions=" + permissions + ", namecolor=" + namecolor + ", prefix=" + prefix + ", suffix="
|
||||
+ suffix + ", description=" + description + "]";
|
||||
}
|
||||
}
|
@ -7,6 +7,9 @@ debug: false
|
||||
# 是否同意插件上传统计信息.
|
||||
# Whether or not you agree with the plugin to upload statistics.
|
||||
metrics: true
|
||||
# 开启称号系统.
|
||||
# Use prefix system.
|
||||
tagSystem: false
|
||||
# 语言文件名称 在'lang'文件夹内.
|
||||
# Language file name.
|
||||
lang: en
|
||||
@ -14,7 +17,7 @@ lang: en
|
||||
# Database settings.
|
||||
mysql:
|
||||
# 是否使用MySQL数据库.
|
||||
# Whether to use the MySQL database.
|
||||
# Use the MySQL database?
|
||||
enable: false
|
||||
# 服务器唯一标识, 用来区分权限是哪个服务器的.
|
||||
# 想要权限跨服,serverId必须一致.
|
||||
|
@ -1,9 +1,12 @@
|
||||
inventoryName: '&4===Permissions Packages==='
|
||||
tagInventoryName: '&4===Tag Packages==='
|
||||
expirationTime: '&4Expiration date: {0}'
|
||||
leftTime: '&4Left time: About {0}{1} {2}{3} {4}{5}'
|
||||
timeUnitD: 'day(s)'
|
||||
timeUnitH: 'hour(s)'
|
||||
timeUnitM: 'minute(s)'
|
||||
timeForever: 'Forever'
|
||||
tag: 'Tag/Prefix'
|
||||
msg:
|
||||
parameterMismatch: '&4Parameter mismatch.'
|
||||
timeParameterIncorrect: '&4The number of time is incorrect. Please enter a nonzero integer.'
|
||||
@ -34,9 +37,12 @@ msg:
|
||||
expirationDate: '{0}packages: {1}({2}), Expiration date: {3}, {4}'
|
||||
unknownPackage: 'Unknown Packages'
|
||||
isExpirationDate: 'Your package: {0}({1})&r has expired.'
|
||||
funcDisabled: '{0} functionality disabled.'
|
||||
tagSetSuccess: '&2Tag Set Success.'
|
||||
cmd:
|
||||
help: '&6/{0} help \n&7 - Show commands.'
|
||||
me: '&6/{0} me \n&7 - View self package.'
|
||||
me: '&6/{0} me \n&7 - View your packages.'
|
||||
tag: '&6/{0} tag <c/p/s>\n&7 - View your color/prefix/suffix tags.'
|
||||
packages: '&6/{0} packages [packageName] \n&7 - View server packages.'
|
||||
get: '&6/{0} get <playerName> \n&7 - View player packages.'
|
||||
give: '&6/{0} give <playerName> <packageName> <time> <timeUnit:d/h/m> \n&7 - Give player package some time. (Time accumulation.) \n&7 timeUnit: d=day, h=hour, m=minute'
|
||||
|
@ -1,9 +1,12 @@
|
||||
inventoryName: '&4===权限仓库==='
|
||||
tagInventoryName: '&4===称号仓库==='
|
||||
expirationTime: '&4到期时间: {0}.'
|
||||
leftTime: '&4剩余时间: 大约 {0}{1} {2}{3} {4}{5}'
|
||||
timeUnitD: '天'
|
||||
timeUnitH: '小时'
|
||||
timeUnitM: '分钟'
|
||||
timeForever: '永久'
|
||||
tag: '标签/称号'
|
||||
msg:
|
||||
parameterMismatch: '&4参数不匹配.'
|
||||
timeParameterIncorrect: '&4时间参数不正确,请输入非零整数.'
|
||||
@ -34,9 +37,12 @@ msg:
|
||||
expirationDate: '{0}权限包: {1}({2}), 到期时间: {3}, {4}'
|
||||
unknownPackage: '未知权限包'
|
||||
isExpirationDate: '你的权限包: {0}({1})&r, 已到期.'
|
||||
funcDisabled: '&4{0} 功能已被禁用.'
|
||||
tagSetSuccess: '&2称号设置成功.'
|
||||
cmd:
|
||||
help: '&6/{0} help \n&7 - 显示所有命令.'
|
||||
me: '&6/{0} me \n&7 - 显示自己的权限包.'
|
||||
tag: '&6/{0} tag <c/p/s>\n&7 - 显示你的昵称颜色/称号前缀/称号后缀.'
|
||||
packages: '&6/{0} packages [权限包名] \n&7 - 查看服务器的(某个)权限包.'
|
||||
get: '&6/{0} get <玩家> \n&7 - 查看玩家的权限包.'
|
||||
give: '&6/{0} give <玩家> <权限包名> <时间> <单位:d或h或m> \n&7 - 给玩家一定时间的权限包. (时间累加.) \n&7 时间单位: d=天, h=小时, m=分钟'
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: PermissionsTime
|
||||
version: 0.3.3-SNAPSHOT
|
||||
version: 0.4.0-SNAPSHOT
|
||||
main: gg.frog.mc.permissionstime.PluginMain
|
||||
author: GeekFrog
|
||||
softdepend:
|
||||
@ -19,6 +19,7 @@ permissions:
|
||||
default: op
|
||||
children:
|
||||
permissionstime.me: true
|
||||
permissionstime.tag: true
|
||||
permissionstime.reload: true
|
||||
permissionstime.give: true
|
||||
permissionstime.set: true
|
||||
@ -27,7 +28,10 @@ permissions:
|
||||
permissionstime.removeall: true
|
||||
permissionstime.packages: true
|
||||
permissionstime.me:
|
||||
description: View himself package.
|
||||
description: View your packages.
|
||||
default: true
|
||||
permissionstime.tag:
|
||||
description: View your color/prefix/suffix tags.
|
||||
default: true
|
||||
permissionstime.reload:
|
||||
description: Reloads the config file.
|
||||
|
53
src/resources/tagNames.yml
Normal file
53
src/resources/tagNames.yml
Normal file
@ -0,0 +1,53 @@
|
||||
# 默认昵称样式.
|
||||
# Default Name Color.
|
||||
defaultNamecolor: '&6'
|
||||
# 默认前缀.
|
||||
# Default Prefix.
|
||||
defaultPrefix: ''
|
||||
# 默认后缀.
|
||||
# Default Suffix.
|
||||
defaultSuffix: ''
|
||||
packages:
|
||||
# 称号包名称.
|
||||
# Tag package name.
|
||||
example1:
|
||||
# 称号包描述,可以填写如何获得这些称号.
|
||||
# Tag package describes. You can type how to get these tag.
|
||||
description: '&4Tag package description.'
|
||||
# 称号包所需权限. 不需要权限请留空,输入 ''
|
||||
# Tag package needs permission. Keep null to make no permission.
|
||||
permissions: ''
|
||||
# 称号包所含的昵称样式.
|
||||
# Name Colors.
|
||||
namecolor:
|
||||
- '&3'
|
||||
- '&4:SKULL_ITEM:5'
|
||||
- '&5:SKULL_ITEM:MHF_Present1'
|
||||
# 称号包所含的昵称前缀.
|
||||
# Name prefix.
|
||||
prefix:
|
||||
- '&3[prefix]'
|
||||
- '&4[prefix]:1'
|
||||
# 称号包所含的昵称后缀.
|
||||
# Name suffix.
|
||||
suffix:
|
||||
- '&3[suffix]'
|
||||
- '&4[suffix]:1:6'
|
||||
vip:
|
||||
description: '&4VIP Tags.'
|
||||
permissions: 'player.vip'
|
||||
namecolor:
|
||||
- '&3&l'
|
||||
- '&4&n:SKULL_ITEM:5'
|
||||
- '&5&o:SKULL_ITEM:MHF_Present1'
|
||||
# 称号包所含的昵称前缀.
|
||||
# Name prefix.
|
||||
prefix:
|
||||
- '&3&l[prefix]'
|
||||
- '&4&n[prefix]:1'
|
||||
# 称号包所含的昵称后缀.
|
||||
# Name suffix.
|
||||
suffix:
|
||||
- '&3&o[suffix]'
|
||||
- '&4&l&n[suffix]:1:6'
|
||||
|
Loading…
Reference in New Issue
Block a user