76 lines
2.7 KiB
Java
76 lines
2.7 KiB
Java
package com.io.yutian.thewardungeon.gui;
|
|
|
|
import com.io.yutian.thewardungeon.dungeon.Dungeon;
|
|
import com.io.yutian.thewardungeon.dungeon.DungeonInstance;
|
|
import com.io.yutian.thewarskyblocklib.gui.Gui;
|
|
import com.io.yutian.thewarskyblocklib.gui.button.Button;
|
|
import com.io.yutian.thewarskyblocklib.gui.button.ClickType;
|
|
import com.io.yutian.thewarskyblocklib.util.ItemStackBuilder;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class DungeonRoomGui extends Gui {
|
|
|
|
private static int[] array = new int[] {0,1,2,3,4,5,6,7,8,9,17,18,26,27,35,36,44,45,46,47,48,49,50,51,52,53};
|
|
private static int[] array1 = new int[] {10,11,12,13,14,15,16,19,20,21,22,23,24,25,28,29,30,31,32,33,34,37,38,39,40,41,42,43};
|
|
|
|
private static List<DungeonRoomGui> guis = new ArrayList<>();
|
|
|
|
private Dungeon dungeon;
|
|
|
|
public DungeonRoomGui(Player player, Dungeon dungeon) {
|
|
super(player, "房间列表", 54);
|
|
this.dungeon = dungeon;
|
|
init();
|
|
initButton();
|
|
}
|
|
|
|
@Override
|
|
public void init() {
|
|
ItemStack item0 = new ItemStackBuilder(Material.GRAY_STAINED_GLASS_PANE).setDisplayName("§7 ").build();
|
|
for (int i : array) {
|
|
addButton(i, new Button(item0));
|
|
}
|
|
int i = 0;
|
|
for (DungeonInstance dungeonInstance : dungeon.getQueue().getAllFreeDungeonInstance()) {
|
|
if (i >= array1.length) {
|
|
break;
|
|
}
|
|
addButton(array1[i], build(dungeonInstance));
|
|
i++;
|
|
}
|
|
}
|
|
|
|
private Button build(DungeonInstance dungeonInstance) {
|
|
return new Button(new ItemStackBuilder(Material.WHITE_STAINED_GLASS_PANE).setDisplayName("§7#"+dungeonInstance.getId()).addLore(" ", "§a创建者: §f"+dungeonInstance.getPlayers().get(0).getPlayer().getName(), "§a人数: §f"+dungeonInstance.getPlayers().size()+"/"+dungeonInstance.getDungeon().getConfig().getOption().getMax(), " ", "§e点击加入").build()).click((player1, clickType) -> {
|
|
if (clickType.equals(ClickType.LEFT_CLICK)) {
|
|
if (!dungeon.getConfig().getConditionGroup().isValid(player)) {
|
|
return;
|
|
}
|
|
if (!dungeonInstance.canJoin(player1)) {
|
|
return;
|
|
}
|
|
dungeonInstance.join(player1, false);
|
|
player1.closeInventory();
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void open() {
|
|
super.open();
|
|
guis.add(this);
|
|
}
|
|
|
|
@Override
|
|
public void close(InventoryCloseEvent event) {
|
|
super.close(event);
|
|
guis.remove(this);
|
|
}
|
|
}
|