Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
更新到 1.5.3: 添加了 getViewers 函数, 以及修复了 GUI 卸载玩家物品栏并没有关闭的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
u2g committed Nov 27, 2016
1 parent 21e3796 commit 0a4b02f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 8 additions & 0 deletions src/com/minecraft/moonlake/gui/api/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -57,6 +58,13 @@ public interface GUI {
*/
int getSize();

/**
* 获取此 GUI 的查看者
*
* @return 查看者
*/
List<Player> getViewers();

/**
* 创建指定索引为按钮对象
*
Expand Down
28 changes: 28 additions & 0 deletions src/com/minecraft/moonlake/gui/util/GUIReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,6 +112,26 @@ public int getSize() {
return sizeProperty.get();
}

/**
* 获取此 GUI 的查看者
*
* @return 查看者
*/
@Override
public List<Player> getViewers() {

List<Player> viewerList = new ArrayList<>();

for(final HumanEntity entity : inventoryProperty.get().getViewers()) {

if(entity instanceof Player) {

viewerList.add((Player) entity);
}
}
return viewerList;
}

/**
* 创建指定索引为按钮对象
*
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 0a4b02f

Please sign in to comment.