Search in sources :

Example 71 with User

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

the class PlayerMoveListener method onPlayerMove.

@EventHandler(ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    if (event.getTo().getBlockX() != event.getFrom().getBlockX() || event.getTo().getBlockZ() != event.getFrom().getBlockZ()) {
        if (user.getTeleportingTask() != null) {
            user.getTeleportingTask().cancel();
            user.setTeleportingTask(null);
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().teleportCanceled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
        Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaPlayerLocation(player);
        if (island.isPresent()) {
            if (IridiumSkyblock.getInstance().getIslandManager().isBannedOnIsland(island.get(), user)) {
                event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenBanned.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%owner%", island.get().getOwner().getName()).replace("%name%", island.get().getName())));
                PlayerUtils.teleportSpawn(player);
            } else {
                IslandSetting islandTimeSetting = IridiumSkyblock.getInstance().getIslandManager().getIslandSetting(island.get(), SettingType.TIME);
                IslandSetting islandWeatherSetting = IridiumSkyblock.getInstance().getIslandManager().getIslandSetting(island.get(), SettingType.WEATHER);
                IslandTime islandTime = IslandTime.valueOf(islandTimeSetting.getValue());
                IslandWeatherType islandWeatherType = IslandWeatherType.valueOf(islandWeatherSetting.getValue());
                if (islandWeatherType == IslandWeatherType.DEFAULT) {
                    player.resetPlayerWeather();
                } else {
                    WeatherType newWeatherType = islandWeatherType == IslandWeatherType.CLEAR ? WeatherType.CLEAR : WeatherType.DOWNFALL;
                    if (player.getPlayerWeather() != newWeatherType) {
                        player.setPlayerWeather(newWeatherType);
                    }
                }
                if ((islandTime == IslandTime.DEFAULT && player.getPlayerTime() != player.getWorld().getTime()) || player.getPlayerTime() != islandTime.getTime()) {
                    player.setPlayerTime(islandTime.getTime(), islandTime.isRelative());
                }
            }
        }
        if (user.isFlying()) {
            if (island.isPresent()) {
                IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island.get(), "flight");
                if (!islandBooster.isActive() && !player.hasPermission("iridiumskyblock.fly")) {
                    user.setFlying(false);
                    if (player.getGameMode().equals(GameMode.SURVIVAL) || player.getGameMode().equals(GameMode.ADVENTURE)) {
                        player.setFlying(false);
                        player.setAllowFlight(false);
                        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().flightDisabled.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                    }
                }
            } else if (!player.hasPermission("iridiumskyblock.fly")) {
                user.setFlying(false);
                if (player.getGameMode().equals(GameMode.SURVIVAL) || player.getGameMode().equals(GameMode.ADVENTURE)) {
                    player.setFlying(false);
                    player.setAllowFlight(false);
                    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().flightDisabled.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                }
            }
        }
    }
    if (event.getTo().getY() < LocationUtils.getMinHeight(event.getTo().getWorld()) && IridiumSkyblock.getInstance().getConfiguration().voidTeleport && IridiumSkyblockAPI.getInstance().isIslandWorld(player.getWorld())) {
        Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaPlayerLocation(player);
        if (island.isPresent()) {
            IridiumSkyblock.getInstance().getIslandManager().teleportHome(player, island.get(), 0);
        } else {
            Optional<Island> userIsland = user.getIsland();
            if (userIsland.isPresent()) {
                IridiumSkyblock.getInstance().getIslandManager().teleportHome(player, userIsland.get(), 0);
            } else {
                PlayerUtils.teleportSpawn(player);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) IslandWeatherType(com.iridium.iridiumskyblock.IslandWeatherType) User(com.iridium.iridiumskyblock.database.User) IslandSetting(com.iridium.iridiumskyblock.database.IslandSetting) IslandBooster(com.iridium.iridiumskyblock.database.IslandBooster) IslandWeatherType(com.iridium.iridiumskyblock.IslandWeatherType) WeatherType(org.bukkit.WeatherType) IslandTime(com.iridium.iridiumskyblock.IslandTime) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 72 with User

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

the class PlayerPortalListener method onPlayerPortal.

@EventHandler(ignoreCancelled = true)
public void onPlayerPortal(PlayerPortalEvent event) {
    IslandManager islandManager = IridiumSkyblock.getInstance().getIslandManager();
    final Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getFrom());
    if (!island.isPresent())
        return;
    final User user = IridiumSkyblock.getInstance().getUserManager().getUser(event.getPlayer());
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.PORTAL)) {
        if (hasNoCooldown(event.getPlayer())) {
            event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotUsePortal.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
        event.setCancelled(true);
        return;
    }
    if (event.getCause() == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) {
        if (IridiumSkyblock.getInstance().getConfiguration().netherIslands) {
            World world = Objects.equals(event.getFrom().getWorld(), islandManager.getNetherWorld()) ? islandManager.getWorld() : islandManager.getNetherWorld();
            event.setTo(island.get().getCenter(world));
            return;
        }
        event.setCancelled(true);
        if (hasNoCooldown(event.getPlayer())) {
            event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().netherIslandsDisabled.replace("%prefix", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
        return;
    }
    if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) {
        event.setCancelled(true);
        if (IridiumSkyblock.getInstance().getConfiguration().endIslands) {
            World world = Objects.equals(event.getFrom().getWorld(), islandManager.getEndWorld()) ? islandManager.getWorld() : islandManager.getEndWorld();
            event.getPlayer().teleport(LocationUtils.getSafeLocation(island.get().getCenter(world), island.get()));
            return;
        }
        if (hasNoCooldown(event.getPlayer())) {
            event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().endIslandsDisabled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    }
}
Also used : IslandManager(com.iridium.iridiumskyblock.managers.IslandManager) User(com.iridium.iridiumskyblock.database.User) World(org.bukkit.World) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 73 with User

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

the class PlayerRespawnListener method onRespawn.

@EventHandler
public void onRespawn(PlayerRespawnEvent event) {
    if (IridiumSkyblock.getInstance().getConfiguration().respawnOnIsland) {
        User user = IridiumSkyblock.getInstance().getUserManager().getUser(event.getPlayer());
        user.getIsland().ifPresent(island -> {
            if (!island.isInIsland(event.getRespawnLocation())) {
                event.setRespawnLocation(LocationUtils.getSafeLocation(island.getHome(), island));
            }
        });
    }
}
Also used : User(com.iridium.iridiumskyblock.database.User) EventHandler(org.bukkit.event.EventHandler)

Example 74 with User

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

the class PlayerTeleportListener method onPlayerTeleport.

@EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
    if (event.getTo() == null)
        return;
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(event.getPlayer());
    IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getTo()).ifPresent(island -> {
        if (IridiumSkyblock.getInstance().getIslandManager().isBannedOnIsland(island, user)) {
            event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenBanned.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%owner%", island.getOwner().getName()).replace("%name%", island.getName())));
            event.setCancelled(true);
        } else {
            Bukkit.getScheduler().runTaskLater(IridiumSkyblock.getInstance(), () -> PlayerUtils.sendBorder(event.getPlayer(), island), 1);
        }
    });
}
Also used : User(com.iridium.iridiumskyblock.database.User) EventHandler(org.bukkit.event.EventHandler)

Example 75 with User

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

the class Placeholders method getIslandPlaceholders.

private static Map<String, Placeholder> getIslandPlaceholders(String startKey, IslandGetter islandGetter) {
    ImmutableMap.Builder<String, Placeholder> placeholderBuilder = ImmutableMap.<String, Placeholder>builder().put(startKey + "_name", player -> islandGetter.getIsland(player).map(Island::getName).orElse(placeholdersConfig.islandName)).put(startKey + "_owner", player -> islandGetter.getIsland(player).map(island -> island.getOwner().getName()).orElse(placeholdersConfig.islandOwner)).put(startKey + "_rank", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getRank())).orElse(placeholdersConfig.islandRank)).put(startKey + "_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getLevel())).orElse(placeholdersConfig.islandLevel)).put(startKey + "_value", player -> islandGetter.getIsland(player).map(Island::getFormattedValue).orElse(placeholdersConfig.islandValue)).put(startKey + "_extravalue", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getExtraValue())).orElse(placeholdersConfig.islandExtraValue)).put(startKey + "_visitable", player -> islandGetter.getIsland(player).map(island -> island.isVisitable() ? IridiumSkyblock.getInstance().getMessages().visitable : IridiumSkyblock.getInstance().getMessages().notVisitable).orElse(placeholdersConfig.islandValue)).put(startKey + "_members", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getMembers().size())).orElse(placeholdersConfig.islandMembers)).put(startKey + "_member_names", player -> islandGetter.getIsland(player).map(island -> island.getMembers().stream().map(User::getName).collect(Collectors.joining(", "))).orElse(placeholdersConfig.islandMemberNames)).put(startKey + "_visitors", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(island).stream().filter(user -> !island.equals(user.getIsland().orElse(null))).count())).orElse(placeholdersConfig.islandVisitors)).put(startKey + "_visitor_names", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(island).stream().filter(user -> !island.equals(user.getIsland().orElse(null))).map(User::getName).collect(Collectors.joining(", "))).orElse(placeholdersConfig.islandVisitorNames)).put(startKey + "_players", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(island).size())).orElse(placeholdersConfig.islandPlayers)).put(startKey + "_player_names", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(island).stream().map(User::getName).collect(Collectors.joining(", "))).orElse(placeholdersConfig.islandPlayerNames)).put(startKey + "_experience", player -> islandGetter.getIsland(player).map(Island::getFormattedExperience).orElse(placeholdersConfig.islandExperience)).put(startKey + "_experience_required", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getExperienceRequiredToLevelUp())).orElse(placeholdersConfig.islandExperienceRequired)).put(startKey + "_experience_remaining", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(island.getExperienceRemainingToLevelUp())).orElse(placeholdersConfig.islandExperienceRemaining)).put(startKey + "_overworld_biome", player -> islandGetter.getIsland(player).map(island -> island.getCenter(IridiumSkyblock.getInstance().getIslandManager().getWorld()).getBlock()).map(Block::getBiome).map(biome -> WordUtils.capitalizeFully(biome.name().toLowerCase().replace("_", " "))).orElse(placeholdersConfig.islandBiome)).put(startKey + "_nether_biome", player -> islandGetter.getIsland(player).map(island -> island.getCenter(IridiumSkyblock.getInstance().getIslandManager().getNetherWorld()).getBlock()).map(Block::getBiome).map(biome -> WordUtils.capitalizeFully(biome.name().toLowerCase().replace("_", " "))).orElse(placeholdersConfig.islandBiome)).put(startKey + "_end_biome", player -> islandGetter.getIsland(player).map(island -> island.getCenter(IridiumSkyblock.getInstance().getIslandManager().getEndWorld()).getBlock()).map(Block::getBiome).map(biome -> WordUtils.capitalizeFully(biome.name().toLowerCase().replace("_", " "))).orElse(placeholdersConfig.islandBiome)).put(startKey + "_bank_experience", player -> islandGetter.getIsland(player).map(Island::getFormattedBankExperience).orElse(placeholdersConfig.islandBankExperience)).put(startKey + "_bank_crystals", player -> islandGetter.getIsland(player).map(Island::getFormattedCrystals).orElse(placeholdersConfig.islandBankCrystals)).put(startKey + "_bank_money", player -> islandGetter.getIsland(player).map(Island::getFormattedMoney).orElse(placeholdersConfig.islandBankMoney)).put(startKey + "_upgrade_blocklimit_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(islandManager.getIslandUpgrade(island, "blocklimit").getLevel())).orElse(placeholdersConfig.islandUpgradeBlocklimitLevel)).put(startKey + "_upgrade_member_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(islandManager.getIslandUpgrade(island, "member").getLevel())).orElse(placeholdersConfig.islandUpgradeMemberLevel)).put(startKey + "_upgrade_size_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(islandManager.getIslandUpgrade(island, "size").getLevel())).orElse(placeholdersConfig.islandUpgradeSizeLevel)).put(startKey + "_upgrade_generator_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(islandManager.getIslandUpgrade(island, "generator").getLevel())).orElse(placeholdersConfig.islandUpgradeGeneratorLevel)).put(startKey + "_upgrade_warp_level", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(islandManager.getIslandUpgrade(island, "warp").getLevel())).orElse(placeholdersConfig.islandUpgradeWarpLevel)).put(startKey + "_upgrade_member_amount", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getUpgrades().memberUpgrade.upgrades.get(islandManager.getIslandUpgrade(island, "member").getLevel()).amount)).orElse(placeholdersConfig.islandUpgradeMemberAmount)).put(startKey + "_upgrade_size_dimensions", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getUpgrades().sizeUpgrade.upgrades.get(islandManager.getIslandUpgrade(island, "size").getLevel()).size)).orElse(placeholdersConfig.islandUpgradeSizeDimensions)).put(startKey + "_upgrade_warp_amount", player -> islandGetter.getIsland(player).map(island -> IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getUpgrades().warpsUpgrade.upgrades.get(islandManager.getIslandUpgrade(island, "warp").getLevel()).amount)).orElse(placeholdersConfig.islandUpgradeWarpAmount));
    // Boosters
    for (String booster : IridiumSkyblock.getInstance().getBoosterList().keySet()) {
        placeholderBuilder.put(startKey + "_booster_" + booster + "_remaining_minutes", player -> islandGetter.getIsland(player).map(island -> {
            IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island, booster);
            long minutes = LocalDateTime.now().until(islandBooster.getTime(), ChronoUnit.MINUTES);
            return String.valueOf(Math.max(minutes, 0));
        }).orElse(placeholdersConfig.islandBoosterRemainingMinutes));
        placeholderBuilder.put(startKey + "_booster_" + booster + "_remaining_seconds", player -> islandGetter.getIsland(player).map(island -> {
            IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island, booster);
            long minutes = LocalDateTime.now().until(islandBooster.getTime(), ChronoUnit.MINUTES);
            long seconds = LocalDateTime.now().until(islandBooster.getTime(), ChronoUnit.SECONDS) - minutes * 60;
            return String.valueOf(Math.max(seconds, 0));
        }).orElse(placeholdersConfig.islandBoosterRemainingSeconds));
    }
    return placeholderBuilder.build();
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) User(com.iridium.iridiumskyblock.database.User) LocalDateTime(java.time.LocalDateTime) Island(com.iridium.iridiumskyblock.database.Island) HashMap(java.util.HashMap) Player(org.bukkit.entity.Player) IslandBooster(com.iridium.iridiumskyblock.database.IslandBooster) Collectors(java.util.stream.Collectors) List(java.util.List) Block(org.bukkit.block.Block) ChronoUnit(java.time.temporal.ChronoUnit) Map(java.util.Map) Optional(java.util.Optional) IslandManager(com.iridium.iridiumskyblock.managers.IslandManager) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) WordUtils(org.apache.commons.lang.WordUtils) IslandBooster(com.iridium.iridiumskyblock.database.IslandBooster) Block(org.bukkit.block.Block) Island(com.iridium.iridiumskyblock.database.Island) ImmutableMap(com.google.common.collect.ImmutableMap)

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