Search in sources :

Example 1 with Mission

use of com.iridium.iridiumskyblock.Mission in project IridiumSkyblock by Iridium-Development.

the class MissionManager method incrementMission.

/**
 * Increments a mission's data based on requirements.
 *
 * @param island      The island
 * @param missionData The mission data e.g. BREAK:COBBLESTONE
 * @param amount      The amount we are incrementing by
 */
public synchronized void incrementMission(@NotNull Island island, @NotNull String missionData, int amount) {
    String[] missionConditions = missionData.toUpperCase().split(":");
    for (Map.Entry<String, Mission> entry : IridiumSkyblock.getInstance().getMissionsList().entrySet()) {
        boolean completedBefore = true;
        List<String> missions = entry.getValue().getMissions();
        for (int i = 0; i < entry.getValue().getMissions().size(); i++) {
            String missionRequirement = missions.get(i).toUpperCase();
            String[] conditions = missionRequirement.split(":");
            // If the conditions are the same length (+1 because missionConditions doesn't include amount)
            if (missionConditions.length + 1 != conditions.length)
                continue;
            // Check if this is a mission we want to increment
            boolean matches = matchesMission(missionConditions, conditions);
            if (!matches)
                continue;
            IslandMission islandMission = IridiumSkyblock.getInstance().getIslandManager().getIslandMission(island, entry.getValue(), entry.getKey(), i);
            String number = conditions[missionData.split(":").length];
            // Validate the required number for this condition
            if (number.matches("^[0-9]+$")) {
                int totalAmount = Integer.parseInt(number);
                if (islandMission.getProgress() >= totalAmount)
                    break;
                completedBefore = false;
                islandMission.setProgress(Math.min(islandMission.getProgress() + amount, totalAmount));
            } else {
                IridiumSkyblock.getInstance().getLogger().warning("Unknown format " + missionRequirement);
                IridiumSkyblock.getInstance().getLogger().warning(number + " Is not a number");
            }
        }
        // Check if this mission is now completed
        if (!completedBefore && hasCompletedMission(island, entry.getValue(), entry.getKey())) {
            island.getMembers().stream().map(user -> Bukkit.getPlayer(user.getUuid())).filter(Objects::nonNull).forEach(player -> {
                entry.getValue().getMessage().stream().map(string -> StringUtils.color(string.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))).forEach(player::sendMessage);
                entry.getValue().getCompleteSound().play(player);
            });
            IridiumSkyblock.getInstance().getDatabaseManager().getIslandRewardTableManager().addEntry(new IslandReward(island, entry.getValue().getReward()));
        }
    }
}
Also used : IslandMission(com.iridium.iridiumskyblock.database.IslandMission) Objects(java.util.Objects) List(java.util.List) Map(java.util.Map) Island(com.iridium.iridiumskyblock.database.Island) Mission(com.iridium.iridiumskyblock.Mission) NotNull(org.jetbrains.annotations.NotNull) StringUtils(com.iridium.iridiumcore.utils.StringUtils) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) IslandReward(com.iridium.iridiumskyblock.database.IslandReward) Bukkit(org.bukkit.Bukkit) IslandReward(com.iridium.iridiumskyblock.database.IslandReward) IslandMission(com.iridium.iridiumskyblock.database.IslandMission) IslandMission(com.iridium.iridiumskyblock.database.IslandMission) Mission(com.iridium.iridiumskyblock.Mission) Map(java.util.Map)

Example 2 with Mission

use of com.iridium.iridiumskyblock.Mission in project IridiumSkyblock by Iridium-Development.

the class IslandMissionsGUI method addContent.

@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;
        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());
        inventory.setItem(slot.getAndIncrement(), ItemStackUtils.makeItem(entry.getValue().getItem(), placeholders));
    }
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : IntStream(java.util.stream.IntStream) ItemStackUtils(com.iridium.iridiumcore.utils.ItemStackUtils) Island(com.iridium.iridiumskyblock.database.Island) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) Collectors(java.util.stream.Collectors) Inventory(org.bukkit.inventory.Inventory) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InventoryUtils(com.iridium.iridiumcore.utils.InventoryUtils) Map(java.util.Map) Mission(com.iridium.iridiumskyblock.Mission) NotNull(org.jetbrains.annotations.NotNull) Placeholder(com.iridium.iridiumcore.utils.Placeholder) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Placeholder(com.iridium.iridiumcore.utils.Placeholder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mission(com.iridium.iridiumskyblock.Mission) Map(java.util.Map)

Aggregations

IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)2 Mission (com.iridium.iridiumskyblock.Mission)2 Island (com.iridium.iridiumskyblock.database.Island)2 List (java.util.List)2 Map (java.util.Map)2 NotNull (org.jetbrains.annotations.NotNull)2 InventoryUtils (com.iridium.iridiumcore.utils.InventoryUtils)1 ItemStackUtils (com.iridium.iridiumcore.utils.ItemStackUtils)1 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 StringUtils (com.iridium.iridiumcore.utils.StringUtils)1 IslandMission (com.iridium.iridiumskyblock.database.IslandMission)1 IslandReward (com.iridium.iridiumskyblock.database.IslandReward)1 Objects (java.util.Objects)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Bukkit (org.bukkit.Bukkit)1 InventoryClickEvent (org.bukkit.event.inventory.InventoryClickEvent)1 Inventory (org.bukkit.inventory.Inventory)1