Rework the GUI
This commit is contained in:
parent
5d24b5a6ee
commit
8847430ed9
|
|
@ -1,17 +1,27 @@
|
|||
package com.alttd.cometskyblock.challenges;
|
||||
|
||||
import com.alttd.cometskyblock.gui.GUIInventory;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class ChallengesGUI extends GUIInventory {
|
||||
|
||||
public ChallengesGUI() {
|
||||
super();
|
||||
public ChallengesGUI(Island island) {
|
||||
super(island);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Inventory createInventory() { // TODO - config
|
||||
return Bukkit.createInventory(this, 54, MiniMessage.miniMessage().deserialize("<red>GUI"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(Player player) {
|
||||
makeMenuBar();
|
||||
super.decorate(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ package com.alttd.cometskyblock.commands.island;
|
|||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import com.alttd.cometskyblock.island.gui.IslandGUI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class IslandCommand extends PlayerSubCommand {
|
||||
|
|
@ -32,26 +34,38 @@ public class IslandCommand extends PlayerSubCommand {
|
|||
|
||||
@Override
|
||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||
MessageConfiguration.Commands.Island.Help help = plugin.messagesConfiguration().get().commands().island().help();
|
||||
// Todo - builder to check for perm and only add messages with permission
|
||||
player.sendRichMessage(
|
||||
help.intro() + "<newline>" +
|
||||
"<gold>/island go: </gold>" + help.go() + "<newline>" +
|
||||
"<gold>/island sethome: </gold>" + help.setHome() + "<newline>" +
|
||||
"<gold>/island restart: </gold>" + help.restart() + "<newline>" +
|
||||
"<gold>/island invite: </gold>" + help.invite() + "<newline>" +
|
||||
"<gold>/island accept: </gold>" + help.accept() + "<newline>" +
|
||||
"<gold>/island kick: </gold>" + help.kick() + "<newline>" +
|
||||
"<gold>/island setowner: </gold>" + help.setOwner() + "<newline>" +
|
||||
"<gold>/island leave: </gold>" + help.leave() + "<newline>" +
|
||||
"<gold>/island level: </gold>" + help.level() + "<newline>" +
|
||||
"<gold>/island members: </gold>" + help.members() + "<newline>" +
|
||||
"<gold>/island options: </gold>" + help.options() + "<newline>" +
|
||||
// "<gold>/island top: </gold>" + help.top() + "<newline>" +
|
||||
"<gold>/island visit: </gold>" + help.visit() + "<newline>" +
|
||||
"<gold>/island confirm: </gold>" + help.confirm() + "<newline>" +
|
||||
"<gold>/island challenges: </gold>" + help.challenges()
|
||||
);
|
||||
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 IslandGUI(island).open(player);
|
||||
// // TODO - move to Helpcommand - some commands should be removed and moved to the gui
|
||||
// MessageConfiguration.Commands.Island.Help help = plugin.messagesConfiguration().get().commands().island().help();
|
||||
// // Todo - builder to check for perm and only add messages with permission
|
||||
// player.sendRichMessage(
|
||||
// help.intro() + "<newline>" +
|
||||
// "<gold>/island go: </gold>" + help.go() + "<newline>" +
|
||||
// "<gold>/island sethome: </gold>" + help.setHome() + "<newline>" +
|
||||
// "<gold>/island restart: </gold>" + help.restart() + "<newline>" +
|
||||
// "<gold>/island invite: </gold>" + help.invite() + "<newline>" +
|
||||
// "<gold>/island accept: </gold>" + help.accept() + "<newline>" +
|
||||
// "<gold>/island kick: </gold>" + help.kick() + "<newline>" +
|
||||
// "<gold>/island setowner: </gold>" + help.setOwner() + "<newline>" +
|
||||
// "<gold>/island leave: </gold>" + help.leave() + "<newline>" +
|
||||
// "<gold>/island level: </gold>" + help.level() + "<newline>" +
|
||||
// "<gold>/island members: </gold>" + help.members() + "<newline>" +
|
||||
// "<gold>/island options: </gold>" + help.options() + "<newline>" +
|
||||
//// "<gold>/island top: </gold>" + help.top() + "<newline>" +
|
||||
// "<gold>/island visit: </gold>" + help.visit() + "<newline>" +
|
||||
// "<gold>/island confirm: </gold>" + help.confirm() + "<newline>" +
|
||||
// "<gold>/island challenges: </gold>" + help.challenges()
|
||||
// );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,7 @@ public class IslandGo extends PlayerSubCommand {
|
|||
player.sendRichMessage("<red>Could not load your island. Contact an administrator");
|
||||
return true;
|
||||
}
|
||||
World islandWorld = plugin.worldGenerator().loadIslandWorld(island.worldName());
|
||||
if (islandWorld == null) {
|
||||
player.sendRichMessage("<red>Could not load your islandWorld. Contact an administrator");
|
||||
return true;
|
||||
}
|
||||
player.teleportAsync(islandWorld.getSpawnLocation());
|
||||
island.teleport(player);
|
||||
return true;
|
||||
}
|
||||
player.sendRichMessage("Generating a new island...");
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ package com.alttd.cometskyblock.commands.island;
|
|||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class IslandInvite extends PlayerSubCommand {
|
||||
|
|
@ -13,6 +16,26 @@ public class IslandInvite extends PlayerSubCommand {
|
|||
|
||||
@Override
|
||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||
MessageConfiguration.Commands.Island.Invite invite = plugin.messagesConfiguration().get().commands().island().invite();
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(plugin.messagesConfiguration().get().commands().island().commandUsage());
|
||||
return true;
|
||||
}
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (player == target) {
|
||||
// can't invite self
|
||||
return true;
|
||||
}
|
||||
if (target == null) {
|
||||
// target offline
|
||||
return true;
|
||||
}
|
||||
IslandPlayer islandPlayer1 = IslandPlayer.getIslandPlayer(target.getUniqueId());
|
||||
if (islandPlayer1.islandId() == 0) {
|
||||
// target does not have an island
|
||||
return true;
|
||||
}
|
||||
// send island invite request
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class IslandMembers extends PlayerSubCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
new MembersGUI().open(player);
|
||||
new MembersGUI(island).open(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package com.alttd.cometskyblock.gui;
|
||||
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
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.event.inventory.InventoryCloseEvent;
|
||||
|
|
@ -12,23 +15,24 @@ import org.bukkit.inventory.InventoryHolder;
|
|||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
// TODO - load the gui from a dependency and share basic info
|
||||
// TODO - Review all GUI and check if they are missing features ...
|
||||
public abstract class GUIInventory implements GUI, InventoryHolder {
|
||||
|
||||
private final Inventory inventory;
|
||||
private final Map<Integer, GUIButton> buttons = new HashMap<>();
|
||||
protected int currentSlot = 0;
|
||||
protected int pageIndex = 0;
|
||||
protected Island island;
|
||||
|
||||
public GUIInventory() {
|
||||
public GUIInventory(Island island) {
|
||||
this.inventory = this.createInventory();
|
||||
this.island = island;
|
||||
}
|
||||
|
||||
protected abstract Inventory createInventory();
|
||||
|
|
@ -95,6 +99,14 @@ public abstract class GUIInventory implements GUI, InventoryHolder {
|
|||
for (int i = inventory.getSize() - 9; i < inventory.getSize(); ++i) {
|
||||
addButton(i, createMenuButton(Material.BLACK_STAINED_GLASS_PANE, "", new ArrayList<>(), event -> {}));
|
||||
}
|
||||
makeTopBar();
|
||||
}
|
||||
|
||||
protected void makeTopBar() {
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
addButton(i, createMenuButton(Material.BLACK_STAINED_GLASS_PANE, "", new ArrayList<>(), event -> {}));
|
||||
}
|
||||
addButton(5, createPlayerHeadMenuButton(island.owner(), event -> {}));
|
||||
}
|
||||
|
||||
public void open(Player player) {
|
||||
|
|
@ -130,4 +142,24 @@ public abstract class GUIInventory implements GUI, InventoryHolder {
|
|||
addButton(slot, createMenuButton(Material.BARRIER, "<yellow>Exit Menu", new ArrayList<>(), event -> player.closeInventory()));
|
||||
}
|
||||
|
||||
protected GUIButton createPlayerHeadMenuButton(UUID uuid, Consumer<InventoryClickEvent> eventConsumer) {
|
||||
return new GUIButton()
|
||||
.creator(player -> createPlayerHead(uuid))
|
||||
.consumer(eventConsumer);
|
||||
}
|
||||
|
||||
protected 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package com.alttd.cometskyblock.island;
|
|||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
|
@ -155,8 +157,18 @@ public class Island extends YamlConfiguration {
|
|||
return getInt("island.generator.level", 0);
|
||||
}
|
||||
|
||||
public void cobblegenLevel(int id) {
|
||||
set("island.generator.level", id);
|
||||
public void cobblegenLevel(int level) {
|
||||
set("island.generator.level", level);
|
||||
save();
|
||||
}
|
||||
|
||||
public void teleport(Player player) {
|
||||
World islandWorld = CometSkyBlockPlugin.instance().worldGenerator().loadIslandWorld(worldName());
|
||||
if (islandWorld == null) {
|
||||
player.sendRichMessage("<red>Could not load islandWorld. Contact an administrator");
|
||||
return;
|
||||
}
|
||||
|
||||
player.teleportAsync(islandWorld.getSpawnLocation());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,48 @@
|
|||
package com.alttd.cometskyblock.island.gui;
|
||||
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class IslandGUI extends GUIInventory {
|
||||
|
||||
public IslandGUI() {
|
||||
super();
|
||||
public IslandGUI(Island island) {
|
||||
super(island);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Inventory createInventory() { // TODO - config
|
||||
return Bukkit.createInventory(this, 54, MiniMessage.miniMessage().deserialize("<red>GUI"));
|
||||
return Bukkit.createInventory(this, 27, MiniMessage.miniMessage().deserialize("<red>GUI"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(Player player) {
|
||||
makeMenuBar();
|
||||
|
||||
// Island GO
|
||||
addButton(10, createMenuButton(Material.GRASS_BLOCK, "Visit your island!", new ArrayList<>(), event -> {
|
||||
player.closeInventory();
|
||||
island.teleport(player);
|
||||
}));
|
||||
// Island Upgrades > WorldBorder | level | CobbleGen | Difficulty
|
||||
addButton(11, createMenuButton(Material.ANVIL, "Island Upgrades!", new ArrayList<>(), event -> {
|
||||
player.closeInventory();
|
||||
new UpgradesGUI(island).open(player);
|
||||
}));
|
||||
// Island Options >
|
||||
// Allow Visits | Visits need requests | Difficulty (after upgrade unlocked? show locked item?)
|
||||
addButton(12, createMenuButton(Material.ENCHANTED_BOOK, "Island Settings!", new ArrayList<>(), event -> {
|
||||
player.closeInventory();
|
||||
new SettingsGUI(island).open(player);
|
||||
}));
|
||||
super.decorate(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ import java.util.function.Consumer;
|
|||
|
||||
public class MembersGUI extends GUIInventory {
|
||||
|
||||
public MembersGUI() {
|
||||
super();
|
||||
public MembersGUI(Island island) {
|
||||
super(island);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -35,20 +35,6 @@ public class MembersGUI extends GUIInventory {
|
|||
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 -> {});
|
||||
|
|
@ -64,23 +50,4 @@ public class MembersGUI extends GUIInventory {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,26 @@
|
|||
package com.alttd.cometskyblock.island.gui;
|
||||
|
||||
import com.alttd.cometskyblock.gui.GUIInventory;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class SettingsGUI extends GUIInventory {
|
||||
|
||||
public SettingsGUI() {
|
||||
super();
|
||||
public SettingsGUI(Island island) {
|
||||
super(island);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Inventory createInventory() { // TODO - config
|
||||
return Bukkit.createInventory(this, 54, MiniMessage.miniMessage().deserialize("<red>GUI"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(Player player) {
|
||||
makeMenuBar();
|
||||
super.decorate(player);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,51 @@
|
|||
package com.alttd.cometskyblock.island.gui;
|
||||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.gui.GUIInventory;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldBorder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class UpgradesGUI extends GUIInventory {
|
||||
|
||||
public UpgradesGUI() {
|
||||
super();
|
||||
public UpgradesGUI(Island island) {
|
||||
super(island);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Inventory createInventory() { // TODO - config
|
||||
return Bukkit.createInventory(this, 54, MiniMessage.miniMessage().deserialize("<red>GUI"));
|
||||
return Bukkit.createInventory(this, 27, MiniMessage.miniMessage().deserialize("<red>GUI"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(Player player) {
|
||||
makeMenuBar();
|
||||
// Todo - move to handlers, add costs, validation ...
|
||||
// WorldBorder
|
||||
addButton(10, createMenuButton(Material.GRASS_BLOCK, "Expand The world border", new ArrayList<>(), event -> {
|
||||
World islandWorld = CometSkyBlockPlugin.instance().worldGenerator().loadIslandWorld(island.worldName());
|
||||
if (islandWorld == null) {
|
||||
player.sendRichMessage("<red>Could not load islandWorld. Contact an administrator");
|
||||
return;
|
||||
}
|
||||
WorldBorder worldBorder = islandWorld.getWorldBorder();
|
||||
worldBorder.setSize(worldBorder.getSize() + 250);
|
||||
}));
|
||||
// Cobble Gen
|
||||
addButton(11, createMenuButton(Material.COBBLESTONE, "Upgrade your cobble stone generator", new ArrayList<>(), event -> {
|
||||
island.cobblegenLevel(island.cobblegenLevel() + 1);
|
||||
}));
|
||||
// Level
|
||||
addButton(12, createMenuButton(Material.ENCHANTING_TABLE, "Increase your island level", new ArrayList<>(), event -> {}));
|
||||
// Difficulty
|
||||
super.decorate(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user