Search in sources :

Example 1 with Island

use of com.iridium.iridiumskyblock.database.Island 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 Island

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

the class EntityTargetListener method onEntityTargetEntity.

@EventHandler
public void onEntityTargetEntity(EntityTargetLivingEntityEvent event) {
    if (IridiumSkyblock.getInstance().getConfiguration().pvpSettings.mobsVisitorTargeting)
        return;
    Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getEntity().getLocation());
    if (!island.isPresent())
        return;
    if (event.getTarget() == null || !(event.getTarget() instanceof Player))
        return;
    Player targetPlayer = (Player) event.getTarget();
    User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
    Optional<IslandTrusted> targetTrusted = IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser);
    if (island.get().equals(targetUser.getIsland().orElse(null)) || targetTrusted.isPresent())
        return;
    if (!canSearchTarget(event.getEntity())) {
        return;
    }
    List<Player> nextTargets = event.getEntity().getNearbyEntities(8, 8, 8).stream().filter(entity -> entity instanceof Player).filter(entity -> island.get().isInIsland(entity.getLocation())).map(entity -> (Player) entity).filter(player -> player != targetPlayer).filter(player -> island.get().equals(IridiumSkyblock.getInstance().getUserManager().getUser(player).getIsland().orElse(null))).filter(player -> IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player)).isPresent()).filter(player -> player.hasLineOfSight(event.getEntity())).collect(Collectors.toList());
    if (nextTargets.isEmpty()) {
        event.setCancelled(true);
        return;
    }
    Player nextTarget = nextTargets.get(ThreadLocalRandom.current().nextInt(nextTargets.size()));
    event.setTarget(nextTarget);
}
Also used : EntityTargetLivingEntityEvent(org.bukkit.event.entity.EntityTargetLivingEntityEvent) Entity(org.bukkit.entity.Entity) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) EventHandler(org.bukkit.event.EventHandler) List(java.util.List) CooldownProvider(com.iridium.iridiumskyblock.managers.CooldownProvider) Duration(java.time.Duration) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IslandTrusted(com.iridium.iridiumskyblock.database.IslandTrusted) Optional(java.util.Optional) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Listener(org.bukkit.event.Listener) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandTrusted(com.iridium.iridiumskyblock.database.IslandTrusted) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Island

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

the class FurnaceSmeltListener method monitorFurnaceSmelt.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorFurnaceSmelt(FurnaceSmeltEvent event) {
    Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getBlock().getLocation());
    XMaterial material = XMaterial.matchXMaterial(event.getSource().getType());
    island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "SMELT", material.name(), 1));
}
Also used : XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Island

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

the class PlayerChatListener method onPlayerChat.

@EventHandler(ignoreCancelled = true)
public void onPlayerChat(AsyncPlayerChatEvent event) {
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(event.getPlayer());
    Optional<Island> island = user.getIsland();
    if (user.isIslandChat() && island.isPresent()) {
        event.setCancelled(true);
        for (User islandUser : island.get().getMembers()) {
            Player recipient = Bukkit.getPlayer(islandUser.getUuid());
            if (recipient != null) {
                recipient.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().islandMemberChat, new PlaceholderBuilder().applyIslandPlaceholders(island.get()).build()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", event.getPlayer().getName()).replace("%message%", event.getMessage())));
            }
        }
        for (Player player : Bukkit.getOnlinePlayers()) {
            User onlineUser = IridiumSkyblockAPI.getInstance().getUser(player);
            if (onlineUser.isIslandChatSpying()) {
                player.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().islandChatSpyMessage, new PlaceholderBuilder().applyIslandPlaceholders(island.get()).build()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%island%", island.get().getName()).replace("%player%", event.getPlayer().getName()).replace("%message%", event.getMessage())));
            }
        }
    } else {
        String format = event.getFormat();
        for (Map.Entry<String, Placeholders.Placeholder> entry : Placeholders.placeholders.entrySet()) {
            if (format.contains(entry.getKey().toUpperCase())) {
                format = format.replace(entry.getKey().toUpperCase(), entry.getValue().placeholderProcess(event.getPlayer()));
            }
        }
        event.setFormat(format);
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island) Map(java.util.Map) EventHandler(org.bukkit.event.EventHandler)

Example 5 with Island

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

the class PlayerInteractListener method onPlayerInteractEntity.

@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    Player player = event.getPlayer();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getRightClicked().getLocation());
    if (!island.isPresent())
        return;
    if (IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.INTERACT_ENTITIES)) {
        return;
    }
    event.setCancelled(true);
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotInteractEntities.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Island (com.iridium.iridiumskyblock.database.Island)92 User (com.iridium.iridiumskyblock.database.User)76 Player (org.bukkit.entity.Player)60 EventHandler (org.bukkit.event.EventHandler)18 List (java.util.List)16 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)15 OfflinePlayer (org.bukkit.OfflinePlayer)15 Collectors (java.util.stream.Collectors)14 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)12 Optional (java.util.Optional)11 StringUtils (com.iridium.iridiumcore.utils.StringUtils)10 IslandBank (com.iridium.iridiumskyblock.database.IslandBank)10 Duration (java.time.Duration)10 Collections (java.util.Collections)9 CommandSender (org.bukkit.command.CommandSender)9 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)7 PlaceholderBuilder (com.iridium.iridiumskyblock.PlaceholderBuilder)6 BankItem (com.iridium.iridiumskyblock.bank.BankItem)6 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)6 Bukkit (org.bukkit.Bukkit)6