1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-21 14:58:48 +00:00

完善称号功能

修复之前的BUG
This commit is contained in:
GeekFrog 2018-06-20 12:52:33 +08:00
parent 3a9169e30b
commit 6b5a1f5aa5
17 changed files with 503 additions and 337 deletions

View File

@ -1,11 +1,13 @@
name: PermissionsTime
version: 0.4.0-SNAPSHOT
main: gg.frog.mc.permissionstime.PluginMain
author: GeekFrog
author:
- GeekFrog
softdepend:
- SQLibrary
- Vault
- PlaceholderAPI
- HolographicDisplays
commands:
permissionstime:
description: Show all commands.

View File

@ -7,6 +7,28 @@ defaultPrefix: ''
# 默认后缀.
# Default Suffix.
defaultSuffix: ''
# 如果你有其他的插件来修改玩家的displayname, 请禁用此项或禁止其他插件修改. 比如Essentials插件.
# 如果安装了PlaceholderAPI 可以使用
# %pttag_fullname% %pttag_prefix% %pttag_suffix% 来显示displayname prefix+color suffix
# If you have other plugin, to modifies player displayname, please disable this.
changeDisplayname: true
# 使用HolographicDisplays显示称号
# use HolographicDisplays to show Tags
useHdPlugin: false
# 称号刷新周期(秒).
# 如果你你的称号使用了PlaceholderAPI请设置此项
# 推荐600秒以上. 设置-1则禁用刷新.
# Title refresh cycle (seconds).
# If you use Placeholder, please set.
# Recommend more than 600s. Set -1 to disable refresh.
refreshTagTime: -1
template:
lore:
- '&1-----------------'
- '&2效果展示: '
- '&3 %displayname%'
- '&4-----------------'
- '&5—— %description%'
packages:
# 称号包名称.
# Tag package name.

28
pom.xml
View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gg.frog.mc</groupId>
<artifactId>permissionstime</artifactId>
<version>0.4.0-SNAPSHOT</version>
<version>0.4.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PermissionsTime</name>
<description>支持跨服的权限限时插件</description>
@ -47,21 +47,21 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.9-R0.1-SNAPSHOT</version>
<version>1.12.2-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
@ -81,11 +81,11 @@
</dependency>
</dependencies>
<build>
<finalName>PermissionsTime-${project.version}</finalName>
<sourceDirectory>${basedir}/src/main</sourceDirectory>
<resources>
<resource>
<directory>src/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<targetPath>.</targetPath>
@ -97,10 +97,18 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<finalName>${project.name}-${project.version}</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
@ -118,7 +126,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>

View File

