Update IslandMembersGUI
This commit is contained in:
parent
8eb09282d2
commit
5d24b5a6ee
|
|
@ -2,7 +2,9 @@ package com.alttd.cometskyblock.commands.island;
|
||||||
|
|
||||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||||
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||||
|
import com.alttd.cometskyblock.island.Island;
|
||||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||||
|
import com.alttd.cometskyblock.island.gui.MembersGUI;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class IslandMembers extends PlayerSubCommand {
|
public class IslandMembers extends PlayerSubCommand {
|
||||||
|
|
@ -13,6 +15,18 @@ public class IslandMembers extends PlayerSubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||||
|
if (islandPlayer.islandId() == 0) {
|
||||||
|
// You need an island to be able to do this
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Island island = Island.getIsland(islandPlayer.islandUUID());
|
||||||
|
if (island == null) {
|
||||||
|
// "Could not load your island. Contact an administrator"
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
new MembersGUI().open(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,13 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
// TODO - load the gui from a dependency and share basic info
|
||||||
public abstract class GUIInventory implements GUI, InventoryHolder {
|
public abstract class GUIInventory implements GUI, InventoryHolder {
|
||||||
|
|
||||||
private final Inventory inventory;
|
private final Inventory inventory;
|
||||||
private final Map<Integer, GUIButton> buttons = new HashMap<>();
|
private final Map<Integer, GUIButton> buttons = new HashMap<>();
|
||||||
int currentSlot = 0;
|
protected int currentSlot = 0;
|
||||||
int pageIndex = 0;
|
protected int pageIndex = 0;
|
||||||
|
|
||||||
public GUIInventory() {
|
public GUIInventory() {
|
||||||
this.inventory = this.createInventory();
|
this.inventory = this.createInventory();
|
||||||
|
|
@ -62,7 +62,7 @@ public abstract class GUIInventory implements GUI, InventoryHolder {
|
||||||
this.buttons.put(slot, button);
|
this.buttons.put(slot, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decorate(Player player) {
|
protected void decorate(Player player) {
|
||||||
this.buttons.forEach((slot, button) -> {
|
this.buttons.forEach((slot, button) -> {
|
||||||
ItemStack icon = button.iconCreator().apply(player);
|
ItemStack icon = button.iconCreator().apply(player);
|
||||||
this.inventory.setItem(slot, icon);
|
this.inventory.setItem(slot, icon);
|
||||||
|
|
@ -91,7 +91,7 @@ public abstract class GUIInventory implements GUI, InventoryHolder {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeMenuBar() {
|
protected void makeMenuBar() {
|
||||||
for (int i = inventory.getSize() - 9; i < inventory.getSize(); ++i) {
|
for (int i = inventory.getSize() - 9; i < inventory.getSize(); ++i) {
|
||||||
addButton(i, createMenuButton(Material.BLACK_STAINED_GLASS_PANE, "", new ArrayList<>(), event -> {}));
|
addButton(i, createMenuButton(Material.BLACK_STAINED_GLASS_PANE, "", new ArrayList<>(), event -> {}));
|
||||||
}
|
}
|
||||||
|
|
@ -112,4 +112,22 @@ public abstract class GUIInventory implements GUI, InventoryHolder {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createPrevPageButton(Player player) {
|
||||||
|
addButton(48, createMenuButton(Material.PAPER, "<yellow><< Previous Page", new ArrayList<>(), event -> {
|
||||||
|
--pageIndex;
|
||||||
|
decorate(player);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createNextPageButton(Player player) {
|
||||||
|
addButton(50, createMenuButton(Material.PAPER, "<yellow>Next Page >>", new ArrayList<>(), event -> {
|
||||||
|
++pageIndex;
|
||||||
|
decorate(player);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createExitButton(Player player, int slot) {
|
||||||
|
addButton(slot, createMenuButton(Material.BARRIER, "<yellow>Exit Menu", new ArrayList<>(), event -> player.closeInventory()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,86 @@
|
||||||
package com.alttd.cometskyblock.island.gui;
|
package com.alttd.cometskyblock.island.gui;
|
||||||
|
|
||||||
|
import com.alttd.cometskyblock.gui.GUIButton;
|
||||||
import com.alttd.cometskyblock.gui.GUIInventory;
|
import com.alttd.cometskyblock.gui.GUIInventory;
|
||||||
|
import com.alttd.cometskyblock.island.Island;
|
||||||
|
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class MembersGUI extends GUIInventory {
|
public class MembersGUI extends GUIInventory {
|
||||||
|
|
||||||
public MembersGUI() {
|
public MembersGUI() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Inventory createInventory() { // TODO - config
|
protected Inventory createInventory() { // TODO - config
|
||||||
return Bukkit.createInventory(this, 54, MiniMessage.miniMessage().deserialize("<red>GUI"));
|
return Bukkit.createInventory(this, 54, MiniMessage.miniMessage().deserialize("<yellow>Island Members"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void decorate(Player player) {
|
||||||
|
currentSlot = 9;
|
||||||
|
makeMenuBar();
|
||||||
|
|
||||||
|
IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(player.getUniqueId());
|
||||||
|
if (islandPlayer.islandId() == 0) {
|
||||||
|
// You need an island to be able to do this
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Island island = Island.getIsland(islandPlayer.islandUUID());
|
||||||
|
if (island == null) {
|
||||||
|
// "Could not load your island. Contact an administrator"
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
addButton(5, createPlayerHeadMenuButton(island.owner(), event -> {}));
|
||||||
|
|
||||||
|
int startIndex = pageIndex * 45;
|
||||||
|
for (int i = startIndex; i < island.members().size(); i++) {
|
||||||
|
GUIButton guiButton = createPlayerHeadMenuButton(island.members().get(i), event -> {});
|
||||||
|
if (!addItem(guiButton)) {
|
||||||
|
createNextPageButton(player);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageIndex > 0) {
|
||||||
|
createPrevPageButton(player);
|
||||||
|
}
|
||||||
|
super.decorate(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUIButton createPlayerHeadMenuButton(UUID uuid, Consumer<InventoryClickEvent> eventConsumer) {
|
||||||
|
return new GUIButton()
|
||||||
|
.creator(player -> createPlayerHead(uuid))
|
||||||
|
.consumer(eventConsumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack createPlayerHead(UUID uuid) {
|
||||||
|
ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
|
||||||
|
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||||
|
if (!player.hasPlayedBefore())
|
||||||
|
return skull;
|
||||||
|
|
||||||
|
SkullMeta meta = (SkullMeta) skull.getItemMeta();
|
||||||
|
meta.setPlayerProfile(player.getPlayerProfile());
|
||||||
|
skull.setItemMeta(meta);
|
||||||
|
|
||||||
|
return skull;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user