From ed354f2aefb1cb8d270f177f176754608ba2cf04 Mon Sep 17 00:00:00 2001 From: Jonathan Boisclair Date: Wed, 29 Mar 2023 18:32:09 -0400 Subject: [PATCH] added mission sorting --- .../configs/Configuration.java | 72 ++++++++------- .../gui/IslandMissionsGUI.java | 88 +++++++++++++++---- 2 files changed, 110 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java b/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java index fe063ef0f..cda50514b 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java @@ -48,7 +48,7 @@ public class Configuration { public boolean backButtons = true; public boolean createIslandOnHome = true; public boolean putBackOnIslandLeave = false; - public boolean forceNetherGeneratorInNether=true; + public boolean forceNetherGeneratorInNether = true; public IslandRegenSettings regenSettings = new IslandRegenSettings(); @@ -57,7 +57,7 @@ public class Configuration { public IslandDamageSettings pvpSettings = new IslandDamageSettings(); public PerformanceSettings performance = new PerformanceSettings(); - + public ConfirmationSettings confirmation = new ConfirmationSettings(); public int distance = 151; @@ -71,9 +71,11 @@ public class Configuration { public int pasterLimitPerTick = 250000; public int pasterDelayInTick = 1; - public Item islandCrystal = new Item(XMaterial.NETHER_STAR, 1, "&b*** &b&lIsland Crystal &b***", Arrays.asList("", "&b%amount% Island Crystals", "&b&l[!] &bRight-Click to Redeem")); + public Item islandCrystal = new Item(XMaterial.NETHER_STAR, 1, "&b*** &b&lIsland Crystal &b***", + Arrays.asList("", "&b%amount% Island Crystals", "&b&l[!] &bRight-Click to Redeem")); public XSound islandLevelUpSound = XSound.ENTITY_PLAYER_LEVELUP; + public MissionSortBy sortMissionsBy = MissionSortBy.KEY; public NumberFormatter numberFormatter = new NumberFormatter(); @@ -102,33 +104,44 @@ public class Configuration { /** * The Rewards the island gets for leveling up - * The integer represents the reward they will get, if the island level is divisible by this number they will get that reward + * The integer represents the reward they will get, if the island level is + * divisible by this number they will get that reward * Higest number takes priority *

- * e.g. 1 will give the reward to every level since every number is divisible by 1 - * 5 will give the reward to levels 5 10 15 20 25 ect since they are divisible by 5 + * e.g. 1 will give the reward to every level since every number is divisible by + * 1 + * 5 will give the reward to levels 5 10 15 20 25 ect since they are divisible + * by 5 */ public Map islandLevelRewards = ImmutableMap.builder() - .put(1, new Reward(new Item(XMaterial.EXPERIENCE_BOTTLE, 1, "&b&lLevel %island_level% Reward", Arrays.asList( - "&7Island Level %island_level% Rewards:", - "&b&l* &b5 Island Crystals", - "&b&l* &b200 Island Money", - "", - "&b&l[!] &bLeft click to redeem" - )), Collections.emptyList(), 0, 5, 200, 0, XSound.ENTITY_PLAYER_LEVELUP)) - - .put(5, new Reward(new Item(XMaterial.EXPERIENCE_BOTTLE, 1, "&b&lLevel %island_level% Reward", Arrays.asList( - "&7Island Level %island_level% Rewards:", - "&b&l* &b15 Island Crystals", - "&b&l* &b2000 Island Money", - "", - "&b&l[!] &bLeft click to redeem" - )), Collections.emptyList(), 0, 15, 2000, 0, XSound.ENTITY_PLAYER_LEVELUP)) + .put(1, new Reward( + new Item(XMaterial.EXPERIENCE_BOTTLE, 1, "&b&lLevel %island_level% Reward", Arrays.asList( + "&7Island Level %island_level% Rewards:", + "&b&l* &b5 Island Crystals", + "&b&l* &b200 Island Money", + "", + "&b&l[!] &bLeft click to redeem")), + Collections.emptyList(), 0, 5, 200, 0, XSound.ENTITY_PLAYER_LEVELUP)) + + .put(5, new Reward( + new Item(XMaterial.EXPERIENCE_BOTTLE, 1, "&b&lLevel %island_level% Reward", Arrays.asList( + "&7Island Level %island_level% Rewards:", + "&b&l* &b15 Island Crystals", + "&b&l* &b2000 Island Money", + "", + "&b&l[!] &bLeft click to redeem")), + Collections.emptyList(), 0, 15, 2000, 0, XSound.ENTITY_PLAYER_LEVELUP)) .build(); + public enum MissionSortBy { + KEY, DISPLAYNAME, SLOT, FILE + } + /** - * Settings for the {@link org.bukkit.generator.ChunkGenerator} of IridiumSkyblock. - * Allows fine-tuning of the {@link com.iridium.iridiumskyblock.generators.OceanGenerator}. + * Settings for the {@link org.bukkit.generator.ChunkGenerator} of + * IridiumSkyblock. + * Allows fine-tuning of the + * {@link com.iridium.iridiumskyblock.generators.OceanGenerator}. */ @AllArgsConstructor @NoArgsConstructor @@ -182,7 +195,6 @@ public static class IslandDeleteSettings { } - /** * The default settings for performance. */ @@ -203,7 +215,7 @@ public static class PerformanceSettings { public boolean disableLeavesDecayCheck = false; } - /** + /** * The default settings for confirmation. */ @AllArgsConstructor @@ -212,8 +224,8 @@ public static class ConfirmationSettings { public boolean islandRegen = true; public boolean warpDeletion = true; public boolean clearData = true; - public boolean islandDelete=true; - public boolean islandLeave=true; + public boolean islandDelete = true; + public boolean islandLeave = true; } @AllArgsConstructor @@ -226,8 +238,7 @@ public static class IslandDamageSettings { public List membersPreventedDamages = Arrays.asList( EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, - EntityDamageEvent.DamageCause.BLOCK_EXPLOSION - ); + EntityDamageEvent.DamageCause.BLOCK_EXPLOSION); public List visitorsPreventedDamages = Arrays.asList( EntityDamageEvent.DamageCause.PROJECTILE, @@ -243,8 +254,7 @@ public static class IslandDamageSettings { EntityDamageEvent.DamageCause.HOT_FLOOR, EntityDamageEvent.DamageCause.LAVA, EntityDamageEvent.DamageCause.CONTACT, - EntityDamageEvent.DamageCause.FIRE_TICK - ); + EntityDamageEvent.DamageCause.FIRE_TICK); } diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/IslandMissionsGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/IslandMissionsGUI.java index c2e160c22..93fd9fddf 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/IslandMissionsGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/IslandMissionsGUI.java @@ -1,22 +1,34 @@ package com.iridium.iridiumskyblock.gui; +import com.iridium.iridiumcore.gui.PagedGUI; import com.iridium.iridiumcore.utils.InventoryUtils; import com.iridium.iridiumcore.utils.ItemStackUtils; import com.iridium.iridiumcore.utils.Placeholder; +import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.Mission; +import com.iridium.iridiumskyblock.configs.inventories.NoItemGUI; import com.iridium.iridiumskyblock.database.Island; +import com.iridium.iridiumskyblock.database.User; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import java.util.Collection; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.IntStream; -public class IslandMissionsGUI extends IslandGUI { +public class IslandMissionsGUI extends PagedGUI> { + + private final Island island; /** * The default constructor. @@ -24,30 +36,68 @@ public class IslandMissionsGUI extends IslandGUI { * @param island The Island this GUI belongs to */ public IslandMissionsGUI(@NotNull Island island, Inventory previousInventory) { - super(IridiumSkyblock.getInstance().getInventories().missionsGUI, previousInventory, island); + super(1, + IridiumSkyblock.getInstance().getInventories().missionsGUI.size, + IridiumSkyblock.getInstance().getInventories().missionsGUI.background, + IridiumSkyblock.getInstance().getInventories().previousPage, + IridiumSkyblock.getInstance().getInventories().nextPage, + previousInventory, + IridiumSkyblock.getInstance().getInventories().backButton); + this.island = island; } + @NotNull @Override - public void addContent(Inventory inventory) { - inventory.clear(); - InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().missionsGUI.background); - - AtomicInteger slot = new AtomicInteger(0); - for (Map.Entry entry : IridiumSkyblock.getInstance().getMissionsList().entrySet()) { - if (entry.getValue().getMissionType() != Mission.MissionType.ONCE) continue; + public Inventory getInventory() { + NoItemGUI noItemGUI = IridiumSkyblock.getInstance().getInventories().missionsGUI; + Inventory inventory = Bukkit.createInventory(this, getSize(), StringUtils.color(noItemGUI.title)); + addContent(inventory); + return inventory; + } - List placeholders = IntStream.range(0, entry.getValue().getMissions().size()) - .boxed() - .map(integer -> IridiumSkyblock.getInstance().getIslandManager().getIslandMission(getIsland(), entry.getValue(), entry.getKey(), integer)) - .map(islandMission -> new Placeholder("progress_"+(islandMission.getMissionIndex()+1), String.valueOf(islandMission.getProgress()))) - .collect(Collectors.toList()); + @Override + public Collection> getPageObjects() { + List> missions = IridiumSkyblock.getInstance().getMissionsList().entrySet().stream() + .filter(e -> e.getValue().getMissionType() == Mission.MissionType.ONCE).collect(Collectors.toList()); - inventory.setItem(slot.getAndIncrement(), ItemStackUtils.makeItem(entry.getValue().getItem(), placeholders)); + switch (IridiumSkyblock.getInstance().getConfiguration().sortMissionsBy) { + case KEY: + missions.sort((a, b) -> { + return a.getKey().compareTo(b.getKey()); + }); + break; + case DISPLAYNAME: + missions.sort((a, b) -> { + if (a.getValue().getItem().displayName==null) return 1; + if (b.getValue().getItem().displayName==null) return -1; + return a.getValue().getItem().displayName.compareTo(b.getValue().getItem().displayName); + }); + break; + case SLOT: + missions.sort((a, b) -> { + if (a.getValue().getItem().slot==null) return 1; + if (b.getValue().getItem().slot==null) return -1; + return a.getValue().getItem().slot.compareTo(b.getValue().getItem().slot); + }); + break; + default: + break; } - if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) { - inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton)); - } + return missions; + } + + @Override + public ItemStack getItemStack(Map.Entry entry) { + List placeholders = IntStream.range(0, entry.getValue().getMissions().size()) + .boxed() + .map(integer -> IridiumSkyblock.getInstance().getIslandManager().getIslandMission(this.island, + entry.getValue(), entry.getKey(), integer)) + .map(islandMission -> new Placeholder("progress_" + (islandMission.getMissionIndex() + 1), + String.valueOf(islandMission.getProgress()))) + .collect(Collectors.toList()); + + return ItemStackUtils.makeItem(entry.getValue().getItem(), placeholders); } /** @@ -58,7 +108,7 @@ public void addContent(Inventory inventory) { */ @Override public void onInventoryClick(InventoryClickEvent event) { - // Do nothing here + super.onInventoryClick(event); } }