@ -37,7 +37,7 @@ public class PluginMain extends JavaPlugin {
private Permission permission = null;
public static boolean enabledHdPlugin;
public static boolean enabledPlaceholder;
private static Map<String, OfflinePlayer> playerMap = new ConcurrentHashMap<>();
private Map<String, OfflinePlayer> playerMap = new ConcurrentHashMap<>();
public PluginMain() {
PLUGIN_NAME = getDescription().getName();
@ -113,6 +113,10 @@ public class PluginMain extends JavaPlugin {
return permission;
}
public Map<String, OfflinePlayer> getPlayerMap() {
return playerMap;
}
private boolean checkPluginDepends() {
boolean needDepend = false;
for (String name : DEPEND_PLUGIN.split(",")) {

View File

@ -20,224 +20,216 @@ import gg.frog.mc.permissionstime.utils.StrUtil;
public class MainCommand implements CommandExecutor, TabCompleter {
private PluginMain pm;
private SqlManager sm;
private PluginMain pm;
private SqlManager sm;
public MainCommand(PluginMain pm) {
this.pm = pm;
this.sm = pm.getSqlManager();
}
public MainCommand(PluginMain pm) {
this.pm = pm;
this.sm = pm.getSqlManager();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if (commandLabel.equalsIgnoreCase(pm.PLUGIN_NAME_LOWER_CASE) || commandLabel.equalsIgnoreCase("pt")) {
boolean isPlayer = false;
if (sender instanceof Player) {
isPlayer = true;
}
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
getHelp(sender, isPlayer);
return true;
} else {
if (args[0].equalsIgnoreCase("reload")) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
if (isPlayer) {
Player player = (Player) sender;
if (sender.isOp() || player.hasPermission("permissionstime.reload")) {
for (Player p : pm.getServer().getOnlinePlayers()) {
InventoryView inventory = p.getOpenInventory();
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();
}
}
pm.getConfigManager().reloadConfig();
if (!sm.updateDatabase()) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Database exceptions."));
}
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_CONFIG_RELOADED));
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_CONFIG_RELOADED));
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION));
}
} else {
for (Player p : pm.getServer().getOnlinePlayers()) {
InventoryView inventory = p.getOpenInventory();
if (inventory != null) {
if (StrUtil.messageFormat(LangCfg.INVENTORY_NAME + "&r&5&9&2&0&r").equals(inventory.getTitle())) {
inventory.close();
}
}
}
pm.getConfigManager().reloadConfig();
if (!sm.updateDatabase()) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Database exceptions."));
}
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_CONFIG_RELOADED));
}
return true;
} else if (args[0].equalsIgnoreCase("me")) {
if (hasPermission(sender, isPlayer, "permissionstime.me")) {
MeCmd meCmd = new MeCmd(pm, sender, isPlayer, args);
new Thread(meCmd).start();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if (commandLabel.equalsIgnoreCase(pm.PLUGIN_NAME_LOWER_CASE) || commandLabel.equalsIgnoreCase("pt")) {
boolean isPlayer = false;
if (sender instanceof Player) {
isPlayer = true;
}
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
getHelp(sender, isPlayer);
return true;
} else {
if (args[0].equalsIgnoreCase("reload")) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
if (isPlayer) {
Player player = (Player) sender;
if (player.hasPermission("permissionstime.reload")) {
for (Player p : pm.getServer().getOnlinePlayers()) {
InventoryView inventory = p.getOpenInventory();
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();
}
}
pm.getConfigManager().reloadConfig();
if (!sm.updateDatabase()) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Database exceptions."));
}
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_CONFIG_RELOADED));
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_CONFIG_RELOADED));
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION));
}
} else {
for (Player p : pm.getServer().getOnlinePlayers()) {
InventoryView inventory = p.getOpenInventory();
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();
}
}
pm.getConfigManager().reloadConfig();
if (!sm.updateDatabase()) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Database exceptions."));
}
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_CONFIG_RELOADED));
}
return true;
} else if (args[0].equalsIgnoreCase("me")) {
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")) {
GiveCmd giveCmd = new GiveCmd(pm, sender, args);
new Thread(giveCmd).start();
}
} else if (args[0].equalsIgnoreCase("set")) {
if (hasPermission(sender, isPlayer, "permissionstime.set")) {
SetCmd setCmd = new SetCmd(pm, sender, args);
new Thread(setCmd).start();
}
} else if (args[0].equalsIgnoreCase("get")) {
if (hasPermission(sender, isPlayer, "permissionstime.get")) {
GetCmd getCmd = new GetCmd(pm, sender, args);
new Thread(getCmd).start();
}
} else if (args[0].equalsIgnoreCase("remove")) {
if (hasPermission(sender, isPlayer, "permissionstime.remove")) {
RemoveCmd removeCmd = new RemoveCmd(pm, sender, args);
new Thread(removeCmd).start();
}
} else if (args[0].equalsIgnoreCase("removeall")) {
if (hasPermission(sender, isPlayer, "permissionstime.removeall")) {
RemoveAllCmd removeAllCmd = new RemoveAllCmd(pm, sender, args);
new Thread(removeAllCmd).start();
}
} else if (args[0].equalsIgnoreCase("packages")) {
if (hasPermission(sender, isPlayer, "permissionstime.packages")) {
PackagesCmd packagesCmd = new PackagesCmd(pm, sender, args);
new Thread(packagesCmd).start();
}
} else {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_HELP, pm.PLUGIN_NAME_LOWER_CASE));
}
return true;
}
}
return false;
}
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")) {
GiveCmd giveCmd = new GiveCmd(pm, sender, args);
new Thread(giveCmd).start();
}
} else if (args[0].equalsIgnoreCase("set")) {
if (hasPermission(sender, isPlayer, "permissionstime.set")) {
SetCmd setCmd = new SetCmd(pm, sender, args);
new Thread(setCmd).start();
}
} else if (args[0].equalsIgnoreCase("get")) {
if (hasPermission(sender, isPlayer, "permissionstime.get")) {
GetCmd getCmd = new GetCmd(pm, sender, args);
new Thread(getCmd).start();
}
} else if (args[0].equalsIgnoreCase("remove")) {
if (hasPermission(sender, isPlayer, "permissionstime.remove")) {
RemoveCmd removeCmd = new RemoveCmd(pm, sender, args);
new Thread(removeCmd).start();
}
} else if (args[0].equalsIgnoreCase("removeall")) {
if (hasPermission(sender, isPlayer, "permissionstime.removeall")) {
RemoveAllCmd removeAllCmd = new RemoveAllCmd(pm, sender, args);
new Thread(removeAllCmd).start();
}
} else if (args[0].equalsIgnoreCase("packages")) {
if (hasPermission(sender, isPlayer, "permissionstime.packages")) {
PackagesCmd packagesCmd = new PackagesCmd(pm, sender, args);
new Thread(packagesCmd).start();
}
} else {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_HELP, pm.PLUGIN_NAME_LOWER_CASE));
}
return true;
}
}
return false;
}
private void getHelp(CommandSender sender, boolean isPlayer) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "\n&a===== " + pm.PLUGIN_NAME + " Version:" + pm.PLUGIN_VERSION + (pm.getDescription().getCommands().containsKey("pt") ? " Aliases:/pt" : "") + " ====="));
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));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".get")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GET, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVE, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVEALL, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_RELOAD, pm.PLUGIN_NAME_LOWER_CASE));
}
}
private void getHelp(CommandSender sender, boolean isPlayer) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "\n&a===== " + pm.PLUGIN_NAME + " Version:" + pm.PLUGIN_VERSION + (pm.getDescription().getCommands().containsKey("pt") ? " Aliases:/pt" : "") + " ====="));
if (isPlayer && (sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_ME, pm.PLUGIN_NAME_LOWER_CASE));
}
if (isPlayer && (sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_PACKAGES, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".get")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GET, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVE, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVEALL, pm.PLUGIN_NAME_LOWER_CASE));
}
if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_RELOAD, pm.PLUGIN_NAME_LOWER_CASE));
}
}
private boolean hasPermission(CommandSender sender, boolean isPlayer, String permissionPath) {
if (isPlayer) {
Player player = (Player) sender;
if (sender.isOp() || player.hasPermission(permissionPath)) {
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION));
return false;
}
}
return true;
}
private boolean hasPermission(CommandSender sender, boolean isPlayer, String permissionPath) {
if (isPlayer) {
Player player = (Player) sender;
if (player.hasPermission(permissionPath)) {
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION));
return false;
}
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> tipList = new ArrayList<String>();
boolean isPlayer = false;
if (sender instanceof Player) {
isPlayer = true;
}
if (args.length == 1) {
args[0] = args[0].toLowerCase(Locale.ENGLISH);
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");
}
if ("give".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give"))) {
tipList.add("give");
}
if ("set".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set"))) {
tipList.add("set");
}
if ("get".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".get"))) {
tipList.add("get");
}
if ("remove".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove"))) {
tipList.add("remove");
}
if ("removeall".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall"))) {
tipList.add("removeall");
}
if ("reload".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload"))) {
tipList.add("reload");
}
} else if (args.length == 2) {
args[0] = args[0].toLowerCase(Locale.ENGLISH);
args[1] = args[1].toLowerCase(Locale.ENGLISH);
if ("packages".equalsIgnoreCase(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) {
for (String name : PackagesCfg.PACKAGES.keySet()) {
if (name.startsWith(args[1])) {
tipList.add(name);
}
}
} 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);
args[2] = args[2].toLowerCase(Locale.ENGLISH);
if ("give".equalsIgnoreCase(args[0]) || "set".equalsIgnoreCase(args[0]) || "remove".equalsIgnoreCase(args[0])) {
for (String name : PackagesCfg.PACKAGES.keySet()) {
if (name.startsWith(args[2])) {
tipList.add(name);
}
}
}
}
return tipList;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> tipList = new ArrayList<String>();
boolean isPlayer = false;
if (sender instanceof Player) {
isPlayer = true;
}
if (args.length == 1) {
args[0] = args[0].toLowerCase(Locale.ENGLISH);
if ("me".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) {
tipList.add("me");
}
if ("tag".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) {
tipList.add("tag");
}
if ("packages".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages"))) {
tipList.add("packages");
}
if ("give".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give"))) {
tipList.add("give");
}
if ("set".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set"))) {
tipList.add("set");
}
if ("get".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".get"))) {
tipList.add("get");
}
if ("remove".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove"))) {
tipList.add("remove");
}
if ("removeall".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall"))) {
tipList.add("removeall");
}
if ("reload".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload"))) {
tipList.add("reload");
}
} else if (args.length == 2) {
args[0] = args[0].toLowerCase(Locale.ENGLISH);
args[1] = args[1].toLowerCase(Locale.ENGLISH);
if ("packages".equalsIgnoreCase(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) {
for (String name : PackagesCfg.PACKAGES.keySet()) {
if (name.startsWith(args[1])) {
tipList.add(name);
}
}
} else if ("tag".equalsIgnoreCase(args[0]) && (!isPlayer || 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);
args[2] = args[2].toLowerCase(Locale.ENGLISH);
if ("give".equalsIgnoreCase(args[0]) || "set".equalsIgnoreCase(args[0]) || "remove".equalsIgnoreCase(args[0])) {
for (String name : PackagesCfg.PACKAGES.keySet()) {
if (name.startsWith(args[2])) {
tipList.add(name);
}
}
}
}
return tipList;
}
}

