Search in sources :

Example 1 with IslandTrusted

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

the class IslandTrustedGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().trustedGUI.background);
    List<IslandTrusted> islandTrustedList = IridiumSkyblock.getInstance().getDatabaseManager().getIslandTrustedTableManager().getEntries(getIsland());
    AtomicInteger slot = new AtomicInteger(0);
    for (IslandTrusted islandTrusted : islandTrustedList) {
        int itemSlot = slot.getAndIncrement();
        List<Placeholder> placeholderList = new PlaceholderBuilder().applyPlayerPlaceholders(islandTrusted.getUser()).applyIslandPlaceholders(getIsland()).build();
        placeholderList.add(new Placeholder("trustee", islandTrusted.getTruster().getName()));
        inventory.setItem(itemSlot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().trustedGUI.item, placeholderList));
        members.put(itemSlot, islandTrusted.getUser());
    }
}
Also used : Placeholder(com.iridium.iridiumcore.utils.Placeholder) IslandTrusted(com.iridium.iridiumskyblock.database.IslandTrusted) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder)

Example 2 with IslandTrusted

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

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

the class UnTrustCommand method execute.

/**
 * Executes the command for the specified {@link CommandSender} with the provided arguments.
 * Not called when the command execution was invalid (no permission, no player or command disabled).
 * Un-Invites a User from an Island.
 *
 * @param sender The CommandSender which executes this command
 * @param args   The arguments used with this command. They contain the sub-command
 */
@Override
public boolean execute(CommandSender sender, String[] args) {
    if (args.length != 2) {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Player player = (Player) sender;
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(Bukkit.getServer().getOfflinePlayer(args[1]));
    if (!island.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.TRUST)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageTrusts.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Optional<IslandTrusted> islandTrusted = IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser);
    if (!islandTrusted.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notTrusted.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandTrustedTableManager().delete(islandTrusted.get());
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().trustRevoked.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_UNTRUSTED, user, targetUser, 0, "");
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    return true;
}
Also used : IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandTrusted(com.iridium.iridiumskyblock.database.IslandTrusted) Island(com.iridium.iridiumskyblock.database.Island)

Example 4 with IslandTrusted

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

the class TrustCommand method execute.

/**
 * Executes the command for the specified {@link CommandSender} with the provided arguments.
 * Not called when the command execution was invalid (no permission, no player or command disabled).
 * Shows an overview over the members of the Island and allows quick rank management.
 *
 * @param sender The CommandSender which executes this command
 * @param args   The arguments used with this command. They contain the sub-command
 */
@Override
public boolean execute(CommandSender sender, String[] args) {
    Player player = (Player) sender;
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    if (!island.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.TRUST)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageTrusts.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (args.length != 2) {
        player.openInventory(new IslandTrustedGUI(island.get()).getInventory());
        return true;
    }
    Player targetPlayer = Bukkit.getPlayer(args[1]);
    if (targetPlayer == null) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
    if (targetUser.getIsland().map(Island::getId).orElse(0) == island.get().getId()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser).isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyTrusted.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandTrusted islandTrusted = new IslandTrusted(island.get(), targetUser, user);
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandTrustedTableManager().addEntry(islandTrusted);
    island.get().getMembers().stream().map(user1 -> Bukkit.getPlayer(user1.getUuid())).filter(Objects::nonNull).forEach(onlineMember -> onlineMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().trustedPlayer.replace("%truster%", player.getName()).replace("%player%", targetPlayer.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))));
    targetPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerTrustedYou.replace("%truster%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_TRUSTED, user, targetUser, 0, "");
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    return true;
}
Also used : IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandTrusted(com.iridium.iridiumskyblock.database.IslandTrusted) IslandTrustedGUI(com.iridium.iridiumskyblock.gui.IslandTrustedGUI) Island(com.iridium.iridiumskyblock.database.Island)

Example 5 with IslandTrusted

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

the class EntityDamageListener method handleDamageBetweenPlayers.

public void handleDamageBetweenPlayers(EntityDamageByEntityEvent event, Player attacker, Player victim, Island island) {
    Configuration configuration = IridiumSkyblock.getInstance().getConfiguration();
    if (!configuration.pvpSettings.pvpOnIslands) {
        if (!messageIsOnCooldown(attacker)) {
            attacker.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotHurtPlayer.replace("%prefix%", configuration.prefix)));
        }
        if (event.getCause().equals(EntityDamageEvent.DamageCause.PROJECTILE)) {
            event.getDamager().remove();
        }
        event.setCancelled(true);
        return;
    }
    User attackerUser = IridiumSkyblock.getInstance().getUserManager().getUser(attacker);
    User victimUser = IridiumSkyblock.getInstance().getUserManager().getUser(victim);
    Optional<IslandTrusted> attackerTrusted = IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island, attackerUser);
    Optional<IslandTrusted> victimTrusted = IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island, victimUser);
    boolean attackerIsMember = island.equals(attackerUser.getIsland().orElse(null)) || attackerTrusted.isPresent();
    boolean victimIsMember = island.equals(victimUser.getIsland().orElse(null)) || victimTrusted.isPresent();
    // If pvp between members is allowed or neither attacker or victim is a member, return
    if (configuration.pvpSettings.pvpBetweenMembers || !(attackerIsMember || victimIsMember))
        return;
    if (!messageIsOnCooldown(attacker)) {
        attacker.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotHurtMember.replace("%prefix%", configuration.prefix)));
    }
    if (event.getCause().equals(EntityDamageEvent.DamageCause.PROJECTILE))
        event.getDamager().remove();
    event.setCancelled(true);
}
Also used : User(com.iridium.iridiumskyblock.database.User) IslandTrusted(com.iridium.iridiumskyblock.database.IslandTrusted) Configuration(com.iridium.iridiumskyblock.configs.Configuration)

Aggregations

IslandTrusted (com.iridium.iridiumskyblock.database.IslandTrusted)6 User (com.iridium.iridiumskyblock.database.User)5 Player (org.bukkit.entity.Player)4 Island (com.iridium.iridiumskyblock.database.Island)3 Configuration (com.iridium.iridiumskyblock.configs.Configuration)2 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)2 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)1 PlaceholderBuilder (com.iridium.iridiumskyblock.PlaceholderBuilder)1 IslandTrustedGUI (com.iridium.iridiumskyblock.gui.IslandTrustedGUI)1 CooldownProvider (com.iridium.iridiumskyblock.managers.CooldownProvider)1 Duration (java.time.Duration)1 List (java.util.List)1 Optional (java.util.Optional)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Entity (org.bukkit.entity.Entity)1 EventHandler (org.bukkit.event.EventHandler)1 Listener (org.bukkit.event.Listener)1