Search in sources :

Example 6 with IslandSetting

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

Aggregations

IslandSetting (com.iridium.iridiumskyblock.database.IslandSetting)6 EventHandler (org.bukkit.event.EventHandler)4 Setting (com.iridium.iridiumskyblock.Setting)2 User (com.iridium.iridiumskyblock.database.User)2 Map (java.util.Map)2 Player (org.bukkit.entity.Player)2 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 IslandTime (com.iridium.iridiumskyblock.IslandTime)1 IslandWeatherType (com.iridium.iridiumskyblock.IslandWeatherType)1 SettingType (com.iridium.iridiumskyblock.SettingType)1 IslandSettingChangeEvent (com.iridium.iridiumskyblock.api.IslandSettingChangeEvent)1 Island (com.iridium.iridiumskyblock.database.Island)1 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)1 WeatherType (org.bukkit.WeatherType)1 LivingEntity (org.bukkit.entity.LivingEntity)1 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)1 MetadataValue (org.bukkit.metadata.MetadataValue)1