View File

@ -6,7 +6,6 @@ import java.util.Map;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import gg.frog.mc.permissionstime.PluginMain;
@ -37,6 +36,7 @@ public class TagCmd implements Runnable {
if (args.length == 2) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
List<ItemStack> itemList = new ArrayList<ItemStack>();
List<ItemStack> disItemList = new ArrayList<ItemStack>();
TagType type = null;
Map<String, List<ItemStack>> p_i_map;
if ("c".equals(args[1])) {
@ -56,13 +56,12 @@ public class TagCmd implements Runnable {
for (String p : p_i_map.keySet()) {
if ("".equals(p) || sender.hasPermission(p)) {
itemList.addAll(p_i_map.get(p));
} else {
disItemList.addAll(p_i_map.get(p));
}
}
OfflinePlayer player = pm.getOfflinePlayer(sender.getName());
Player p = player.getPlayer();
if (p != null) {
PlayerTagShow.show(p, type, itemList);
}
PlayerTagShow.show(player, type, itemList, disItemList);
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE));

View File

@ -42,7 +42,7 @@ public class PackagesCfg extends PluginConfig {
PACKAGES_VERSION = setGetDefault("version", "1.00");
DEFAULT_GROUP = setGetDefault("defaultGroup", "Default");
PACKAGES = getObjMap("packages", PermissionPackageBean.class);
saveObj("packages", PACKAGES);
setObj("packages", PACKAGES);
if (PluginCfg.IS_DEBUG) {
System.out.println("packages vresion:" + PACKAGES_VERSION);
System.out.println("defaultGroup:" + DEFAULT_GROUP);

View File

@ -26,9 +26,11 @@ 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 boolean CHANGE_DISPLAYNAME = true;
public static boolean USE_HD_PLUGIN = false;
public static Integer REFRESH_TAG_TIME = null;
public static Map<String, TagPackageBean> PACKAGES = new ConcurrentHashMap<>();
public static List<String> TEMPLATE_LORE = null;
public static Map<String, List<ItemStack>> NAMECOLOR_ITEMS = new ConcurrentHashMap<>();
public static Map<String, List<ItemStack>> PREFIX_ITEMS = new ConcurrentHashMap<>();
@ -61,10 +63,13 @@ public class TagNameCfg extends PluginConfig {
DEFAULT_NAMECOLOR = setGetDefault("defaultNamecolor", "");
DEFAULT_PREFIX = setGetDefault("defaultPrefix", "");
DEFAULT_SUFFIX = setGetDefault("defaultSuffix", "");
CHANGE_DISPLAYNAME = setGetDefault("changeDisplayname", true);
USE_HD_PLUGIN = setGetDefault("useHdPlugin", false);
REFRESH_TAG_TIME = setGetDefault("refreshTagTime", -1);
PACKAGES = getObjMap("packages", TagPackageBean.class);
saveObj("packages", PACKAGES);
TEMPLATE_LORE = getConfig().getStringList("template.lore");
getConfig().set("template.lore", TEMPLATE_LORE);
setObj("packages", PACKAGES);
if (PluginCfg.IS_DEBUG) {
System.out.println("defaultNamecolor:" + DEFAULT_NAMECOLOR);
System.out.println("defaultPrefix:" + DEFAULT_PREFIX);
@ -73,6 +78,9 @@ public class TagNameCfg extends PluginConfig {
for (Entry<String, TagPackageBean> p : PACKAGES.entrySet()) {
System.out.println(p.getKey() + ":" + p.getValue());
}
for (String lore : TEMPLATE_LORE) {
System.out.println(lore);
}
}
NAMECOLOR_ITEMS.clear();
PREFIX_ITEMS.clear();
@ -82,8 +90,6 @@ public class TagNameCfg extends PluginConfig {
PREFIX_PERMISSIONS.clear();
SUFFIX_PERMISSIONS.clear();
PLAYER_TAG.clear();
for (Entry<String, TagPackageBean> e : PACKAGES.entrySet()) {
List<ItemStack> items = getTagItem(TagType.NAMECOLOR_TYPE, e.getValue());
if (NAMECOLOR_ITEMS.containsKey(e.getValue().getPermissions())) {
@ -104,7 +110,6 @@ public class TagNameCfg extends PluginConfig {
SUFFIX_ITEMS.put(e.getValue().getPermissions(), items);
}
}
if (task != null) {
task.cancel();
}
@ -133,15 +138,15 @@ public class TagNameCfg extends PluginConfig {
Map<String, List<String>> tagPermissions = null;
if (tagType == TagType.NAMECOLOR_TYPE) {
tags = tpb.getNamecolor();
itemDisplayName = "&6&l昵称效果 &r";
itemDisplayName = "&6&l昵称效果&r ";
tagPermissions = NAMECOLOR_PERMISSIONS;
} else if (tagType == TagType.PREFIX_TYPE) {
tags = tpb.getPrefix();
itemDisplayName = "&6&l昵称前缀 &r";
itemDisplayName = "&6&l昵称前缀&r ";
tagPermissions = PREFIX_PERMISSIONS;
} else if (tagType == TagType.SUFFIX_TYPE) {
tags = tpb.getSuffix();
itemDisplayName = "&6&l昵称后缀 &r";
itemDisplayName = "&6&l昵称后缀&r ";
tagPermissions = SUFFIX_PERMISSIONS;
}
if (tags != null) {
@ -176,13 +181,16 @@ public class TagNameCfg extends PluginConfig {
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);// 称号
List<String> lores = new ArrayList<>(TEMPLATE_LORE);
for (int i = 0; i < lores.size(); i++) {
if (lores.get(i).contains("%description%")) {
lores.set(i, StrUtil.messageFormat(lores.get(i).replaceAll("%description%", tpb.getDescription())));// 描述
} else {
lores.set(i, StrUtil.messageFormat(lores.get(i)));
}
}
lores.add("§8§k" + tpb.getPermissions());// 权限
lores.add("§8" + tag);// 称号
meta.setLore(lores);
item.setItemMeta(meta);
if (skullOwner != null) {

View File

@ -21,9 +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&r"));
for (PlayerDataBean pdb : pdbList) {
PermissionPackageBean ppb = PackagesCfg.PACKAGES.get(pdb.getPackageName());
if (ppb != null && pdb.getGlobal() == ppb.getGlobal()) {
@ -31,8 +29,7 @@ public class PlayerPermissionShow {
ItemStack tItem = item.clone();
ItemMeta meta = tItem.getItemMeta();
List<String> lores = meta.getLore();
lores.add(
StrUtil.messageFormat(LangCfg.EXPIRATION_TIME, StrUtil.timestampToString(pdb.getExpire())));
lores.add(StrUtil.messageFormat(LangCfg.EXPIRATION_TIME, StrUtil.timestampToString(pdb.getExpire())));
lores.add(StrUtil.getLeftTime(pdb.getExpire()));
meta.setLore(lores);
tItem.setItemMeta(meta);

View File

@ -14,46 +14,80 @@ import gg.frog.mc.permissionstime.config.TagNameCfg;
import gg.frog.mc.permissionstime.config.TagNameCfg.TagType;
import gg.frog.mc.permissionstime.model.PlayerTagBean;
import gg.frog.mc.permissionstime.utils.StrUtil;
import gg.frog.mc.permissionstime.utils.nms.ItemUtil;
public class PlayerTagShow {
public static void show(OfflinePlayer p, TagType tagType, List<ItemStack> itemList) {
public static void show(OfflinePlayer player, TagType tagType, List<ItemStack> itemList, List<ItemStack> disItemList) {
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();
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"));
String uuid = player.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) {
playerTag = playerTag.clone();
ItemStack tItem = item.clone();
ItemMeta meta = tItem.getItemMeta();
List<String> lores = meta.getLore();
String tag = lores.get(5);
String tag = lores.get(lores.size() - 1);
tag = tag.length() > 2 ? tag.substring(2) : "";
if (tagType == TagType.NAMECOLOR_TYPE) {
meta.setDisplayName(meta.getDisplayName() + p.getName());
meta.setDisplayName(meta.getDisplayName() + player.getName());
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.getPlayer()));
for (int i = 0; i < lores.size(); i++) {
if (lores.get(i).contains("%displayname%")) {
lores.set(i, lores.get(i).replaceAll("%displayname%", playerTag.getDisplayNameStr(player.getPlayer())));// 效果
}
}
meta.setLore(lores);
tItem.setItemMeta(meta);
inventory.addItem(tItem);
size++;
}
for (ItemStack item : disItemList) {
playerTag = playerTag.clone();
ItemStack tItem = item.clone();
ItemMeta meta = tItem.getItemMeta();
List<String> lores = meta.getLore();
String tag = lores.get(lores.size() - 1);
tag = tag.length() > 2 ? tag.substring(2) : "";
if (tagType == TagType.NAMECOLOR_TYPE) {
meta.setDisplayName("§6§l§m" + meta.getDisplayName().substring(4) + player.getName());
playerTag.setNamecolor(tag);
} else if (tagType == TagType.PREFIX_TYPE) {
meta.setDisplayName("§6§l§m" + meta.getDisplayName().substring(4));
playerTag.setPrefix(tag);
} else if (tagType == TagType.SUFFIX_TYPE) {
meta.setDisplayName("§6§l§m" + meta.getDisplayName().substring(4));
playerTag.setSuffix(tag);
}
for (int i = 0; i < lores.size(); i++) {
if (lores.get(i).contains("%displayname%")) {
lores.set(i, lores.get(i).replaceAll("%displayname%", playerTag.getDisplayNameStr(player.getPlayer())));// 效果
}
}
meta.setLore(lores);
tItem.setItemMeta(meta);
tItem = ItemUtil.addEnchantLight(tItem);
inventory.addItem(tItem);
size++;
}
}
}
}
if (inventory != null && size > 0) {
p.getPlayer().openInventory(inventory);
player.getPlayer().openInventory(inventory);
} else {
p.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_TAG_DATA));
player.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_TAG_DATA));
}
}
}

View File

@ -1,7 +1,6 @@
package gg.frog.mc.permissionstime.listener;
import java.util.List;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.EventHandler;
@ -10,6 +9,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import gg.frog.mc.permissionstime.PluginMain;
@ -49,19 +49,27 @@ public class MainListener implements Listener {
}).start();
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
new Thread(new Runnable() {
@Override
public void run() {
try {
PermissionPackageBean.delPlayerAllPermissions(event.getPlayer(), pm);
if (PluginCfg.TAG_SYSTEM && TagNameCfg.USE_HD_PLUGIN) {
String uuid = pm.getPlayerUUIDByName(event.getPlayer().getName());
PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
playerTag.delHologramsName();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
pm.getPlayerMap().remove(event.getPlayer().getName());
}
@EventHandler
public void onKick(PlayerKickEvent event) {
new Thread(new Runnable() {
@Override
@ -73,6 +81,18 @@ public class MainListener implements Listener {
}
}
}).start();
pm.getPlayerMap().remove(event.getPlayer().getName());
}
@EventHandler
public void onMove(PlayerMoveEvent event) {
if (PluginCfg.TAG_SYSTEM && TagNameCfg.USE_HD_PLUGIN) {
String uuid = this.pm.getPlayerUUIDByName(event.getPlayer().getName());
PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
if (playerTag != null) {
playerTag.moveHologramsName(event.getPlayer());
}
}
}
@EventHandler
@ -81,25 +101,34 @@ public class MainListener implements Listener {
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) {
if (event.getCurrentItem() != null && event.getCurrentItem().getItemMeta() != null && event.getCurrentItem().getItemMeta().hasLore()) {
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));
if (lores.size() > 1) {
String permissions = lores.get(lores.size() - 2);
permissions = permissions.length() > 4 ? permissions.substring(4) : "";
OfflinePlayer player = this.pm.getOfflinePlayer(event.getWhoClicked().getName());
String uuid = player.getUniqueId().toString();
if (permissions.length() == 0 || player.getPlayer().hasPermission(permissions)) {
if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) {
String itemName = event.getCurrentItem().getItemMeta().getDisplayName();
PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
if (itemName.startsWith("§6§l昵称效果§r ")) {
playerTag.setNamecolor(lores.get(lores.size() - 1).substring(2));
} else if (itemName.startsWith("§6§l昵称前缀§r ")) {
playerTag.setPrefix(lores.get(lores.size() - 1).substring(2));
} else if (itemName.startsWith("§6§l昵称后缀§r ")) {
playerTag.setSuffix(lores.get(lores.size() - 1).substring(2));
} else {
event.setCancelled(true);
return;
}
playerTag.setPlayerDisplayName(player.getPlayer(), true);
playerTag.saveConfig();
player.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TAG_SET_SUCCESS));
}
} else {
event.setCancelled(true);
player.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION));
}
playerTag.setPlayerDisplayName(player.getPlayer(), true);
playerTag.saveConfig();
event.getWhoClicked().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TAG_SET_SUCCESS));
}
}
event.setCancelled(true);

