From 277d091ce79092e57a278cc88ba91f91803ea7a4 Mon Sep 17 00:00:00 2001 From: GeekFrog Date: Sun, 16 Jul 2017 07:35:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dgui=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../mc/permissionstime/command/MainCommand.java | 15 +++++++++++++++ .../permissionstime/gui/PlayerPermissionShow.java | 5 ++--- .../mc/permissionstime/listener/MainListener.java | 8 ++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ec0ff39..777f5d5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ - **调用vault API 设置玩家权限 -- 登录时(添加 移除)、游戏中(命令添加/移除 延迟移除)、退出时移除** - **mysql保存数据** - **支持跨服** -- **gui显示自己的权限包**(可以拿出gui的物品, 有待处理) +- **gui显示自己的权限包** - 手动删除过期的或无效数据 - 语言支持整理 diff --git a/src/main/gg/frog/mc/permissionstime/command/MainCommand.java b/src/main/gg/frog/mc/permissionstime/command/MainCommand.java index 024877c..41450a2 100644 --- a/src/main/gg/frog/mc/permissionstime/command/MainCommand.java +++ b/src/main/gg/frog/mc/permissionstime/command/MainCommand.java @@ -4,6 +4,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.config.LangCfg; @@ -37,6 +38,12 @@ public class MainCommand implements CommandExecutor { if (isPlayer) { Player player = (Player) sender; if (sender.isOp() || player.hasPermission("permissionstime.reload")) { + for (Player p : pm.getServer().getOnlinePlayers()) { + InventoryView inventory = p.getOpenInventory(); + if (StrUtil.messageFormat("&4===权限仓库===" + "&r&5&9&2&0&r").equals(inventory.getTitle())) { + inventory.close(); + } + } pm.getConfigManager().reloadConfig(); if (!sm.updateDatabase()) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "数据库异常")); @@ -47,6 +54,14 @@ public class MainCommand implements CommandExecutor { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.NO_PERMISSION)); } } else { + for (Player p : pm.getServer().getOnlinePlayers()) { + InventoryView inventory = p.getOpenInventory(); + if (inventory != null) { + if (StrUtil.messageFormat("&4===权限仓库===" + "&r&5&9&2&0&r").equals(inventory.getTitle())) { + inventory.close(); + } + } + } pm.getConfigManager().reloadConfig(); if (!sm.updateDatabase()) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "数据库异常")); diff --git a/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java b/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java index 643d024..f19fb61 100644 --- a/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java +++ b/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java @@ -5,7 +5,6 @@ import java.util.List; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -16,7 +15,7 @@ import gg.frog.mc.permissionstime.utils.StrUtil; public class PlayerPermissionShow { public static void show(Player p, List pdbList) { - Inventory inventory = Bukkit.createInventory(null, (pdbList.size() % 9 == 0 ? pdbList.size() : (pdbList.size() / 9 + 1) * 9), StrUtil.messageFormat("&4你共有{0}种权限包", pdbList.size())); + Inventory inventory = Bukkit.createInventory(null, (pdbList.size() % 9 == 0 ? pdbList.size() : (pdbList.size() / 9 + 1) * 9), StrUtil.messageFormat("&4===权限仓库===" + "&r&5&9&2&0&r")); for (PlayerDataBean pdb : pdbList) { ItemStack item = PackagesCfg.PACKAGE_ITEMS.get(pdb.getPackageName()); if (item != null) { @@ -29,6 +28,6 @@ public class PlayerPermissionShow { inventory.addItem(item); } } - InventoryView view = p.openInventory(inventory); + p.openInventory(inventory); } } diff --git a/src/main/gg/frog/mc/permissionstime/listener/MainListener.java b/src/main/gg/frog/mc/permissionstime/listener/MainListener.java index 9499501..4ae9e9a 100644 --- a/src/main/gg/frog/mc/permissionstime/listener/MainListener.java +++ b/src/main/gg/frog/mc/permissionstime/listener/MainListener.java @@ -4,6 +4,7 @@ import java.util.List; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -70,4 +71,11 @@ public class MainListener implements Listener { } }).start(); } + + @EventHandler + public void onPlayerClick(InventoryClickEvent event) { + if (StrUtil.messageFormat("&4===权限仓库===" + "&r&5&9&2&0&r").equals(event.getInventory().getName())) { + event.setCancelled(true); + } + } }