Search in sources :

Example 1 with User

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

the class UserManager method getUser.

/**
 * Gets a {@link User}'s info. Creates one if he doesn't exist.
 *
 * @param offlinePlayer The player who's data should be fetched
 * @return The user data
 */
@NotNull
public User getUser(@NotNull OfflinePlayer offlinePlayer) {
    Optional<User> userOptional = getUserByUUID(offlinePlayer.getUniqueId());
    if (userOptional.isPresent()) {
        return userOptional.get();
    } else {
        Optional<String> name = Optional.ofNullable(offlinePlayer.getName());
        User user = new User(offlinePlayer.getUniqueId(), name.orElse(""));
        IridiumSkyblock.getInstance().getDatabaseManager().getUserTableManager().addEntry(user);
        return user;
    }
}
Also used : User(com.iridium.iridiumskyblock.database.User) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with User

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

the class IslandTrustedGUI method onInventoryClick.

/**
 * Called when there is a click in this GUI.
 * Cancelled automatically.
 *
 * @param event The InventoryClickEvent provided by Bukkit
 */
@Override
public void onInventoryClick(InventoryClickEvent event) {
    if (members.containsKey(event.getSlot())) {
        User user = members.get(event.getSlot());
        IridiumSkyblock.getInstance().getCommands().unTrustCommand.execute(event.getWhoClicked(), new String[] { "", user.getName() });
        addContent(event.getInventory());
    }
}
Also used : User(com.iridium.iridiumskyblock.database.User)

Example 3 with User

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

the class IslandVisitorsGUI method onInventoryClick.

/**
 * Called when there is a click in this GUI.
 * Cancelled automatically.
 *
 * @param event The InventoryClickEvent provided by Bukkit
 */
@Override
public void onInventoryClick(InventoryClickEvent event) {
    final int size = IridiumSkyblock.getInstance().getInventories().bansGUI.size;
    Player player = (Player) event.getWhoClicked();
    if (event.getSlot() == size - 7 && page > 1) {
        player.openInventory(new IslandVisitorsGUI(page - 1, getIsland()).getInventory());
        return;
    }
    if (event.getSlot() == size - 3 && (size - 9) * page < visitors.size()) {
        player.openInventory(new IslandVisitorsGUI(page + 1, getIsland()).getInventory());
        return;
    }
    if (visitors.size() > event.getSlot()) {
        User visitor = visitors.get(event.getSlot());
        if (event.isLeftClick()) {
            IridiumSkyblock.getInstance().getCommands().expelCommand.execute(event.getWhoClicked(), new String[] { "", visitor.getName() });
        } else if (event.isRightClick()) {
            IridiumSkyblock.getInstance().getCommands().banCommand.execute(event.getWhoClicked(), new String[] { "", visitor.getName() });
        }
        addContent(event.getInventory());
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User)

Example 4 with User

use of com.iridium.iridiumskyblock.database.User 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 5 with User

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

Aggregations

User (com.iridium.iridiumskyblock.database.User)94 Island (com.iridium.iridiumskyblock.database.Island)73 Player (org.bukkit.entity.Player)66 OfflinePlayer (org.bukkit.OfflinePlayer)16 EventHandler (org.bukkit.event.EventHandler)16 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)13 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)12 List (java.util.List)12 Optional (java.util.Optional)11 Collectors (java.util.stream.Collectors)11 IslandBank (com.iridium.iridiumskyblock.database.IslandBank)10 Duration (java.time.Duration)10 StringUtils (com.iridium.iridiumcore.utils.StringUtils)9 Collections (java.util.Collections)9 CommandSender (org.bukkit.command.CommandSender)9 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)6 BankItem (com.iridium.iridiumskyblock.bank.BankItem)5 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)5 IslandTrusted (com.iridium.iridiumskyblock.database.IslandTrusted)5 IslandWarp (com.iridium.iridiumskyblock.database.IslandWarp)5