From 77527884165441cd596fb687e434429426045e72 Mon Sep 17 00:00:00 2001 From: GeekFrog Date: Sat, 30 Jun 2018 00:41:12 +0800 Subject: [PATCH] =?UTF-8?q?1.V0.4.3=E6=AD=A3=E5=BC=8F=E5=8F=91=E5=B8=83=20?= =?UTF-8?q?2.=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9BBUG:=20=20=201.7.10?= =?UTF-8?q?=E7=9A=84=E5=85=BC=E5=AE=B9=20=20=20=E4=BB=A5=E5=8F=8A=E6=96=B0?= =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E6=95=B0=E6=8D=AE=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/plugin.yml | 2 +- pom.xml | 5 +- src/main/gg/frog/mc/base/PluginMain.java | 33 ++- .../gg/frog/mc/base/utils/nms/ItemUtil.java | 216 +++++++++--------- .../gg/frog/mc/base/utils/nms/NMSUtil.java | 32 +-- .../frog/mc/nametags/config/TagNameCfg.java | 9 +- .../frog/mc/nametags/gui/PlayerTagShow.java | 2 +- .../mc/nametags/listener/TagsListener.java | 67 +++--- .../frog/mc/nametags/model/PlayerTagBean.java | 3 +- .../nametags/placeholder/TagPlaceholder.java | 2 +- .../mc/permissionstime/command/MeCmd.java | 2 +- .../permissionstime/config/PackagesCfg.java | 2 +- .../permissionstime/listener/PtListener.java | 2 +- .../model/cfg/PermissionPackageBean.java | 6 +- src/resources/plugin.yml | 2 +- 帖子代码.txt | 24 -- 16 files changed, 208 insertions(+), 201 deletions(-) diff --git a/config/plugin.yml b/config/plugin.yml index de8c166..54645fc 100644 --- a/config/plugin.yml +++ b/config/plugin.yml @@ -1,5 +1,5 @@ name: ${project.name} -version: 0.4.2-SNAPSHOT-b1002 +version: 0.4.3-SNAPSHOT-b1005 main: gg.frog.mc.base.PluginMain author: - GeekFrog diff --git a/pom.xml b/pom.xml index 4dcf744..78b5a98 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,11 @@ - 4.0.0 gg.frog.mc permissionstime - 0.4.2-SNAPSHOT-b1003 + 0.4.3-SNAPSHOT-b1005 jar PermissionsTime 支持跨服的权限限时插件 diff --git a/src/main/gg/frog/mc/base/PluginMain.java b/src/main/gg/frog/mc/base/PluginMain.java index 999b1b7..858f504 100644 --- a/src/main/gg/frog/mc/base/PluginMain.java +++ b/src/main/gg/frog/mc/base/PluginMain.java @@ -9,6 +9,7 @@ import java.util.logging.Logger; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; @@ -67,19 +68,19 @@ public class PluginMain extends JavaPlugin { registerListeners(); registerCommands(); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "§2Startup successful!")); - } - getServer().getScheduler().runTask(pm, new Runnable() { - public void run() { - if (PluginCfg.IS_METRICS) { - try { - new Metrics(pm); - } catch (Exception e) { - e.printStackTrace(); + getServer().getScheduler().runTask(pm, new Runnable() { + public void run() { + if (PluginCfg.IS_METRICS) { + try { + new Metrics(pm); + } catch (Exception e) { + e.printStackTrace(); + } } + getServer().getScheduler().runTaskAsynchronously(pm, new UpdateCheck(pm)); } - getServer().getScheduler().runTaskAsynchronously(pm, new UpdateCheck(pm)); - } - }); + }); + } } /** @@ -99,7 +100,7 @@ public class PluginMain extends JavaPlugin { private void registerCommands() { PtCommand ptCmd = new PtCommand(pm); if (getDescription().getCommands().containsKey("permissionstime")) { - getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(ptCmd); + getCommand("permissionstime").setExecutor(ptCmd); } if (getDescription().getCommands().containsKey("pt")) { getCommand("pt").setExecutor(ptCmd); @@ -206,6 +207,14 @@ public class PluginMain extends JavaPlugin { return null; } + public String getPlayerUUIDByName(Player p) { + String uuid = getPlayerUUIDByName(p.getName()); + if (uuid == null) { + return p.getUniqueId().toString(); + } + return uuid; + } + public String getPlayerUUIDByName(String name) { if (name != null) { String uuid = PLAYER_UUID_MAP.get(name); diff --git a/src/main/gg/frog/mc/base/utils/nms/ItemUtil.java b/src/main/gg/frog/mc/base/utils/nms/ItemUtil.java index f693e43..d61e64d 100644 --- a/src/main/gg/frog/mc/base/utils/nms/ItemUtil.java +++ b/src/main/gg/frog/mc/base/utils/nms/ItemUtil.java @@ -11,114 +11,116 @@ import gg.frog.mc.base.utils.StrUtil; public class ItemUtil { - private static Class nbtBaseClass; - private static Class nbtTagCompoundClass; - private static Class nbtTagStringClass; - private static Class nbtTagIntClass; -// private static Class nbtTagShortClass; -// private static Class nbtTagListClass; - private static Class nmsItemstackClass; - private static Method asNmsCopyMethod; - private static Method asCraftMirrorMethod; - private static Method hasTagMethod; - private static Method getTagMethod; - private static Method setTagMethod; - private static Method nbtSetMethod; -// private static Method nbtListAddSetMethod; - private static boolean setupOk; + private static Class nbtBaseClass; + private static Class nbtTagCompoundClass; + private static Class nbtTagStringClass; + private static Class nbtTagIntClass; + // private static Class nbtTagShortClass; + // private static Class nbtTagListClass; + private static Class itemstackClass; + private static Method asNmsCopyMethod; + private static Method asCraftMirrorMethod; + private static Method hasTagMethod; + private static Method getTagMethod; + private static Method setTagMethod; + private static Method nbtSetMethod; + // private static Method nbtListAddSetMethod; + private static boolean setupOk; - static { - try { - nmsItemstackClass = NMSUtil.getNmsClass("ItemStack");// add - nbtBaseClass = NMSUtil.getNmsClass("NBTBase");// dy - nbtTagStringClass = NMSUtil.getNmsClass("NBTTagString");// dx - nbtTagIntClass = NMSUtil.getNmsClass("NBTTagInt");// dp - nbtTagCompoundClass = NMSUtil.getNmsClass("NBTTagCompound");// dh -// nbtTagShortClass = NMSUtil.getNmsClass("NBTTagShort"); -// nbtTagListClass = NMSUtil.getNmsClass("NBTTagList"); - asNmsCopyMethod = NMSUtil.getObcClass("inventory.CraftItemStack").getMethod("asNMSCopy", new Class[] { ItemStack.class }); - asCraftMirrorMethod = NMSUtil.getObcClass("inventory.CraftItemStack").getMethod("asCraftMirror", new Class[] { nmsItemstackClass }); - hasTagMethod = nmsItemstackClass.getMethod("hasTag", new Class[0]);// p - getTagMethod = nmsItemstackClass.getMethod("getTag", new Class[0]);// q - setTagMethod = nmsItemstackClass.getMethod("setTag", new Class[] { nbtTagCompoundClass });// d - nbtSetMethod = nbtTagCompoundClass.getMethod("set", new Class[] { String.class, nbtBaseClass });// a -// nbtListAddSetMethod = nbtTagListClass.getMethod("add", new Class[] { nbtBaseClass }); - setupOk = true; - } catch (Exception e) { - e.printStackTrace(); -// try { -// nmsItemstackClass = Class.forName("add"); -// nbtBaseClass = Class.forName("dy"); -// nbtTagStringClass = Class.forName("dx"); -// nbtTagIntClass = Class.forName("dp"); -// nbtTagCompoundClass = Class.forName("dh"); -// asNmsCopyMethod = NMSUtil.getObcClass("inventory.CraftItemStack").getMethod("asNMSCopy", new Class[] { ItemStack.class }); -// asCraftMirrorMethod = NMSUtil.getObcClass("inventory.CraftItemStack").getMethod("asCraftMirror", new Class[] { nmsItemstackClass }); -// hasTagMethod = nmsItemstackClass.getMethod("func_77942_o", new Class[0]); -// getTagMethod = nmsItemstackClass.getMethod("func_77978_p", new Class[0]); -// setTagMethod = nmsItemstackClass.getMethod("func_77982_d", new Class[] { nbtTagCompoundClass }); -// nbtSetMethod = nbtTagCompoundClass.getMethod("func_74782_a", new Class[] { String.class, nbtBaseClass }); -// setupOk = true; -// } catch (Exception ex) { -// ex.printStackTrace(); -// PluginMain.LOG.warning(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "ItemUtil setup fail. Some functions are unavailable.")); -// } - PluginMain.LOG.warning(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "ItemUtil setup fail. Some functions are unavailable.")); - } - } + static { + try { + try { + itemstackClass = NMSUtil.getNmsClass("ItemStack"); + nbtBaseClass = NMSUtil.getNmsClass("NBTBase"); + nbtTagStringClass = NMSUtil.getNmsClass("NBTTagString"); + nbtTagIntClass = NMSUtil.getNmsClass("NBTTagInt"); + nbtTagCompoundClass = NMSUtil.getNmsClass("NBTTagCompound"); - public static ItemStack addEnchantLight(ItemStack item) { - item.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 0); - if (!NMSUtil.getServerVersion().startsWith("v1_7_") && setupOk) { - try { - Object nmsItemstack = asNmsCopyMethod.invoke(null, new Object[] { item }); - if (nmsItemstack == null) { - return item; - } - Object nbtCompound = null; - if (((Boolean) hasTagMethod.invoke(nmsItemstack, new Object[0])).booleanValue()) { - nbtCompound = getTagMethod.invoke(nmsItemstack, new Object[0]); - } else { - nbtCompound = nbtTagCompoundClass.newInstance(); - setTagMethod.invoke(nmsItemstack, new Object[] { nbtCompound }); - } - if (nbtCompound == null) { - return item; - } - Object nbtHideFlags = nbtTagIntClass.getConstructor(int.class).newInstance(1); - nbtSetMethod.invoke(nbtCompound, new Object[] { "HideFlags", nbtHideFlags }); - return (ItemStack) asCraftMirrorMethod.invoke(null, new Object[] { nmsItemstack }); - } catch (Exception e) { - e.printStackTrace(); - } - } - return item; - } + hasTagMethod = itemstackClass.getMethod("hasTag", new Class[0]); + getTagMethod = itemstackClass.getMethod("getTag", new Class[0]); + setTagMethod = itemstackClass.getMethod("setTag", new Class[] { nbtTagCompoundClass }); + nbtSetMethod = nbtTagCompoundClass.getMethod("set", new Class[] { String.class, nbtBaseClass }); + // nbtTagShortClass = NMSUtil.getNmsClass("NBTTagShort"); + // nbtTagListClass = NMSUtil.getNmsClass("NBTTagList"); + // nbtListAddSetMethod = nbtTagListClass.getMethod("add", new Class[] + // {nbtBaseClass}); + } catch (Exception e) { + if (NMSUtil.getServerVersion().startsWith("v1_7_R4")) { + itemstackClass = NMSUtil.getNmClass("item.ItemStack");// add + nbtBaseClass = NMSUtil.getNmClass("nbt.NBTBase");// dy + nbtTagStringClass = NMSUtil.getNmClass("nbt.NBTTagString");// dx + nbtTagIntClass = NMSUtil.getNmClass("nbt.NBTTagInt");// dp + nbtTagCompoundClass = NMSUtil.getNmClass("nbt.NBTTagCompound");// dh - public static ItemStack addSkullOwner(ItemStack item, String name) { - if (setupOk) { - try { - Object nmsItemstack = asNmsCopyMethod.invoke(null, new Object[] { item }); - if (nmsItemstack == null) { - return item; - } - Object nbtCompound = null; - if (((Boolean) hasTagMethod.invoke(nmsItemstack, new Object[0])).booleanValue()) { - nbtCompound = getTagMethod.invoke(nmsItemstack, new Object[0]); - } else { - nbtCompound = nbtTagCompoundClass.newInstance(); - setTagMethod.invoke(nmsItemstack, new Object[] { nbtCompound }); - } - if (nbtCompound == null) { - return item; - } - Object nbtString = nbtTagStringClass.getConstructor(String.class).newInstance(name); - nbtSetMethod.invoke(nbtCompound, new Object[] { "SkullOwner", nbtString }); - return (ItemStack) asCraftMirrorMethod.invoke(null, new Object[] { nmsItemstack }); - } catch (Exception e) { - e.printStackTrace(); - } - } - return item; - } + hasTagMethod = itemstackClass.getMethod("func_77942_o", new Class[0]);// hasTagCompound + getTagMethod = itemstackClass.getMethod("func_77978_p", new Class[0]);// getTagCompound + setTagMethod = itemstackClass.getMethod("func_77982_d", new Class[] { nbtTagCompoundClass });// setTagCompound + nbtSetMethod = nbtTagCompoundClass.getMethod("func_74782_a", new Class[] { String.class, nbtBaseClass });// setTag + } else { + throw new Exception("Nbt edit is not support."); + } + } + asNmsCopyMethod = NMSUtil.getObcClass("inventory.CraftItemStack").getMethod("asNMSCopy", new Class[] { ItemStack.class }); + asCraftMirrorMethod = NMSUtil.getObcClass("inventory.CraftItemStack").getMethod("asCraftMirror", new Class[] { itemstackClass }); + setupOk = true; + } catch (Exception e) { + e.printStackTrace(); + PluginMain.LOG.warning(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "ItemUtil setup fail. Some functions are unavailable.")); + } + } + + public static ItemStack addEnchantLight(ItemStack item) { + item.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 0); + if (!NMSUtil.getServerVersion().startsWith("v1_7_") && setupOk) { + try { + Object nmsItemstack = asNmsCopyMethod.invoke(null, new Object[] { item }); + if (nmsItemstack == null) { + return item; + } + Object nbtCompound = null; + if (((Boolean) hasTagMethod.invoke(nmsItemstack, new Object[0])).booleanValue()) { + nbtCompound = getTagMethod.invoke(nmsItemstack, new Object[0]); + } else { + nbtCompound = nbtTagCompoundClass.newInstance(); + setTagMethod.invoke(nmsItemstack, new Object[] { nbtCompound }); + } + if (nbtCompound == null) { + return item; + } + Object nbtHideFlags = nbtTagIntClass.getConstructor(int.class).newInstance(1); + nbtSetMethod.invoke(nbtCompound, new Object[] { "HideFlags", nbtHideFlags }); + return (ItemStack) asCraftMirrorMethod.invoke(null, new Object[] { nmsItemstack }); + } catch (Exception e) { + e.printStackTrace(); + } + } + return item; + } + + public static ItemStack addSkullOwner(ItemStack item, String name) { + if (setupOk) { + try { + Object nmsItemstack = asNmsCopyMethod.invoke(null, new Object[] { item }); + if (nmsItemstack == null) { + return item; + } + Object nbtCompound = null; + if (((Boolean) hasTagMethod.invoke(nmsItemstack, new Object[0])).booleanValue()) { + nbtCompound = getTagMethod.invoke(nmsItemstack, new Object[0]); + } else { + nbtCompound = nbtTagCompoundClass.newInstance(); + setTagMethod.invoke(nmsItemstack, new Object[] { nbtCompound }); + } + if (nbtCompound == null) { + return item; + } + Object nbtString = nbtTagStringClass.getConstructor(String.class).newInstance(name); + nbtSetMethod.invoke(nbtCompound, new Object[] { "SkullOwner", nbtString }); + return (ItemStack) asCraftMirrorMethod.invoke(null, new Object[] { nmsItemstack }); + } catch (Exception e) { + e.printStackTrace(); + } + } + return item; + } } diff --git a/src/main/gg/frog/mc/base/utils/nms/NMSUtil.java b/src/main/gg/frog/mc/base/utils/nms/NMSUtil.java index 3474476..4feb743 100644 --- a/src/main/gg/frog/mc/base/utils/nms/NMSUtil.java +++ b/src/main/gg/frog/mc/base/utils/nms/NMSUtil.java @@ -4,23 +4,27 @@ import org.bukkit.Bukkit; public class NMSUtil { - private static String serverVersion; + private static String serverVersion; - static { - String packageName = Bukkit.getServer().getClass().getPackage().getName(); - serverVersion = packageName.substring(packageName.lastIndexOf('.') + 1); - } + static { + String packageName = Bukkit.getServer().getClass().getPackage().getName(); + serverVersion = packageName.substring(packageName.lastIndexOf('.') + 1); + } - public static String getServerVersion() { - return serverVersion; - } + public static String getServerVersion() { + return serverVersion; + } - public static Class getNmsClass(String name) throws ClassNotFoundException { - return Class.forName("net.minecraft.server." + getServerVersion() + "." + name); - } + public static Class getNmsClass(String name) throws ClassNotFoundException { + return Class.forName("net.minecraft.server." + getServerVersion() + "." + name); + } - public static Class getObcClass(String name) throws ClassNotFoundException { - return Class.forName("org.bukkit.craftbukkit." + getServerVersion() + "." + name); - } + public static Class getObcClass(String name) throws ClassNotFoundException { + return Class.forName("org.bukkit.craftbukkit." + getServerVersion() + "." + name); + } + + public static Class getNmClass(String name) throws ClassNotFoundException { + return Class.forName("net.minecraft." + name); + } } diff --git a/src/main/gg/frog/mc/nametags/config/TagNameCfg.java b/src/main/gg/frog/mc/nametags/config/TagNameCfg.java index 20b67af..98cf26d 100644 --- a/src/main/gg/frog/mc/nametags/config/TagNameCfg.java +++ b/src/main/gg/frog/mc/nametags/config/TagNameCfg.java @@ -12,6 +12,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.scheduler.BukkitTask; import org.bukkit.scoreboard.Scoreboard; @@ -210,7 +211,13 @@ public class TagNameCfg extends PluginConfig { meta.setLore(lores); item.setItemMeta(meta); if (skullOwner != null) { - item = ItemUtil.addSkullOwner(item, skullOwner); + try { + ((SkullMeta) meta).setOwner(skullOwner); + item.setItemMeta(meta); + } catch (Exception e) { + e.printStackTrace(); + item = ItemUtil.addSkullOwner(item, skullOwner); + } } items.add(item); } diff --git a/src/main/gg/frog/mc/nametags/gui/PlayerTagShow.java b/src/main/gg/frog/mc/nametags/gui/PlayerTagShow.java index 319c2c2..adf5275 100644 --- a/src/main/gg/frog/mc/nametags/gui/PlayerTagShow.java +++ b/src/main/gg/frog/mc/nametags/gui/PlayerTagShow.java @@ -24,7 +24,7 @@ public class PlayerTagShow { int size = 0; if (itemList.size() > 0) { inventory = Bukkit.createInventory(null, ((itemList.size() + disItemList.size()) % 9 == 0 ? (itemList.size() + disItemList.size()) : ((itemList.size() + disItemList.size()) / 9 + 1) * 9), StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "§r§5§9§2§0§2§r")); - String uuid = pm.getPlayerUUIDByName(p.getName()); + String uuid = pm.getPlayerUUIDByName(p); PlayerTagBean playerTag = null; if (uuid != null && TagNameCfg.PLAYER_TAG.containsKey(uuid)) { playerTag = TagNameCfg.PLAYER_TAG.get(uuid); diff --git a/src/main/gg/frog/mc/nametags/listener/TagsListener.java b/src/main/gg/frog/mc/nametags/listener/TagsListener.java index 65d27ec..5d67f08 100644 --- a/src/main/gg/frog/mc/nametags/listener/TagsListener.java +++ b/src/main/gg/frog/mc/nametags/listener/TagsListener.java @@ -31,10 +31,15 @@ public class TagsListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onJoin(PlayerLoginEvent event) { if (PluginCfg.TAG_SYSTEM) { - PlayerTagBean.initPlayerTag(event.getPlayer(), pm); + pm.getServer().getScheduler().runTaskLaterAsynchronously(pm, new Runnable() { + @Override + public void run() { + PlayerTagBean.initPlayerTag(event.getPlayer(), pm); + } + }, 1 * 20); } } - + @EventHandler public void onRespawn(PlayerChangedWorldEvent event) { if (PluginCfg.TAG_SYSTEM) { @@ -45,7 +50,7 @@ public class TagsListener implements Listener { @EventHandler public void onQuit(PlayerQuitEvent event) { if (PluginCfg.TAG_SYSTEM && TagNameCfg.USE_HD_PLUGIN) { - String uuid = pm.getPlayerUUIDByName(event.getPlayer().getName()); + String uuid = pm.getPlayerUUIDByName(event.getPlayer()); PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid); playerTag.delHologramsName(); } @@ -54,7 +59,7 @@ public class TagsListener implements Listener { @EventHandler public void onKick(PlayerKickEvent event) { if (PluginCfg.TAG_SYSTEM && TagNameCfg.USE_HD_PLUGIN) { - String uuid = pm.getPlayerUUIDByName(event.getPlayer().getName()); + String uuid = pm.getPlayerUUIDByName(event.getPlayer()); PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid); playerTag.delHologramsName(); } @@ -63,7 +68,7 @@ public class TagsListener implements Listener { @EventHandler public void onMove(PlayerMoveEvent event) { if (PluginCfg.TAG_SYSTEM && TagNameCfg.USE_HD_PLUGIN) { - String uuid = this.pm.getPlayerUUIDByName(event.getPlayer().getName()); + String uuid = this.pm.getPlayerUUIDByName(event.getPlayer()); PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid); if (playerTag != null) { playerTag.moveHologramsName(event.getPlayer()); @@ -74,36 +79,40 @@ public class TagsListener implements Listener { @EventHandler public void onPlayerClick(InventoryClickEvent event) { if (StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "§r§5§9§2§0§2§r").equals(event.getInventory().getName())) { - if (event.getCurrentItem() != null && event.getCurrentItem().getItemMeta() != null && event.getCurrentItem().getItemMeta().hasLore()) { - List lores = event.getCurrentItem().getItemMeta().getLore(); - if (lores.size() > 1) { - String permissions = lores.get(lores.size() - 2); - permissions = permissions.startsWith("§8§k") ? permissions.substring(4) : "noPermissions"; - String uuid = pm.getPlayerUUIDByName(event.getWhoClicked().getName()); - if (permissions.length() == 0 || event.getWhoClicked().hasPermission(permissions)) { - if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) { - String itemName = event.getCurrentItem().getItemMeta().getDisplayName(); - PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid); - if (itemName.startsWith(StrUtil.messageFormat(LangCfg.TAG_COLOR_ITEM_NAME + "§1§r "))) { - playerTag.setNamecolor(lores.get(lores.size() - 1).substring(2)); - } else if (itemName.startsWith(StrUtil.messageFormat(LangCfg.TAG_PREFIX_ITEM_NAME + "§2§r "))) { - playerTag.setPrefix(lores.get(lores.size() - 1).substring(2)); - } else if (itemName.startsWith(StrUtil.messageFormat(LangCfg.TAG_SUFFIX_ITEM_NAME + "§3§r "))) { - playerTag.setSuffix(lores.get(lores.size() - 1).substring(2)); - } else { - event.getWhoClicked().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION)); + try { + if (event.getCurrentItem() != null && event.getCurrentItem().getItemMeta() != null && event.getCurrentItem().getItemMeta().hasLore()) { + List lores = event.getCurrentItem().getItemMeta().getLore(); + if (lores.size() > 1) { + String permissions = lores.get(lores.size() - 2); + permissions = permissions.startsWith("§8§k") ? permissions.substring(4) : "noPermissions"; + String uuid = pm.getPlayerUUIDByName((Player) event.getWhoClicked()); + if (permissions.length() == 0 || event.getWhoClicked().hasPermission(permissions)) { + if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) { + String itemName = event.getCurrentItem().getItemMeta().getDisplayName(); + PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid); + if (itemName.startsWith(StrUtil.messageFormat(LangCfg.TAG_COLOR_ITEM_NAME + "§1§r "))) { + playerTag.setNamecolor(lores.get(lores.size() - 1).substring(2)); + } else if (itemName.startsWith(StrUtil.messageFormat(LangCfg.TAG_PREFIX_ITEM_NAME + "§2§r "))) { + playerTag.setPrefix(lores.get(lores.size() - 1).substring(2)); + } else if (itemName.startsWith(StrUtil.messageFormat(LangCfg.TAG_SUFFIX_ITEM_NAME + "§3§r "))) { + playerTag.setSuffix(lores.get(lores.size() - 1).substring(2)); + } else { + ((Player) event.getWhoClicked()).sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION)); + event.setCancelled(true); + return; + } + playerTag.setPlayerDisplayName((Player) event.getWhoClicked(), true); + playerTag.saveConfig(); + ((Player) event.getWhoClicked()).sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TAG_SET_SUCCESS)); event.setCancelled(true); return; } - playerTag.setPlayerDisplayName((Player) event.getWhoClicked(), true); - playerTag.saveConfig(); - event.getWhoClicked().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TAG_SET_SUCCESS)); - event.setCancelled(true); - return; } + ((Player) event.getWhoClicked()).sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION)); } - event.getWhoClicked().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_PERMISSION)); } + } catch (Exception e) { + e.printStackTrace(); } event.setCancelled(true); } diff --git a/src/main/gg/frog/mc/nametags/model/PlayerTagBean.java b/src/main/gg/frog/mc/nametags/model/PlayerTagBean.java index 0648976..fcaf0f5 100644 --- a/src/main/gg/frog/mc/nametags/model/PlayerTagBean.java +++ b/src/main/gg/frog/mc/nametags/model/PlayerTagBean.java @@ -69,7 +69,7 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl } public static void initPlayerTag(Player player, PluginMain pm) { - String uuid = pm.getPlayerUUIDByName(player.getName()); + String uuid = pm.getPlayerUUIDByName(player); PlayerTagBean playerTag = null; if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) { playerTag = TagNameCfg.PLAYER_TAG.get(uuid); @@ -164,7 +164,6 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl 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); } diff --git a/src/main/gg/frog/mc/nametags/placeholder/TagPlaceholder.java b/src/main/gg/frog/mc/nametags/placeholder/TagPlaceholder.java index b736813..c9f552c 100644 --- a/src/main/gg/frog/mc/nametags/placeholder/TagPlaceholder.java +++ b/src/main/gg/frog/mc/nametags/placeholder/TagPlaceholder.java @@ -38,7 +38,7 @@ public class TagPlaceholder extends PlaceholderExpansion { public String onPlaceholderRequest(Player player, String identifier) { if (PluginCfg.TAG_SYSTEM && player != null) { - String uuid = pm.getPlayerUUIDByName(player.getName()); + String uuid = pm.getPlayerUUIDByName(player); PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid); if (playerTag != null) { if (identifier.equalsIgnoreCase("fullname")) { diff --git a/src/main/gg/frog/mc/permissionstime/command/MeCmd.java b/src/main/gg/frog/mc/permissionstime/command/MeCmd.java index f4b7b38..eb02dea 100644 --- a/src/main/gg/frog/mc/permissionstime/command/MeCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/MeCmd.java @@ -34,7 +34,7 @@ public class MeCmd implements Runnable { if (isPlayer) { if (args.length == 1) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); - String uuid = pm.getPlayerUUIDByName(sender.getName()); + String uuid = pm.getPlayerUUIDByName((Player) sender); List ps = sm.getTime(uuid); PlayerPermissionShow.show((Player) sender, ps); } else { diff --git a/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java b/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java index bb8da46..8263c54 100644 --- a/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java +++ b/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java @@ -72,7 +72,7 @@ public class PackagesCfg extends PluginConfig { } for (Player player : pm.getServer().getOnlinePlayers()) { try { - String uuid = pm.getPlayerUUIDByName(player.getName()); + String uuid = pm.getPlayerUUIDByName(player); List pdbList = pm.getSqlManager().getTime(uuid); PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm, false); } catch (Exception e) { diff --git a/src/main/gg/frog/mc/permissionstime/listener/PtListener.java b/src/main/gg/frog/mc/permissionstime/listener/PtListener.java index a210d8c..093ab54 100644 --- a/src/main/gg/frog/mc/permissionstime/listener/PtListener.java +++ b/src/main/gg/frog/mc/permissionstime/listener/PtListener.java @@ -28,7 +28,7 @@ public class PtListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onJoin(PlayerLoginEvent event) { try { - String uuid = pm.getPlayerUUIDByName(event.getPlayer().getName()); + String uuid = pm.getPlayerUUIDByName(event.getPlayer()); List pdbList = pm.getSqlManager().getTime(uuid); PermissionPackageBean.reloadPlayerPermissions(event.getPlayer(), pdbList, pm, false); } catch (Exception e) { diff --git a/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java b/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java index 72052ed..ebfd978 100644 --- a/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java +++ b/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java @@ -267,7 +267,7 @@ public class PermissionPackageBean implements IConfigBean { addPpb.givePlayer(player, pm.getServer(), pm.getPermission()); } checkExpire(player, pm); - String uuid = pm.getPlayerUUIDByName(player.getName()); + String uuid = pm.getPlayerUUIDByName(player.getPlayer()); BukkitTask task = taskMap.get(uuid); if (pdbList.size() > 0) { delay = (delay / 1000 + 1) * 20;// 1秒=20ticks @@ -299,7 +299,7 @@ public class PermissionPackageBean implements IConfigBean { subPpb.clearPlayer(player, pm.getServer(), pm.getPermission()); } }); - String uuid = pm.getPlayerUUIDByName(player.getName()); + String uuid = pm.getPlayerUUIDByName(player.getPlayer()); BukkitTask task = taskMap.get(uuid); if (task != null) { pm.getServer().getScheduler().cancelTask(task.getTaskId()); @@ -307,7 +307,7 @@ public class PermissionPackageBean implements IConfigBean { } public static void checkExpire(OfflinePlayer player, PluginMain pm) { - String uuid = pm.getPlayerUUIDByName(player.getName()); + String uuid = pm.getPlayerUUIDByName(player.getPlayer()); List playerDataList = pm.getSqlManager().getAllTime(uuid); long now = new Date().getTime(); for (PlayerDataBean playerData : playerDataList) { diff --git a/src/resources/plugin.yml b/src/resources/plugin.yml index de8c166..54645fc 100644 --- a/src/resources/plugin.yml +++ b/src/resources/plugin.yml @@ -1,5 +1,5 @@ name: ${project.name} -version: 0.4.2-SNAPSHOT-b1002 +version: 0.4.3-SNAPSHOT-b1005 main: gg.frog.mc.base.PluginMain author: - GeekFrog diff --git a/帖子代码.txt b/帖子代码.txt index 7e105a1..b796acd 100644 --- a/帖子代码.txt +++ b/帖子代码.txt @@ -371,29 +371,5 @@ cmd: [tr][td][align=center][size=6][color=#ffffff][b]使用统计[/b][/color][/size][/align][/td][/tr] [/table][/align][align=center][table=98%,gray] [tr][td][align=center][url=https://bstats.org/plugin/bukkit/PermissionsTime][size=4][b]https://bstats.org/plugin/bukkit/PermissionsTime[/b][/size][/url][/align][/td][/tr] -[/table][/align][align=center][table=98%,#4169e1] -[tr][td][align=center][size=6][color=#ffffff][b]此插件已加入我的世界公益插件计划[/b][/color][/size][/align][/td][/tr] -[/table][/align][align=center][table=98%,gray] -[tr][td][spoiler] -[color=#ffffff][b][size=6]项目简介[/size][/b] - -[size=4]我的世界公益插件计划(Minecraft Public Welfare Plugin)是一项我的世界公益性多人联机插件扶持计划。[/size] -[size=4]由沉寂(1582952890)发起、策划、组织及执行。[/size] -[size=4]本计划旨在更多优秀的想法、点子能够顺利实现以推动我的世界多人联机方面的创新和发展。[/size] - -[b][size=6]项目须知[/size][/b] - -[size=4]提供完整的功能描述和实现意图,若是搬运其他游戏及平台的功能请提供示例或相似演示。[/size] -[size=4]请勿提供使用范围不广的想法、点子,甚至是个人服务器所需的功能。[/size] -[size=4]并非满足以上条件便一定会立项,我们会尽最大努力完成大家提供的项目;如若没有完成或出现其他问题,敬请谅解。[/size] -[size=4]我们团队的所有项目均是公益性的,不会向任何人索取任何金额的报酬、劳务费,并且原则上均开源。[/size] -[size=4]我们团队是由来自各地的志愿者组成的,没有工资薪酬,只有为了自己那颗执着又不甘平凡的心而埋头苦干。[/size] -[size=4]我们团队欢迎所有来自各地的志愿者加入,我们不侵犯、不伤害、不歧视,因为加入团队就意味着我们有着共同的奋斗目标。[/size] -[size=4]我的世界公益插件计划项目最终解释权由本团队所有。[/size] - -[size=6][b]联系我们[/b][/size] -[size=4]邮箱:[/size][size=4][url=mailto:master@mcplugin.org]master@mcplugin.org[/url][/size] -[size=4]QQ交流群:662367867[/size][/color] -[/spoiler][/td][/tr] [/table][/align][/td][/tr] [/table][/font][/align] \ No newline at end of file