Search in sources :

Example 66 with Island

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

the class SetCommand 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).
 *
 * @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 < 4) {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]);
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> optionalIsland = user.getIsland();
    if (!optionalIsland.isPresent()) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    double amount;
    try {
        amount = Double.parseDouble(args[3]);
    } catch (NumberFormatException exception) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Island island = optionalIsland.get();
    island.setExtraValue(amount);
    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().extraValueSet.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName()).replace("%amount%", String.valueOf(island.getExtraValue()))));
    return true;
}
Also used : User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) Island(com.iridium.iridiumskyblock.database.Island)

Example 67 with Island

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

the class CurrentOffsetCommand 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).
 *
 * @param sender The CommandSender which executes this command
 * @param arguments   The arguments used with this command. They contain the sub-command
 */
@Override
public boolean execute(CommandSender sender, String[] arguments) {
    Player player = (Player) sender;
    Location playerLocation = player.getLocation();
    Optional<Island> islandOptional = IridiumSkyblock.getInstance().getIslandManager().getIslandViaPlayerLocation(player);
    if (!islandOptional.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notOnAnIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Location offset = playerLocation.subtract(islandOptional.get().getCenter(player.getWorld()));
    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandCenterOffset.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%x%", String.valueOf(offset.getBlockX() + 0.5)).replace("%y%", String.valueOf(offset.getBlockY())).replace("%z%", String.valueOf(offset.getBlockZ() + 0.5)).replace("%yaw%", String.valueOf(playerLocation.getYaw()))));
    return true;
}
Also used : Player(org.bukkit.entity.Player) Island(com.iridium.iridiumskyblock.database.Island) Location(org.bukkit.Location)

Example 68 with Island

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

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

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

the class PotionBrewListener method monitorPotionBrew.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorPotionBrew(BrewEvent event) {
    // Delay the check so the new potion is checked
    Bukkit.getScheduler().scheduleSyncDelayedTask(IridiumSkyblock.getInstance(), () -> {
        Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getBlock().getLocation());
        for (int i = 0; i < 3; i++) {
            ItemStack itemStack = event.getContents().getItem(i);
            if (itemStack != null && itemStack.getItemMeta() instanceof PotionMeta) {
                PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
                island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "BREW", potionMeta.getBasePotionData().getType() + ":" + (potionMeta.getBasePotionData().isUpgraded() ? 2 : 1), 1));
            }
        }
    });
}
Also used : PotionMeta(org.bukkit.inventory.meta.PotionMeta) ItemStack(org.bukkit.inventory.ItemStack) 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