use of com.iridium.iridiumskyblock.database.IslandReward 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()));
}
}
}
use of com.iridium.iridiumskyblock.database.IslandReward in project IridiumSkyblock by Iridium-Development.
the class IslandRewardsGUI method addContent.
@Override
public void addContent(Inventory inventory) {
inventory.clear();
InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().islandReward.background);
List<Placeholder> placeholders = new PlaceholderBuilder().applyIslandPlaceholders(getIsland()).build();
// slot 0
int maxSize = inventory.getSize() - 1;
AtomicInteger atomicInteger = new AtomicInteger(0);
for (IslandReward islandReward : IridiumSkyblock.getInstance().getDatabaseManager().getIslandRewardTableManager().getEntries(getIsland())) {
if (atomicInteger.get() > maxSize)
break;
inventory.setItem(atomicInteger.getAndIncrement(), ItemStackUtils.makeItem(islandReward.getReward().item, placeholders));
}
if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
}
}
use of com.iridium.iridiumskyblock.database.IslandReward in project IridiumSkyblock by Iridium-Development.
the class IslandRewardsGUI method onInventoryClick.
@Override
public void onInventoryClick(InventoryClickEvent event) {
List<IslandReward> islandRewards = IridiumSkyblock.getInstance().getDatabaseManager().getIslandRewardTableManager().getEntries(getIsland());
if (islandRewards.size() > event.getSlot()) {
IslandReward islandReward = islandRewards.get(event.getSlot());
islandReward.getReward().claim((Player) event.getWhoClicked(), getIsland());
IridiumSkyblock.getInstance().getDatabaseManager().getIslandRewardTableManager().delete(islandReward);
event.getWhoClicked().closeInventory();
}
}
Aggregations