From 8025ea6a007e90543f39677a5dd9f68dd3618511 Mon Sep 17 00:00:00 2001 From: Daniel Scherf <35780068+dlsf@users.noreply.github.com> Date: Fri, 2 Jul 2021 20:30:42 +0200 Subject: [PATCH] Add support for inventory title placeholders (#229) * Add support for inventory title placeholders * Fix NoItemGUI usage * Moved where island is stored Co-authored-by: Peaches_MLG --- .../configs/inventories/NoItemGUI.java | 10 +++++--- .../iridium/iridiumskyblock/gui/BankGUI.java | 7 ++---- .../iridium/iridiumskyblock/gui/BiomeGUI.java | 8 +++---- .../iridiumskyblock/gui/BlockValueGUI.java | 2 +- .../iridiumskyblock/gui/BoostersGUI.java | 7 ++---- .../iridiumskyblock/gui/ConfirmationGUI.java | 2 +- .../com/iridium/iridiumskyblock/gui/GUI.java | 24 ++++++++++++++++--- .../gui/InventoryConfigGUI.java | 2 +- .../iridiumskyblock/gui/InvitesGUI.java | 8 +++---- .../iridiumskyblock/gui/IslandRanksGUI.java | 19 +++++++-------- .../iridiumskyblock/gui/IslandTopGUI.java | 2 +- .../iridium/iridiumskyblock/gui/LogsGUI.java | 11 ++++----- .../iridiumskyblock/gui/MembersGUI.java | 8 +++---- .../iridiumskyblock/gui/MissionsGUI.java | 10 ++++---- .../iridiumskyblock/gui/PermissionsGUI.java | 12 ++++------ .../iridiumskyblock/gui/RewardsGUI.java | 13 ++++------ .../iridiumskyblock/gui/SchematicGUI.java | 2 +- .../iridiumskyblock/gui/ShopOverviewGUI.java | 1 + .../iridiumskyblock/gui/TrustedGUI.java | 8 +++---- .../iridiumskyblock/gui/UpgradesGUI.java | 7 ++---- .../iridium/iridiumskyblock/gui/VisitGUI.java | 2 +- .../iridium/iridiumskyblock/gui/WarpsGUI.java | 12 ++++------ 22 files changed, 84 insertions(+), 93 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/inventories/NoItemGUI.java b/src/main/java/com/iridium/iridiumskyblock/configs/inventories/NoItemGUI.java index d27d7db54..a7a0ebaae 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/inventories/NoItemGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/inventories/NoItemGUI.java @@ -7,16 +7,20 @@ @NoArgsConstructor @AllArgsConstructor public class NoItemGUI { + /** - * The size of the GUI + * The size of the GUI. */ public int size; + /** - * The title of the GUI + * The title of the GUI. */ public String title; + /** - * The background of the GUI + * The background of the GUI. */ public Background background; + } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/BankGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/BankGUI.java index 27e8d3711..d6ab01f12 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/BankGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/BankGUI.java @@ -20,16 +20,13 @@ */ public class BankGUI extends GUI { - private final Island island; - /** * The default constructor. * * @param island The Island this GUI belongs to */ public BankGUI(@NotNull Island island) { - super(IridiumSkyblock.getInstance().getInventories().bankGUI); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().bankGUI, island); } @Override @@ -38,7 +35,7 @@ public void addContent(Inventory inventory) { InventoryUtils.fillInventory(inventory, getNoItemGUI().background); for (BankItem bankItem : IridiumSkyblock.getInstance().getBankItemList()) { - IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, bankItem); + IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(getIsland(), bankItem); inventory.setItem(bankItem.getItem().slot, ItemStackUtils.makeItem(bankItem.getItem(), Collections.singletonList(new Placeholder("amount", bankItem.toString(islandBank.getNumber()))))); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/BiomeGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/BiomeGUI.java index d26a39a14..364a0ddd2 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/BiomeGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/BiomeGUI.java @@ -24,16 +24,14 @@ public class BiomeGUI extends GUI { private final List biomes; private final int page; - private final Island island; private final World.Environment environment; private final CooldownProvider cooldownProvider; public BiomeGUI(int page, Island island, World.Environment environment, CooldownProvider cooldownProvider) { - super(IridiumSkyblock.getInstance().getInventories().biomeGUI); + super(IridiumSkyblock.getInstance().getInventories().biomeGUI, island); this.biomes = XBiome.VALUES.stream().filter(biome -> biome.getEnvironment() == environment).collect(Collectors.toList()); this.environment = environment; this.page = page; - this.island = island; this.cooldownProvider = cooldownProvider; } @@ -64,12 +62,12 @@ public void onInventoryClick(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); if (event.getSlot() == size - 7 && page > 1) { - player.openInventory(new BiomeGUI(page - 1, this.island, environment, cooldownProvider).getInventory()); + player.openInventory(new BiomeGUI(page - 1, getIsland(), environment, cooldownProvider).getInventory()); return; } if (event.getSlot() == size - 3 && (size - 9) * page < biomes.size()) { - player.openInventory(new BiomeGUI(page + 1, this.island, environment, cooldownProvider).getInventory()); + player.openInventory(new BiomeGUI(page + 1, getIsland(), environment, cooldownProvider).getInventory()); return; } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/BlockValueGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/BlockValueGUI.java index e7e1f129c..31a51ee12 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/BlockValueGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/BlockValueGUI.java @@ -31,7 +31,7 @@ public class BlockValueGUI extends GUI { * @param type The type of valuable block shown in this GUI */ public BlockValueGUI(BlockValueType type) { - super(IridiumSkyblock.getInstance().getInventories().blockValue); + super(IridiumSkyblock.getInstance().getInventories().blockValue, null); this.guiType = type; } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/BoostersGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/BoostersGUI.java index 17c7537ea..7cb2bffab 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/BoostersGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/BoostersGUI.java @@ -23,16 +23,13 @@ */ public class BoostersGUI extends GUI { - private final Island island; - /** * The default constructor. * * @param island The Island this GUI belongs to */ public BoostersGUI(@NotNull Island island) { - super(IridiumSkyblock.getInstance().getInventories().boostersGUI); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().boostersGUI, island); } @Override @@ -42,7 +39,7 @@ public void addContent(Inventory inventory) { for (Map.Entry entry : IridiumSkyblock.getInstance().getBoosterList().entrySet()) { Item item = entry.getValue().item; - IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island, entry.getKey()); + IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(getIsland(), entry.getKey()); long minutes = LocalDateTime.now().until(islandBooster.getTime(), ChronoUnit.MINUTES); long seconds = LocalDateTime.now().until(islandBooster.getTime(), ChronoUnit.SECONDS) - minutes * 60; inventory.setItem(item.slot, ItemStackUtils.makeItem(item, Arrays.asList( diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/ConfirmationGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/ConfirmationGUI.java index 5442fc6a8..1e062f996 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/ConfirmationGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/ConfirmationGUI.java @@ -25,7 +25,7 @@ public class ConfirmationGUI extends GUI { * @param cooldownProvider The provider for cooldowns that should be started on success */ public ConfirmationGUI(@NotNull Runnable runnable, @NotNull CooldownProvider cooldownProvider) { - super(IridiumSkyblock.getInstance().getInventories().confirmationGUI); + super(IridiumSkyblock.getInstance().getInventories().confirmationGUI, null); this.runnable = runnable; this.cooldownProvider = cooldownProvider; } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/GUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/GUI.java index 892e50aab..1c821b523 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/GUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/GUI.java @@ -2,29 +2,43 @@ import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; +import com.iridium.iridiumskyblock.PlaceholderBuilder; import com.iridium.iridiumskyblock.configs.inventories.NoItemGUI; -import lombok.AllArgsConstructor; +import com.iridium.iridiumskyblock.database.Island; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Represents a clickable GUI. * Base for all other classes in this package. */ -@AllArgsConstructor @NoArgsConstructor public abstract class GUI implements InventoryHolder { private NoItemGUI noItemGUI; + private @Nullable Island island; + + /** + * The default constructor. + * + * @param noItemGUI The NoItemGUI of this GUI + * @param island The island of this GUI. Can be null + */ + public GUI(@NotNull NoItemGUI noItemGUI, @Nullable Island island) { + this.noItemGUI = noItemGUI; + this.island = island; + } @NotNull @Override public Inventory getInventory() { - Inventory inventory = Bukkit.createInventory(this, noItemGUI.size, StringUtils.color(noItemGUI.title)); + String title = island == null ? noItemGUI.title : StringUtils.processMultiplePlaceholders(noItemGUI.title, new PlaceholderBuilder().applyIslandPlaceholders(island).build()); + Inventory inventory = Bukkit.createInventory(this, noItemGUI.size, StringUtils.color(title)); Bukkit.getScheduler().runTaskAsynchronously(IridiumSkyblock.getInstance(), () -> addContent(inventory)); @@ -47,4 +61,8 @@ public Inventory getInventory() { public NoItemGUI getNoItemGUI() { return noItemGUI; } + + public Island getIsland() { + return island; + } } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/InventoryConfigGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/InventoryConfigGUI.java index 29813ce7d..695170589 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/InventoryConfigGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/InventoryConfigGUI.java @@ -12,7 +12,7 @@ public class InventoryConfigGUI extends GUI { private final InventoryConfig inventoryConfig; public InventoryConfigGUI(InventoryConfig inventoryConfig) { - super(inventoryConfig); + super(inventoryConfig, null); this.inventoryConfig = inventoryConfig; } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/InvitesGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/InvitesGUI.java index a6b474905..c56728b06 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/InvitesGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/InvitesGUI.java @@ -21,7 +21,6 @@ */ public class InvitesGUI extends GUI { - private final Island island; private final HashMap invites; /** @@ -30,21 +29,20 @@ public class InvitesGUI extends GUI { * @param island The Island this GUI belongs to */ public InvitesGUI(@NotNull Island island) { - super(IridiumSkyblock.getInstance().getInventories().islandInvitesGUI); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().islandInvitesGUI, island); invites = new HashMap<>(); } @Override public void addContent(Inventory inventory) { - List islandInvites = IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().getEntries(island); + List islandInvites = IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().getEntries(getIsland()); inventory.clear(); InventoryUtils.fillInventory(inventory, getNoItemGUI().background); int i = 0; for (IslandInvite islandInvite : islandInvites) { - List placeholderList = new PlaceholderBuilder().applyPlayerPlaceholders(islandInvite.getUser()).applyIslandPlaceholders(island).build(); + List placeholderList = new PlaceholderBuilder().applyPlayerPlaceholders(islandInvite.getUser()).applyIslandPlaceholders(getIsland()).build(); placeholderList.add(new Placeholder("inviter", islandInvite.getInviter().getName())); placeholderList.add(new Placeholder("time", islandInvite.getTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat)))); inventory.setItem(i, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().islandInvitesGUI.item, placeholderList)); diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/IslandRanksGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/IslandRanksGUI.java index 7c0942557..450515800 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/IslandRanksGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/IslandRanksGUI.java @@ -21,16 +21,13 @@ */ public class IslandRanksGUI extends GUI { - private final Island island; - /** * The default constructor. * * @param island The Island this GUI belongs to */ public IslandRanksGUI(@NotNull Island island) { - super(IridiumSkyblock.getInstance().getInventories().islandRanksGUI); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().islandRanksGUI, island); } @Override @@ -38,9 +35,9 @@ public void addContent(Inventory inventory) { inventory.clear(); IslandRanksInventoryConfig islandRanks = IridiumSkyblock.getInstance().getInventories().islandRanksGUI; InventoryUtils.fillInventory(inventory, islandRanks.background); - List members = IridiumSkyblock.getInstance().getIslandManager().getIslandMembers(island); + List members = IridiumSkyblock.getInstance().getIslandManager().getIslandMembers(getIsland()); inventory.setItem(islandRanks.owner.slot, ItemStackUtils.makeItem(islandRanks.owner, - Collections.singletonList(new Placeholder("members", island.getOwner().getName())))); + Collections.singletonList(new Placeholder("members", getIsland().getOwner().getName())))); inventory.setItem(islandRanks.coOwner.slot, ItemStackUtils.makeItem(islandRanks.coOwner, Collections.singletonList(new Placeholder("members", members.stream().filter(member -> member.getIslandRank().equals(IslandRank.CO_OWNER)).map(User::getName).collect(Collectors.joining(", ")))))); inventory.setItem(islandRanks.moderator.slot, ItemStackUtils.makeItem(islandRanks.moderator, @@ -61,15 +58,15 @@ public void addContent(Inventory inventory) { public void onInventoryClick(InventoryClickEvent event) { IslandRanksInventoryConfig islandRanks = IridiumSkyblock.getInstance().getInventories().islandRanksGUI; if (event.getSlot() == islandRanks.owner.slot) - event.getWhoClicked().openInventory(new PermissionsGUI(island, IslandRank.OWNER).getInventory()); + event.getWhoClicked().openInventory(new PermissionsGUI(getIsland(), IslandRank.OWNER).getInventory()); else if (event.getSlot() == islandRanks.coOwner.slot) - event.getWhoClicked().openInventory(new PermissionsGUI(island, IslandRank.CO_OWNER).getInventory()); + event.getWhoClicked().openInventory(new PermissionsGUI(getIsland(), IslandRank.CO_OWNER).getInventory()); else if (event.getSlot() == islandRanks.moderator.slot) - event.getWhoClicked().openInventory(new PermissionsGUI(island, IslandRank.MODERATOR).getInventory()); + event.getWhoClicked().openInventory(new PermissionsGUI(getIsland(), IslandRank.MODERATOR).getInventory()); else if (event.getSlot() == islandRanks.member.slot) - event.getWhoClicked().openInventory(new PermissionsGUI(island, IslandRank.MEMBER).getInventory()); + event.getWhoClicked().openInventory(new PermissionsGUI(getIsland(), IslandRank.MEMBER).getInventory()); else if (event.getSlot() == islandRanks.visitor.slot) - event.getWhoClicked().openInventory(new PermissionsGUI(island, IslandRank.VISITOR).getInventory()); + event.getWhoClicked().openInventory(new PermissionsGUI(getIsland(), IslandRank.VISITOR).getInventory()); } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/IslandTopGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/IslandTopGUI.java index 110597ce6..bf0440005 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/IslandTopGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/IslandTopGUI.java @@ -26,7 +26,7 @@ public class IslandTopGUI extends GUI { * The default constructor. */ public IslandTopGUI() { - super(IridiumSkyblock.getInstance().getInventories().islandTopGUI); + super(IridiumSkyblock.getInstance().getInventories().islandTopGUI, null); } @Override diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/LogsGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/LogsGUI.java index c3c11ec90..7c8d66923 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/LogsGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/LogsGUI.java @@ -29,8 +29,6 @@ */ public class LogsGUI extends GUI { - private final Island island; - private int membersPage = 1; private int invitesPage = 1; private int trustsPage = 1; @@ -45,8 +43,7 @@ public class LogsGUI extends GUI { * @param island The Island this GUI belongs to */ public LogsGUI(@NotNull Island island) { - super(IridiumSkyblock.getInstance().getInventories().logsGUI); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().logsGUI, island); } @Override @@ -66,11 +63,11 @@ public void addContent(Inventory inventory) { } public void setItemStack(Inventory inventory, Item item, int page, LogAction... logActions) { - ItemStack itemStack = ItemStackUtils.makeItem(item, new PlaceholderBuilder().applyIslandPlaceholders(island).build()); + ItemStack itemStack = ItemStackUtils.makeItem(item, new PlaceholderBuilder().applyIslandPlaceholders(getIsland()).build()); ItemMeta itemMeta = itemStack.getItemMeta(); List lore = new ArrayList<>(); - List islandLogs = IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().getEntries(island).stream() + List islandLogs = IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().getEntries(getIsland()).stream() .filter(islandLog -> Arrays.stream(logActions).anyMatch(logAction -> logAction.equals(islandLog.getLogAction()))) .sorted(Comparator.comparing(IslandLog::getTime).reversed()) .collect(Collectors.toList()); @@ -192,7 +189,7 @@ public void onInventoryClick(InventoryClickEvent event) { } private boolean canChangePage(int page, int change, LogAction... logActions) { - List islandLogs = IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().getEntries(island).stream() + List islandLogs = IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().getEntries(getIsland()).stream() .filter(islandLog -> Arrays.stream(logActions).anyMatch(logAction -> logAction.equals(islandLog.getLogAction()))) .sorted(Comparator.comparing(IslandLog::getTime).reversed()) .collect(Collectors.toList()); diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/MembersGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/MembersGUI.java index a6d8e9ad1..8ce2228e4 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/MembersGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/MembersGUI.java @@ -18,7 +18,6 @@ */ public class MembersGUI extends GUI { - private final Island island; private final HashMap members; /** @@ -27,8 +26,7 @@ public class MembersGUI extends GUI { * @param island The Island this GUI belongs to */ public MembersGUI(@NotNull Island island) { - super(IridiumSkyblock.getInstance().getInventories().membersGUI); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().membersGUI, island); this.members = new HashMap<>(); } @@ -38,8 +36,8 @@ public void addContent(Inventory inventory) { InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().membersGUI.background); int i = 0; - for (User member : island.getMembers()) { - inventory.setItem(i, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().membersGUI.item, new PlaceholderBuilder().applyPlayerPlaceholders(member).applyIslandPlaceholders(island).build())); + for (User member : getIsland().getMembers()) { + inventory.setItem(i, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().membersGUI.item, new PlaceholderBuilder().applyPlayerPlaceholders(member).applyIslandPlaceholders(getIsland()).build())); members.put(i, member); i++; } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/MissionsGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/MissionsGUI.java index 1224f4dad..dbb125647 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/MissionsGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/MissionsGUI.java @@ -19,7 +19,6 @@ public class MissionsGUI extends GUI { - private final Island island; private final Mission.MissionType missionType; /** @@ -30,8 +29,7 @@ public class MissionsGUI extends GUI { * @see com.iridium.iridiumskyblock.Mission.MissionType */ public MissionsGUI(@NotNull Island island, @NotNull Mission.MissionType missionType) { - super(missionType == Mission.MissionType.DAILY ? IridiumSkyblock.getInstance().getInventories().dailyMissionGUI : IridiumSkyblock.getInstance().getInventories().missionsGUI); - this.island = island; + super(missionType == Mission.MissionType.DAILY ? IridiumSkyblock.getInstance().getInventories().dailyMissionGUI : IridiumSkyblock.getInstance().getInventories().missionsGUI, island); this.missionType = missionType; } @@ -41,14 +39,14 @@ public void addContent(Inventory inventory) { InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().missionsGUI.background); if (missionType == Mission.MissionType.DAILY) { - HashMap missions = IridiumSkyblock.getInstance().getIslandManager().getDailyIslandMissions(island); + HashMap missions = IridiumSkyblock.getInstance().getIslandManager().getDailyIslandMissions(getIsland()); int i = 0; for (Map.Entry entry : missions.entrySet()) { List placeholders = new ArrayList<>(); for (int j = 1; j <= entry.getValue().getMissions().size(); j++) { - IslandMission islandMission = IridiumSkyblock.getInstance().getIslandManager().getIslandMission(island, entry.getValue(), entry.getKey(), j); + IslandMission islandMission = IridiumSkyblock.getInstance().getIslandManager().getIslandMission(getIsland(), entry.getValue(), entry.getKey(), j); placeholders.add(new Placeholder("progress_" + j, String.valueOf(islandMission.getProgress()))); } if (IridiumSkyblock.getInstance().getMissions().dailySlots.size() > i) { @@ -64,7 +62,7 @@ public void addContent(Inventory inventory) { List placeholders = new ArrayList<>(); for (int j = 1; j <= entry.getValue().getMissions().size(); j++) { - IslandMission islandMission = IridiumSkyblock.getInstance().getIslandManager().getIslandMission(island, entry.getValue(), entry.getKey(), j); + IslandMission islandMission = IridiumSkyblock.getInstance().getIslandManager().getIslandMission(getIsland(), entry.getValue(), entry.getKey(), j); placeholders.add(new Placeholder("progress_" + j, String.valueOf(islandMission.getProgress()))); } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/PermissionsGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/PermissionsGUI.java index 37c0fb3b6..df63b168f 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/PermissionsGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/PermissionsGUI.java @@ -23,7 +23,6 @@ */ public class PermissionsGUI extends GUI { - private final Island island; private final IslandRank islandRank; /** @@ -33,8 +32,7 @@ public class PermissionsGUI extends GUI { * @param islandRank The rank which is being configured */ public PermissionsGUI(@NotNull Island island, @NotNull IslandRank islandRank) { - super(IridiumSkyblock.getInstance().getInventories().islandPermissionsGUI); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().islandPermissionsGUI, island); this.islandRank = islandRank; } @@ -44,7 +42,7 @@ public void addContent(Inventory inventory) { InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().islandPermissionsGUI.background); for (Map.Entry permission : IridiumSkyblock.getInstance().getPermissionList().entrySet()) { - boolean allowed = IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, islandRank, permission.getValue(), permission.getKey()); + boolean allowed = IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(getIsland(), islandRank, permission.getValue(), permission.getKey()); inventory.setItem(permission.getValue().getItem().slot, ItemStackUtils.makeItem(permission.getValue().getItem(), Collections.singletonList(new Placeholder("permission", allowed ? IridiumSkyblock.getInstance().getPermissions().allowed : IridiumSkyblock.getInstance().getPermissions().denied)))); } } @@ -61,11 +59,11 @@ public void onInventoryClick(InventoryClickEvent event) { if (permission.getValue().getItem().slot != event.getSlot()) continue; User user = IridiumSkyblock.getInstance().getUserManager().getUser((Player) event.getWhoClicked()); - if (user.getIslandRank().getLevel() <= islandRank.getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.CHANGE_PERMISSIONS)) { + if (user.getIslandRank().getLevel() <= islandRank.getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(getIsland(), user, PermissionType.CHANGE_PERMISSIONS)) { event.getWhoClicked().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotChangePermissions.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } else { - boolean allowed = IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, islandRank, permission.getValue(), permission.getKey()); - IridiumSkyblock.getInstance().getIslandManager().setIslandPermission(island, islandRank, permission.getValue(), permission.getKey(), !allowed); + boolean allowed = IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(getIsland(), islandRank, permission.getValue(), permission.getKey()); + IridiumSkyblock.getInstance().getIslandManager().setIslandPermission(getIsland(), islandRank, permission.getValue(), permission.getKey(), !allowed); event.getWhoClicked().openInventory(getInventory()); } return; diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/RewardsGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/RewardsGUI.java index aa70f6e01..1a7da5c62 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/RewardsGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/RewardsGUI.java @@ -16,11 +16,8 @@ public class RewardsGUI extends GUI { - private final Island island; - public RewardsGUI(Island island) { - super(IridiumSkyblock.getInstance().getInventories().islandReward); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().islandReward, island); } @Override @@ -29,20 +26,20 @@ public void addContent(Inventory inventory) { InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().islandReward.background); - List placeholders = new PlaceholderBuilder().applyIslandPlaceholders(island).build(); + List placeholders = new PlaceholderBuilder().applyIslandPlaceholders(getIsland()).build(); AtomicInteger atomicInteger = new AtomicInteger(0); - IridiumSkyblock.getInstance().getDatabaseManager().getIslandRewardTableManager().getEntries(island).forEach(islandReward -> + IridiumSkyblock.getInstance().getDatabaseManager().getIslandRewardTableManager().getEntries(getIsland()).forEach(islandReward -> inventory.setItem(atomicInteger.getAndIncrement(), ItemStackUtils.makeItem(islandReward.getReward().item, placeholders)) ); } @Override public void onInventoryClick(InventoryClickEvent event) { - List islandRewards = IridiumSkyblock.getInstance().getDatabaseManager().getIslandRewardTableManager().getEntries(island); + List islandRewards = IridiumSkyblock.getInstance().getDatabaseManager().getIslandRewardTableManager().getEntries(getIsland()); if (islandRewards.size() > event.getSlot()) { IslandReward islandReward = islandRewards.get(event.getSlot()); - islandReward.getReward().claim((Player) event.getWhoClicked(), island); + islandReward.getReward().claim((Player) event.getWhoClicked(), getIsland()); IridiumSkyblock.getInstance().getDatabaseManager().getIslandRewardTableManager().delete(islandReward); event.getWhoClicked().closeInventory(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/SchematicGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/SchematicGUI.java index ce254a8a6..d07925365 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/SchematicGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/SchematicGUI.java @@ -19,7 +19,7 @@ public abstract class SchematicGUI extends GUI { private final HashMap schematics = new HashMap<>(); public SchematicGUI() { - super(IridiumSkyblock.getInstance().getInventories().islandSchematicGUI); + super(IridiumSkyblock.getInstance().getInventories().islandSchematicGUI, null); } @Override diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/ShopOverviewGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/ShopOverviewGUI.java index c06b3967d..a3e3eed61 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/ShopOverviewGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/ShopOverviewGUI.java @@ -14,6 +14,7 @@ * GUI which shows all categories of the shop. */ public class ShopOverviewGUI extends GUI { + /** * Get the object's inventory. * diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/TrustedGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/TrustedGUI.java index e8df943d1..a7d51cb5d 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/TrustedGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/TrustedGUI.java @@ -21,7 +21,6 @@ */ public class TrustedGUI extends GUI { - private final Island island; private final HashMap members; /** @@ -30,8 +29,7 @@ public class TrustedGUI extends GUI { * @param island The Island this GUI belongs to */ public TrustedGUI(@NotNull Island island) { - super(IridiumSkyblock.getInstance().getInventories().trustedGUI); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().trustedGUI, island); this.members = new HashMap<>(); } @@ -41,10 +39,10 @@ public void addContent(Inventory inventory) { InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().trustedGUI.background); int i = 0; - List islandTrustedList = IridiumSkyblock.getInstance().getDatabaseManager().getIslandTrustedTableManager().getEntries(island); + List islandTrustedList = IridiumSkyblock.getInstance().getDatabaseManager().getIslandTrustedTableManager().getEntries(getIsland()); for (IslandTrusted islandTrusted : islandTrustedList) { List placeholderList = - new PlaceholderBuilder().applyPlayerPlaceholders(islandTrusted.getUser()).applyIslandPlaceholders(island).build(); + new PlaceholderBuilder().applyPlayerPlaceholders(islandTrusted.getUser()).applyIslandPlaceholders(getIsland()).build(); placeholderList.add(new Placeholder("trustee", islandTrusted.getTruster().getName())); inventory.setItem(i, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().trustedGUI.item, placeholderList)); members.put(i, islandTrusted.getUser()); diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/UpgradesGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/UpgradesGUI.java index 53aa08241..1983ce2e7 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/UpgradesGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/UpgradesGUI.java @@ -22,16 +22,13 @@ */ public class UpgradesGUI extends GUI { - private final Island island; - /** * The default constructor. * * @param island The Island this GUI belongs to */ public UpgradesGUI(@NotNull Island island) { - super(IridiumSkyblock.getInstance().getInventories().upgradesGUI); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().upgradesGUI, island); } @Override @@ -41,7 +38,7 @@ public void addContent(Inventory inventory) { for (Map.Entry upgrade : IridiumSkyblock.getInstance().getUpgradesList().entrySet()) { Item item = upgrade.getValue().item; - int level = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island, upgrade.getKey()).getLevel(); + int level = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(getIsland(), upgrade.getKey()).getLevel(); List placeholderList = new ArrayList<>(); placeholderList.add(new Placeholder("level", String.valueOf(level))); diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/VisitGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/VisitGUI.java index d2009d27f..206a37ef9 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/VisitGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/VisitGUI.java @@ -27,7 +27,7 @@ public class VisitGUI extends GUI { * @param page The current page of this GUI */ public VisitGUI(int page) { - super(IridiumSkyblock.getInstance().getInventories().visitGUI); + super(IridiumSkyblock.getInstance().getInventories().visitGUI, null); this.page = page; this.islands = IridiumSkyblock.getInstance().getDatabaseManager().getIslandTableManager().getEntries().stream().filter(Island::isVisitable).collect(Collectors.toList()); } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/WarpsGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/WarpsGUI.java index 0636c52f1..57dc5af8e 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/WarpsGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/WarpsGUI.java @@ -20,16 +20,13 @@ public class WarpsGUI extends GUI { - private final Island island; - /** * The default constructor. * * @param island The Island this GUI belongs to */ public WarpsGUI(@NotNull Island island) { - super(IridiumSkyblock.getInstance().getInventories().warpsGUI); - this.island = island; + super(IridiumSkyblock.getInstance().getInventories().warpsGUI, island); } @Override @@ -39,12 +36,12 @@ public void addContent(Inventory inventory) { AtomicInteger atomicInteger = new AtomicInteger(1); - List islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island); + List islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(getIsland()); Collections.reverse(islandWarps); for (IslandWarp islandWarp : islandWarps) { int slot = IridiumSkyblock.getInstance().getConfiguration().islandWarpSlots.get(atomicInteger.getAndIncrement()); ItemStack itemStack = ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().warpsGUI.item, Arrays.asList( - new Placeholder("island_name", island.getName()), + new Placeholder("island_name", getIsland().getName()), new Placeholder("warp_name", islandWarp.getName()), new Placeholder("description", islandWarp.getDescription() != null ? islandWarp.getDescription() : "") )); @@ -62,7 +59,7 @@ public void addContent(Inventory inventory) { */ @Override public void onInventoryClick(InventoryClickEvent event) { - List islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island); + List islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(getIsland()); Collections.reverse(islandWarps); AtomicInteger atomicInteger = new AtomicInteger(1); for (IslandWarp islandWarp : islandWarps) { @@ -82,4 +79,5 @@ public void onInventoryClick(InventoryClickEvent event) { } } } + }