From 0a4b02f7ac7ca02cf3c689a2f74aca444dbe047b Mon Sep 17 00:00:00 2001 From: u2g Date: Sun, 27 Nov 2016 13:37:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=B0=201.5.3:=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=20getViewers=20=E5=87=BD=E6=95=B0,?= =?UTF-8?q?=20=E4=BB=A5=E5=8F=8A=E4=BF=AE=E5=A4=8D=E4=BA=86=20GUI=20?= =?UTF-8?q?=E5=8D=B8=E8=BD=BD=E7=8E=A9=E5=AE=B6=E7=89=A9=E5=93=81=E6=A0=8F?= =?UTF-8?q?=E5=B9=B6=E6=B2=A1=E6=9C=89=E5=85=B3=E9=97=AD=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.yml | 2 +- src/com/minecraft/moonlake/gui/api/GUI.java | 8 ++++++ .../moonlake/gui/util/GUIReference.java | 28 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plugin.yml b/plugin.yml index 190d71b..eb6d13d 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: MoonLakeGUI main: com.minecraft.moonlake.gui.GUIPlugin -version: 1.5.2 +version: 1.5.3 author: Month_Light website: http://www.mcyszh.com diff --git a/src/com/minecraft/moonlake/gui/api/GUI.java b/src/com/minecraft/moonlake/gui/api/GUI.java index 7e96872..9d07aa1 100644 --- a/src/com/minecraft/moonlake/gui/api/GUI.java +++ b/src/com/minecraft/moonlake/gui/api/GUI.java @@ -28,6 +28,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.List; import java.util.Map; import java.util.Set; @@ -57,6 +58,13 @@ public interface GUI { */ int getSize(); + /** + * 获取此 GUI 的查看者 + * + * @return 查看者 + */ + List getViewers(); + /** * 创建指定索引为按钮对象 * diff --git a/src/com/minecraft/moonlake/gui/util/GUIReference.java b/src/com/minecraft/moonlake/gui/util/GUIReference.java index 2a38fab..819818a 100644 --- a/src/com/minecraft/moonlake/gui/util/GUIReference.java +++ b/src/com/minecraft/moonlake/gui/util/GUIReference.java @@ -38,6 +38,7 @@ import com.minecraft.moonlake.validate.Validate; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -111,6 +112,26 @@ public int getSize() { return sizeProperty.get(); } + /** + * 获取此 GUI 的查看者 + * + * @return 查看者 + */ + @Override + public List getViewers() { + + List viewerList = new ArrayList<>(); + + for(final HumanEntity entity : inventoryProperty.get().getViewers()) { + + if(entity instanceof Player) { + + viewerList.add((Player) entity); + } + } + return viewerList; + } + /** * 创建指定索引为按钮对象 * @@ -1558,6 +1579,13 @@ public void register() { @Deprecated public void unregister() { + for(final Player player : getViewers()) { + + if(player != null) { + + player.closeInventory(); + } + } GUIPlugin.getManagers().unregisterGUI(this); } }