1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-22 07:28:47 +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 name: PermissionsTime
version: 0.4.0-SNAPSHOT version: 0.4.0-SNAPSHOT
main: gg.frog.mc.permissionstime.PluginMain main: gg.frog.mc.permissionstime.PluginMain
author: GeekFrog author:
- GeekFrog
softdepend: softdepend:
- SQLibrary - SQLibrary
- Vault - Vault
- PlaceholderAPI - PlaceholderAPI
- HolographicDisplays
commands: commands:
permissionstime: permissionstime:
description: Show all commands. description: Show all commands.

View File

@ -7,6 +7,28 @@ defaultPrefix: ''
# 默认后缀. # 默认后缀.
# Default Suffix. # Default Suffix.
defaultSuffix: '' 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: packages:
# 称号包名称. # 称号包名称.
# Tag package name. # Tag package name.

28
pom.xml
View File

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

View File

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

View File

@ -43,16 +43,10 @@ public class MainCommand implements CommandExecutor, TabCompleter {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
if (isPlayer) { if (isPlayer) {
Player player = (Player) sender; Player player = (Player) sender;
if (sender.isOp() || player.hasPermission("permissionstime.reload")) { if (player.hasPermission("permissionstime.reload")) {
for (Player p : pm.getServer().getOnlinePlayers()) { for (Player p : pm.getServer().getOnlinePlayers()) {
InventoryView inventory = p.getOpenInventory(); InventoryView inventory = p.getOpenInventory();
if (inventory!=null && 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()))) {
(
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(); inventory.close();
} }
} }
@ -68,12 +62,10 @@ public class MainCommand implements CommandExecutor, TabCompleter {
} else { } else {
for (Player p : pm.getServer().getOnlinePlayers()) { for (Player p : pm.getServer().getOnlinePlayers()) {
InventoryView inventory = p.getOpenInventory(); InventoryView inventory = p.getOpenInventory();
if (inventory != null) { 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()))) {
if (StrUtil.messageFormat(LangCfg.INVENTORY_NAME + "&r&5&9&2&0&r").equals(inventory.getTitle())) {
inventory.close(); inventory.close();
} }
} }
}
pm.getConfigManager().reloadConfig(); pm.getConfigManager().reloadConfig();
if (!sm.updateDatabase()) { if (!sm.updateDatabase()) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Database exceptions.")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Database exceptions."));
@ -136,31 +128,31 @@ public class MainCommand implements CommandExecutor, TabCompleter {
private void getHelp(CommandSender sender, boolean isPlayer) { 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" : "") + " =====")); 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"))) { if (isPlayer && (sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_ME, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_ME, pm.PLUGIN_NAME_LOWER_CASE));
} }
if (isPlayer && (sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) { if (isPlayer && (sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages")) { if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_PACKAGES, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_PACKAGES, pm.PLUGIN_NAME_LOWER_CASE));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".get")) { if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".get")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GET, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GET, pm.PLUGIN_NAME_LOWER_CASE));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give")) { if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set")) { if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove")) { if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVE, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVE, pm.PLUGIN_NAME_LOWER_CASE));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall")) { if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVEALL, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVEALL, pm.PLUGIN_NAME_LOWER_CASE));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload")) { if (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload")) {
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_RELOAD, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_RELOAD, pm.PLUGIN_NAME_LOWER_CASE));
} }
} }
@ -168,7 +160,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
private boolean hasPermission(CommandSender sender, boolean isPlayer, String permissionPath) { private boolean hasPermission(CommandSender sender, boolean isPlayer, String permissionPath) {
if (isPlayer) { if (isPlayer) {
Player player = (Player) sender; Player player = (Player) sender;
if (sender.isOp() || player.hasPermission(permissionPath)) { if (player.hasPermission(permissionPath)) {
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION));
return false; return false;
@ -186,43 +178,43 @@ public class MainCommand implements CommandExecutor, TabCompleter {
} }
if (args.length == 1) { if (args.length == 1) {
args[0] = args[0].toLowerCase(Locale.ENGLISH); args[0] = args[0].toLowerCase(Locale.ENGLISH);
if ("me".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) { if ("me".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) {
tipList.add("me"); tipList.add("me");
} }
if ("tag".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) { if ("tag".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) {
tipList.add("tag"); tipList.add("tag");
} }
if ("packages".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages"))) { if ("packages".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages"))) {
tipList.add("packages"); tipList.add("packages");
} }
if ("give".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give"))) { if ("give".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give"))) {
tipList.add("give"); tipList.add("give");
} }
if ("set".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set"))) { if ("set".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set"))) {
tipList.add("set"); tipList.add("set");
} }
if ("get".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".get"))) { if ("get".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".get"))) {
tipList.add("get"); tipList.add("get");
} }
if ("remove".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove"))) { if ("remove".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove"))) {
tipList.add("remove"); tipList.add("remove");
} }
if ("removeall".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall"))) { if ("removeall".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall"))) {
tipList.add("removeall"); tipList.add("removeall");
} }
if ("reload".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload"))) { if ("reload".startsWith(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload"))) {
tipList.add("reload"); tipList.add("reload");
} }
} else if (args.length == 2) { } else if (args.length == 2) {
args[0] = args[0].toLowerCase(Locale.ENGLISH); args[0] = args[0].toLowerCase(Locale.ENGLISH);
args[1] = args[1].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"))) { if ("packages".equalsIgnoreCase(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me"))) {
for (String name : PackagesCfg.PACKAGES.keySet()) { for (String name : PackagesCfg.PACKAGES.keySet()) {
if (name.startsWith(args[1])) { if (name.startsWith(args[1])) {
tipList.add(name); tipList.add(name);
} }
} }
} else if ("tag".equalsIgnoreCase(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) { } else if ("tag".equalsIgnoreCase(args[0]) && (!isPlayer || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".tag"))) {
tipList.add("c"); tipList.add("c");
tipList.add("p"); tipList.add("p");
tipList.add("s"); tipList.add("s");

View File

@ -6,7 +6,6 @@ import java.util.Map;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
@ -37,6 +36,7 @@ public class TagCmd implements Runnable {
if (args.length == 2) { if (args.length == 2) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
List<ItemStack> itemList = new ArrayList<ItemStack>(); List<ItemStack> itemList = new ArrayList<ItemStack>();
List<ItemStack> disItemList = new ArrayList<ItemStack>();
TagType type = null; TagType type = null;
Map<String, List<ItemStack>> p_i_map; Map<String, List<ItemStack>> p_i_map;
if ("c".equals(args[1])) { if ("c".equals(args[1])) {
@ -56,13 +56,12 @@ public class TagCmd implements Runnable {
for (String p : p_i_map.keySet()) { for (String p : p_i_map.keySet()) {
if ("".equals(p) || sender.hasPermission(p)) { if ("".equals(p) || sender.hasPermission(p)) {
itemList.addAll(p_i_map.get(p)); itemList.addAll(p_i_map.get(p));
} else {
disItemList.addAll(p_i_map.get(p));
} }
} }
OfflinePlayer player = pm.getOfflinePlayer(sender.getName()); OfflinePlayer player = pm.getOfflinePlayer(sender.getName());
Player p = player.getPlayer(); PlayerTagShow.show(player, type, itemList, disItemList);
if (p != null) {
PlayerTagShow.show(p, type, itemList);
}
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE)); 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"); PACKAGES_VERSION = setGetDefault("version", "1.00");
DEFAULT_GROUP = setGetDefault("defaultGroup", "Default"); DEFAULT_GROUP = setGetDefault("defaultGroup", "Default");
PACKAGES = getObjMap("packages", PermissionPackageBean.class); PACKAGES = getObjMap("packages", PermissionPackageBean.class);
saveObj("packages", PACKAGES); setObj("packages", PACKAGES);
if (PluginCfg.IS_DEBUG) { if (PluginCfg.IS_DEBUG) {
System.out.println("packages vresion:" + PACKAGES_VERSION); System.out.println("packages vresion:" + PACKAGES_VERSION);
System.out.println("defaultGroup:" + DEFAULT_GROUP); 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_NAMECOLOR = null;
public static String DEFAULT_PREFIX = null; public static String DEFAULT_PREFIX = null;
public static String DEFAULT_SUFFIX = null; public static String DEFAULT_SUFFIX = null;
public static boolean CHANGE_DISPLAYNAME = true;
public static boolean USE_HD_PLUGIN = false; public static boolean USE_HD_PLUGIN = false;
public static Integer REFRESH_TAG_TIME = null; public static Integer REFRESH_TAG_TIME = null;
public static Map<String, TagPackageBean> PACKAGES = new ConcurrentHashMap<>(); 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>> NAMECOLOR_ITEMS = new ConcurrentHashMap<>();
public static Map<String, List<ItemStack>> PREFIX_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_NAMECOLOR = setGetDefault("defaultNamecolor", "");
DEFAULT_PREFIX = setGetDefault("defaultPrefix", ""); DEFAULT_PREFIX = setGetDefault("defaultPrefix", "");
DEFAULT_SUFFIX = setGetDefault("defaultSuffix", ""); DEFAULT_SUFFIX = setGetDefault("defaultSuffix", "");
CHANGE_DISPLAYNAME = setGetDefault("changeDisplayname", true);
USE_HD_PLUGIN = setGetDefault("useHdPlugin", false); USE_HD_PLUGIN = setGetDefault("useHdPlugin", false);
REFRESH_TAG_TIME = setGetDefault("refreshTagTime", -1); REFRESH_TAG_TIME = setGetDefault("refreshTagTime", -1);
PACKAGES = getObjMap("packages", TagPackageBean.class); 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) { if (PluginCfg.IS_DEBUG) {
System.out.println("defaultNamecolor:" + DEFAULT_NAMECOLOR); System.out.println("defaultNamecolor:" + DEFAULT_NAMECOLOR);
System.out.println("defaultPrefix:" + DEFAULT_PREFIX); System.out.println("defaultPrefix:" + DEFAULT_PREFIX);
@ -73,6 +78,9 @@ public class TagNameCfg extends PluginConfig {
for (Entry<String, TagPackageBean> p : PACKAGES.entrySet()) { for (Entry<String, TagPackageBean> p : PACKAGES.entrySet()) {
System.out.println(p.getKey() + ":" + p.getValue()); System.out.println(p.getKey() + ":" + p.getValue());
} }
for (String lore : TEMPLATE_LORE) {
System.out.println(lore);
}
} }
NAMECOLOR_ITEMS.clear(); NAMECOLOR_ITEMS.clear();
PREFIX_ITEMS.clear(); PREFIX_ITEMS.clear();
@ -82,8 +90,6 @@ public class TagNameCfg extends PluginConfig {
PREFIX_PERMISSIONS.clear(); PREFIX_PERMISSIONS.clear();
SUFFIX_PERMISSIONS.clear(); SUFFIX_PERMISSIONS.clear();
PLAYER_TAG.clear();
for (Entry<String, TagPackageBean> e : PACKAGES.entrySet()) { for (Entry<String, TagPackageBean> e : PACKAGES.entrySet()) {
List<ItemStack> items = getTagItem(TagType.NAMECOLOR_TYPE, e.getValue()); List<ItemStack> items = getTagItem(TagType.NAMECOLOR_TYPE, e.getValue());
if (NAMECOLOR_ITEMS.containsKey(e.getValue().getPermissions())) { if (NAMECOLOR_ITEMS.containsKey(e.getValue().getPermissions())) {
@ -104,7 +110,6 @@ public class TagNameCfg extends PluginConfig {
SUFFIX_ITEMS.put(e.getValue().getPermissions(), items); SUFFIX_ITEMS.put(e.getValue().getPermissions(), items);
} }
} }
if (task != null) { if (task != null) {
task.cancel(); task.cancel();
} }
@ -176,13 +181,16 @@ public class TagNameCfg extends PluginConfig {
ItemStack item = new ItemStack(type, 1, (short) 0, (byte) exid); ItemStack item = new ItemStack(type, 1, (short) 0, (byte) exid);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName(StrUtil.messageFormat(itemDisplayName + tag)); meta.setDisplayName(StrUtil.messageFormat(itemDisplayName + tag));
List<String> lores = new ArrayList<String>(); List<String> lores = new ArrayList<>(TEMPLATE_LORE);
lores.add(""); for (int i = 0; i < lores.size(); i++) {
lores.add("");// 效果展示 if (lores.get(i).contains("%description%")) {
lores.add(""); lores.set(i, StrUtil.messageFormat(lores.get(i).replaceAll("%description%", tpb.getDescription())));// 描述
lores.add(StrUtil.messageFormat(tpb.getDescription()));// 描述 } else {
lores.add(""); lores.set(i, StrUtil.messageFormat(lores.get(i)));
lores.add(tag);// 称号 }
}
lores.add("§8§k" + tpb.getPermissions());// 权限
lores.add("§8" + tag);// 称号
meta.setLore(lores); meta.setLore(lores);
item.setItemMeta(meta); item.setItemMeta(meta);
if (skullOwner != null) { if (skullOwner != null) {

View File

@ -21,9 +21,7 @@ public class PlayerPermissionShow {
Inventory inventory = null; Inventory inventory = null;
int size = 0; int size = 0;
if (pdbList.size() > 0) { if (pdbList.size() > 0) {
inventory = Bukkit.createInventory(null, 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"));
(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) { for (PlayerDataBean pdb : pdbList) {
PermissionPackageBean ppb = PackagesCfg.PACKAGES.get(pdb.getPackageName()); PermissionPackageBean ppb = PackagesCfg.PACKAGES.get(pdb.getPackageName());
if (ppb != null && pdb.getGlobal() == ppb.getGlobal()) { if (ppb != null && pdb.getGlobal() == ppb.getGlobal()) {
@ -31,8 +29,7 @@ public class PlayerPermissionShow {
ItemStack tItem = item.clone(); ItemStack tItem = item.clone();
ItemMeta meta = tItem.getItemMeta(); ItemMeta meta = tItem.getItemMeta();
List<String> lores = meta.getLore(); List<String> lores = meta.getLore();
lores.add( lores.add(StrUtil.messageFormat(LangCfg.EXPIRATION_TIME, StrUtil.timestampToString(pdb.getExpire())));
StrUtil.messageFormat(LangCfg.EXPIRATION_TIME, StrUtil.timestampToString(pdb.getExpire())));
lores.add(StrUtil.getLeftTime(pdb.getExpire())); lores.add(StrUtil.getLeftTime(pdb.getExpire()));
meta.setLore(lores); meta.setLore(lores);
tItem.setItemMeta(meta); 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.config.TagNameCfg.TagType;
import gg.frog.mc.permissionstime.model.PlayerTagBean; import gg.frog.mc.permissionstime.model.PlayerTagBean;
import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.StrUtil;
import gg.frog.mc.permissionstime.utils.nms.ItemUtil;
public class PlayerTagShow { 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; Inventory inventory = null;
int size = 0; int size = 0;
if (itemList.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")); 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 = p.getUniqueId().toString(); String uuid = player.getUniqueId().toString();
PlayerTagBean playerTag = null; PlayerTagBean playerTag = null;
if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) { if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) {
playerTag = TagNameCfg.PLAYER_TAG.get(uuid); playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
playerTag = playerTag.clone();
if (playerTag != null) { if (playerTag != null) {
for (ItemStack item : itemList) { for (ItemStack item : itemList) {
playerTag = playerTag.clone();
ItemStack tItem = item.clone(); ItemStack tItem = item.clone();
ItemMeta meta = tItem.getItemMeta(); ItemMeta meta = tItem.getItemMeta();
List<String> lores = meta.getLore(); 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) { if (tagType == TagType.NAMECOLOR_TYPE) {
meta.setDisplayName(meta.getDisplayName() + p.getName()); meta.setDisplayName(meta.getDisplayName() + player.getName());
playerTag.setNamecolor(tag); playerTag.setNamecolor(tag);
} else if (tagType == TagType.PREFIX_TYPE) { } else if (tagType == TagType.PREFIX_TYPE) {
playerTag.setPrefix(tag); playerTag.setPrefix(tag);
} else if (tagType == TagType.SUFFIX_TYPE) { } else if (tagType == TagType.SUFFIX_TYPE) {
playerTag.setSuffix(tag); 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); meta.setLore(lores);
tItem.setItemMeta(meta); tItem.setItemMeta(meta);
inventory.addItem(tItem); inventory.addItem(tItem);
size++; 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) { if (inventory != null && size > 0) {
p.getPlayer().openInventory(inventory); player.getPlayer().openInventory(inventory);
} else { } 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; package gg.frog.mc.permissionstime.listener;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -10,6 +9,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
@ -49,19 +49,27 @@ public class MainListener implements Listener {
}).start(); }).start();
} }
@EventHandler
public void onQuit(PlayerQuitEvent event) { public void onQuit(PlayerQuitEvent event) {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
PermissionPackageBean.delPlayerAllPermissions(event.getPlayer(), pm); 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
}).start(); }).start();
pm.getPlayerMap().remove(event.getPlayer().getName());
} }
@EventHandler
public void onKick(PlayerKickEvent event) { public void onKick(PlayerKickEvent event) {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
@ -73,6 +81,18 @@ public class MainListener implements Listener {
} }
} }
}).start(); }).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 @EventHandler
@ -81,25 +101,34 @@ public class MainListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
if (StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "&r&5&9&2&0&r").equals(event.getInventory().getName())) { if (StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "&r&5&9&2&0&r").equals(event.getInventory().getName())) {
OfflinePlayer player = this.pm.getOfflinePlayer(event.getWhoClicked().getName()); if (event.getCurrentItem() != null && event.getCurrentItem().getItemMeta() != null && event.getCurrentItem().getItemMeta().hasLore()) {
UUID uuid = player.getUniqueId();
if (TagNameCfg.PLAYER_TAG.containsKey(uuid.toString()) && event.getCurrentItem() != null) {
List<String> lores = event.getCurrentItem().getItemMeta().getLore(); List<String> lores = event.getCurrentItem().getItemMeta().getLore();
if (lores.size() == 6) { 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(); String itemName = event.getCurrentItem().getItemMeta().getDisplayName();
PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid.toString()); PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
if (itemName.startsWith(StrUtil.messageFormat("&6&l昵称效果 &r"))) { if (itemName.startsWith("§6§l昵称效果§r ")) {
playerTag.setNamecolor(lores.get(5)); playerTag.setNamecolor(lores.get(lores.size() - 1).substring(2));
} else if (itemName.startsWith(StrUtil.messageFormat("&6&l昵称前缀 &r"))) { } else if (itemName.startsWith("§6§l昵称前缀§r ")) {
playerTag.setPrefix(lores.get(5)); playerTag.setPrefix(lores.get(lores.size() - 1).substring(2));
} else if (itemName.startsWith(StrUtil.messageFormat("&6&l昵称后缀 &r"))) { } else if (itemName.startsWith("§6§l昵称后缀§r ")) {
playerTag.setSuffix(lores.get(5)); playerTag.setSuffix(lores.get(lores.size() - 1).substring(2));
} else { } else {
event.setCancelled(true); event.setCancelled(true);
return;
} }
playerTag.setPlayerDisplayName(player.getPlayer(), true); playerTag.setPlayerDisplayName(player.getPlayer(), true);
playerTag.saveConfig(); playerTag.saveConfig();
event.getWhoClicked().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TAG_SET_SUCCESS)); player.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TAG_SET_SUCCESS));
}
} else {
player.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION));
}
} }
} }
event.setCancelled(true); event.setCancelled(true);

View File

@ -1,16 +1,21 @@
package gg.frog.mc.permissionstime.model; package gg.frog.mc.permissionstime.model;
import org.bukkit.Location;
import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team; 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.PluginMain;
import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.config.TagNameCfg; import gg.frog.mc.permissionstime.config.TagNameCfg;
import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.StrUtil;
import gg.frog.mc.permissionstime.utils.config.IConfigBean; import gg.frog.mc.permissionstime.utils.config.IConfigBean;
import gg.frog.mc.permissionstime.utils.config.PluginConfig; 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 suffix;
// 当前显示的名称 // 当前显示的名称
private String displayName; 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) { public PlayerTagBean(String fileName, PluginMain pm) {
super(fileName, pm); super(fileName, pm);
if (PluginCfg.IS_DEBUG) {
System.out.println("Player Tag File:" + fileName);
}
} }
@Override @Override
@ -115,59 +127,86 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
} }
} }
if (forceSet || namecolor_flag || prefix_flag || suffix_flag) { if (forceSet || namecolor_flag || prefix_flag || suffix_flag) {
displayName = getDisplayNameStr(player); 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); player.setDisplayName(displayName);
}
if (PluginCfg.IS_DEBUG) { if (PluginCfg.IS_DEBUG) {
System.out.println("PlayerTagBean:" + playerTag); System.out.println("PlayerTagBean:" + playerTag);
} }
if (!TagNameCfg.USE_HD_PLUGIN) {
try { try {
if (TagNameCfg.scoreboard == null) { if (TagNameCfg.scoreboard == null) {
TagNameCfg.scoreboard = pm.getServer().getScoreboardManager().getNewScoreboard(); TagNameCfg.scoreboard = pm.getServer().getScoreboardManager().getNewScoreboard();
} }
Team team = TagNameCfg.scoreboard.getTeam(player.getName()); 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) { if (team == null) {
team = TagNameCfg.scoreboard.registerNewTeam(player.getName()); team = TagNameCfg.scoreboard.registerNewTeam(player.getName());
} }
String teamPrefix = StrUtil.messageFormat(player, prefix + "&r" + namecolor); String teamPrefix = displayPrefix.length() > 16 ? (displayPrefix.substring(0, 7) + ".." + displayPrefix.substring(displayPrefix.length() - 7)) : displayPrefix;
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);
team.setPrefix(teamPrefix); team.setPrefix(teamPrefix);
String teamSuffix = StrUtil.messageFormat(player, "&r" + suffix); String teamSuffix = displaySuffix.length() > 16 ? (displaySuffix.substring(0, 7) + ".." + displaySuffix.substring(displaySuffix.length() - 7)) : displaySuffix;
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);
}
team.setSuffix(teamSuffix); team.setSuffix(teamSuffix);
team.addEntry(player.getName()); if (!(holograms == null || holograms.isDeleted())) {
player.setScoreboard(TagNameCfg.scoreboard); holograms.delete();
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();
} }
} else { } else {
//TODO team = TagNameCfg.scoreboard.getTeam(invisibleName);
//player.setCustomNameVisible(false); 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);
}
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) { 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 @Override
@ -209,6 +248,14 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
return displayName; return displayName;
} }
public String getDisplayPrefix() {
return displayPrefix;
}
public String getDisplaySuffix() {
return displaySuffix;
}
@Override @Override
public YamlConfiguration toConfig() { public YamlConfiguration toConfig() {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
@ -227,7 +274,7 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
@Override @Override
public String toString() { 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() { public String getIdentifier() {
return pm.PLUGIN_NAME_LOWER_CASE; return "pttag";
} }
public String getPlugin() { public String getPlugin() {
@ -37,12 +37,16 @@ public class TagPlaceholder extends PlaceholderExpansion {
} }
public String onPlaceholderRequest(Player player, String identifier) { public String onPlaceholderRequest(Player player, String identifier) {
if (identifier.equalsIgnoreCase("displayname") && PluginCfg.TAG_SYSTEM) { if (PluginCfg.TAG_SYSTEM && player != null) {
if (player != null) {
String uuid = pm.getPlayerUUIDByName(player.getName()); String uuid = pm.getPlayerUUIDByName(player.getName());
PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid); PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
if (playerTag != null) { if (playerTag != null) {
if (identifier.equalsIgnoreCase("fullname")) {
return playerTag.getDisplayName(); 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; private static final long mt = IPlayerDataDao.TIME_UNIT;
public static String messageFormat(String src, Object... args) { 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) { 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) { if (PluginMain.enabledPlaceholder) {
message = PlaceholderAPI.setPlaceholders(player, message); 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()) { 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()); getConfig().set(path, o.toConfig());
} }

View File

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

View File

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