View File

@ -1,16 +1,21 @@
package gg.frog.mc.permissionstime.model;
import org.bukkit.Location;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team;
import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
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;
import gg.frog.mc.permissionstime.utils.nms.NMSUtil;
/**
* 玩家标签包实体类
@ -28,12 +33,19 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
private String suffix;
// 当前显示的名称
private String displayName;
// 当前显示的前缀
private String displayPrefix;
// 当前显示的后缀
private String displaySuffix;
// 玩家所在队伍
private Team team;
// 不可见的队伍名
private String invisibleName;
// hd
private Hologram holograms;
public PlayerTagBean(String fileName, PluginMain pm) {
super(fileName, pm);
if (PluginCfg.IS_DEBUG) {
System.out.println("Player Tag File:" + fileName);
}
}
@Override
@ -115,59 +127,86 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
}
}
if (forceSet || namecolor_flag || prefix_flag || suffix_flag) {
displayName = getDisplayNameStr(player);
player.setDisplayName(displayName);
displayPrefix = StrUtil.messageFormat(player, prefix + "&r" + namecolor);
displaySuffix = StrUtil.messageFormat(player, "&r" + suffix);
displayName = "§r" + displayPrefix + player.getName() + displaySuffix + "§r";
if (TagNameCfg.CHANGE_DISPLAYNAME) {
player.setDisplayName(displayName);
}
if (PluginCfg.IS_DEBUG) {
System.out.println("PlayerTagBean:" + playerTag);
}
if (!TagNameCfg.USE_HD_PLUGIN) {
try {
if (TagNameCfg.scoreboard == null) {
TagNameCfg.scoreboard = pm.getServer().getScoreboardManager().getNewScoreboard();
}
Team team = TagNameCfg.scoreboard.getTeam(player.getName());
try {
if (TagNameCfg.scoreboard == null) {
TagNameCfg.scoreboard = pm.getServer().getScoreboardManager().getNewScoreboard();
}
if (invisibleName == null) {
invisibleName = String.valueOf(TagNameCfg.scoreboard.getTeams().size() + 1).replaceAll("", "§");
}
if (!TagNameCfg.USE_HD_PLUGIN) {
team = TagNameCfg.scoreboard.getTeam(player.getName());
if (team == null) {
team = TagNameCfg.scoreboard.registerNewTeam(player.getName());
}
String teamPrefix = StrUtil.messageFormat(player, prefix + "&r" + namecolor);
if (PluginCfg.IS_DEBUG)
System.out.println(teamPrefix);
teamPrefix = teamPrefix.length() > 16 ? (teamPrefix.substring(0, 7) + ".." + teamPrefix.substring(teamPrefix.length() - 7)) : teamPrefix;
if (PluginCfg.IS_DEBUG)
System.out.println(teamPrefix);
String teamPrefix = displayPrefix.length() > 16 ? (displayPrefix.substring(0, 7) + ".." + displayPrefix.substring(displayPrefix.length() - 7)) : displayPrefix;
team.setPrefix(teamPrefix);
String teamSuffix = StrUtil.messageFormat(player, "&r" + suffix);
if (PluginCfg.IS_DEBUG)
System.out.println(teamSuffix);
teamSuffix = teamSuffix.length() > 16 ? (teamSuffix.substring(0, 7) + ".." + teamSuffix.substring(teamSuffix.length() - 7)) : teamSuffix;
if (PluginCfg.IS_DEBUG) {
System.out.println(teamSuffix);
}
String teamSuffix = displaySuffix.length() > 16 ? (displaySuffix.substring(0, 7) + ".." + displaySuffix.substring(displaySuffix.length() - 7)) : displaySuffix;
team.setSuffix(teamSuffix);
team.addEntry(player.getName());
player.setScoreboard(TagNameCfg.scoreboard);
if (PluginCfg.IS_DEBUG)
for (Team t : TagNameCfg.scoreboard.getTeams()) {
System.out.println(t.getPrefix());
System.out.println(t.getSuffix());
for (String e : t.getEntries()) {
System.out.println(e);
}
}
} catch (Exception e) {
e.printStackTrace();
if (!(holograms == null || holograms.isDeleted())) {
holograms.delete();
}
} else {
team = TagNameCfg.scoreboard.getTeam(invisibleName);
if (team == null) {
team = TagNameCfg.scoreboard.registerNewTeam(invisibleName);
}
team.setPrefix("");
team.setSuffix("");
if (NMSUtil.getServerVersion().startsWith("v1_7") || NMSUtil.getServerVersion().startsWith("v1_8")) {
} else {
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}
initHologramsName(player);
}
} else {
//TODO
//player.setCustomNameVisible(false);
team.addPlayer(player);
player.setScoreboard(TagNameCfg.scoreboard);
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
public void initHologramsName(Player player) {
if (holograms == null || holograms.isDeleted()) {
Location loc = player.getLocation();
loc = new Location(loc.getWorld(), loc.getX(), loc.getY() + 2.75, loc.getZ());
holograms = HologramsAPI.createHologram(pm, loc);
holograms.getVisibilityManager().hideTo(player);
}
holograms.clearLines();
holograms.appendTextLine(StrUtil.messageFormat(player, prefix));
holograms.appendTextLine(StrUtil.messageFormat(player, namecolor + player.getName()));
holograms.appendTextLine(StrUtil.messageFormat(player, suffix));
}
public void moveHologramsName(Player player) {
if (!(holograms == null || holograms.isDeleted())) {
Location loc = player.getLocation();
holograms.teleport(loc.getWorld(), loc.getX(), loc.getY() + 2.75, loc.getZ());
}
}
public void delHologramsName() {
if (!(holograms == null || holograms.isDeleted())) {
holograms.delete();
}
}
public String getDisplayNameStr(Player player) {
return StrUtil.messageFormat(player, "&r" + prefix + "&r" + namecolor + player.getName() + "&r" + suffix + "&r");
return StrUtil.messageFormat(prefix + "&r" + namecolor + player.getName() + "&r" + suffix);
}
@Override
@ -209,6 +248,14 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
return displayName;
}
public String getDisplayPrefix() {
return displayPrefix;
}
public String getDisplaySuffix() {
return displaySuffix;
}
@Override
public YamlConfiguration toConfig() {
YamlConfiguration config = new YamlConfiguration();
@ -227,7 +274,7 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
@Override
public String toString() {
return "PlayerTagBean [namecolor=" + namecolor + ", prefix=" + prefix + ", suffix=" + suffix + "]";
return "PlayerTagBean [namecolor=" + namecolor + ", prefix=" + prefix + ", suffix=" + suffix + ", displayName=" + displayName + ", displayPrefix=" + displayPrefix + ", displaySuffix=" + displaySuffix + ", invisibleName=" + invisibleName + "]";
}
}

View File

@ -21,7 +21,7 @@ public class TagPlaceholder extends PlaceholderExpansion {
}
public String getIdentifier() {
return pm.PLUGIN_NAME_LOWER_CASE;
return "pttag";
}
public String getPlugin() {
@ -37,12 +37,16 @@ public class TagPlaceholder extends PlaceholderExpansion {
}
public String onPlaceholderRequest(Player player, String identifier) {
if (identifier.equalsIgnoreCase("displayname") && PluginCfg.TAG_SYSTEM) {
if (player != null) {
String uuid = pm.getPlayerUUIDByName(player.getName());
PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
if (playerTag != null) {
if (PluginCfg.TAG_SYSTEM && player != null) {
String uuid = pm.getPlayerUUIDByName(player.getName());
PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
if (playerTag != null) {
if (identifier.equalsIgnoreCase("fullname")) {
return playerTag.getDisplayName();
} else if (identifier.equalsIgnoreCase("prefix")) {
return playerTag.getDisplayPrefix();
} else if (identifier.equalsIgnoreCase("suffix")) {
return playerTag.getDisplaySuffix();
}
}
}

View File

@ -19,11 +19,11 @@ public class StrUtil {
private static final long mt = IPlayerDataDao.TIME_UNIT;
public static String messageFormat(String src, Object... args) {
return MessageFormat.format(src, args).replace("&", "§").replace("\\n", "\n");
return MessageFormat.format(src, args).replaceAll("&", "§").replaceAll("\\n", "\n");
}
public static String messageFormat(Player player, String src, Object... args) {
String message = MessageFormat.format(src, args).replace("&", "§").replace("\\n", "\n").replace("%player%", player.getPlayer().getDisplayName());
String message = MessageFormat.format(src, args).replaceAll("&", "§").replaceAll("\\n", "\n").replaceAll("%player%", player.getPlayer().getDisplayName());
if (PluginMain.enabledPlaceholder) {
message = PlaceholderAPI.setPlaceholders(player, message);
}

View File

@ -156,13 +156,13 @@ public abstract class PluginConfig {
// }
}
protected void saveObj(String path, Map<String, ? extends IConfigBean> o) {
protected void setObj(String path, Map<String, ? extends IConfigBean> o) {
for (Entry<String, ? extends IConfigBean> configBean : o.entrySet()) {
saveObj(path + "." + configBean.getKey(), configBean.getValue());
setObj(path + "." + configBean.getKey(), configBean.getValue());
}
}
protected void saveObj(String path, IConfigBean o) {
protected void setObj(String path, IConfigBean o) {
getConfig().set(path, o.toConfig());
}

View File

@ -1,8 +1,9 @@
name: PermissionsTime
version: 0.4.0-SNAPSHOT
name: ${project.name}
version: ${project.version}
main: gg.frog.mc.permissionstime.PluginMain
author:
- GeekFrog
description: ${project.description}
softdepend:
- SQLibrary
- Vault
@ -55,5 +56,4 @@ permissions:
default: op
permissionstime.packages:
description: View packages.
default: op
default: op

View File

@ -3,23 +3,43 @@
defaultNamecolor: '&6'
# 默认前缀.
# Default Prefix.
defaultPrefix: ''
defaultPrefix: '&3[player]'
# 默认后缀.
# Default Suffix.
defaultSuffix: ''
# 使用HolographicDisplays显示称号
# use HolographicDisplays to show Tags
# 如果你有其他的插件来修改玩家的displayname, 请禁用此项或禁止其他插件修改. 比如Essentials插件.
# 如果安装了PlaceholderAPI 可以使用
# %pttag_fullname% %pttag_prefix% %pttag_suffix% 来显示displayname prefix+color suffix
# If you have other plugin, to modifies player displayname, please disable this.
changeDisplayname: true
# 使用HolographicDisplays显示称号. 称号可以更长,不会被省略.
# use HolographicDisplays to show Tags. The Tag can be more than 16 char
useHdPlugin: false
# 称号刷新周期(秒).
# 如果你你的称号使用了Placeholder请设置此项
# 如果你你的称号使用了PlaceholderAPI请设置此项
# 推荐600秒以上. 设置-1则禁用刷新.
# Title refresh cycle (seconds).
# If you use Placeholder, please set.
# Recommend more than 600s. Set -1 to disable refresh.
refreshTagTime: -1
template:
lore:
- '&1-----------------'
- '&2效果展示:'
- '&3 %displayname%'
- '&4-----------------'
- '&5 %description%'
- '&6-----------------'
packages:
# 称号包名称.
# Tag package name.
default:
description: '&4The default tag.'
permissions: ''
namecolor:
- '&6'
prefix:
- '&3[player]'
example1:
# 称号包描述,可以填写如何获得这些称号.
# Tag package describes. You can type how to get these tag.