Skip to content

Commit

Permalink
added mission sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
boiscljo committed Mar 29, 2023
1 parent 68d45e7 commit ed354f2
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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
* <p>
* 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<Integer, Reward> islandLevelRewards = ImmutableMap.<Integer, Reward>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
Expand Down Expand Up @@ -182,7 +195,6 @@ public static class IslandDeleteSettings {

}


/**
* The default settings for performance.
*/
Expand All @@ -203,7 +215,7 @@ public static class PerformanceSettings {
public boolean disableLeavesDecayCheck = false;
}

/**
/**
* The default settings for confirmation.
*/
@AllArgsConstructor
Expand All @@ -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
Expand All @@ -226,8 +238,7 @@ public static class IslandDamageSettings {

public List<EntityDamageEvent.DamageCause> membersPreventedDamages = Arrays.asList(
EntityDamageEvent.DamageCause.ENTITY_EXPLOSION,
EntityDamageEvent.DamageCause.BLOCK_EXPLOSION
);
EntityDamageEvent.DamageCause.BLOCK_EXPLOSION);

public List<EntityDamageEvent.DamageCause> visitorsPreventedDamages = Arrays.asList(
EntityDamageEvent.DamageCause.PROJECTILE,
Expand All @@ -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);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,103 @@
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<Map.Entry<String, Mission>> {

private final Island island;

/**
* The default constructor.
*
* @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<String, Mission> 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<Placeholder> 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<Map.Entry<String, Mission>> getPageObjects() {
List<Map.Entry<String, Mission>> 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<String, Mission> entry) {
List<Placeholder> 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);
}

/**
Expand All @@ -58,7 +108,7 @@ public void addContent(Inventory inventory) {
*/
@Override
public void onInventoryClick(InventoryClickEvent event) {
// Do nothing here
super.onInventoryClick(event);
}

}

0 comments on commit ed354f2

Please sign in to comment.