Search in sources :

Example 1 with IslandDeleteEvent

use of com.iridium.iridiumskyblock.api.IslandDeleteEvent in project IridiumSkyblock by Iridium-Development.

the class IslandManager method deleteIsland.

/**
 * Deletes the specified Island.
 *
 * @param island The Island which should be deleted
 * @param user   The user who deleted the island
 */
public void deleteIsland(@NotNull Island island, @Nullable User user) {
    IslandDeleteEvent islandDeleteEvent = new IslandDeleteEvent(island, user);
    Bukkit.getPluginManager().callEvent(islandDeleteEvent);
    if (islandDeleteEvent.isCancelled())
        return;
    clearIslandCache();
    deleteIslandBlocks(island, getWorld(), 3);
    deleteIslandBlocks(island, getNetherWorld(), 3);
    deleteIslandBlocks(island, getEndWorld(), 3);
    deleteIslanDatabasedEntries(island);
    getIslandMembers(island).stream().map(User::getPlayer).forEach(player -> {
        if (player != null) {
            if (IridiumSkyblock.getInstance().getConfiguration().deleteSettings.clearInventories) {
                player.getInventory().clear();
            }
            if (IridiumSkyblock.getInstance().getConfiguration().deleteSettings.clearEnderChests) {
                player.getEnderChest().clear();
            }
            if (IridiumSkyblock.getInstance().getConfiguration().deleteSettings.resetVaultBalances) {
                IridiumSkyblock.getInstance().getEconomy().withdrawPlayer(player, IridiumSkyblock.getInstance().getEconomy().getBalance(player));
            }
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandDeleted.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    });
    getEntities(island, getWorld(), getEndWorld(), getNetherWorld()).thenAccept(entities -> Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> entities.stream().filter(entity -> entity instanceof Player).map(entity -> (Player) entity).forEach(PlayerUtils::teleportSpawn)));
}
Also used : IslandRegenSettings(com.iridium.iridiumskyblock.configs.Configuration.IslandRegenSettings) IntStream(java.util.stream.IntStream) IridiumSkyblockAPI(com.iridium.iridiumskyblock.api.IridiumSkyblockAPI) java.util(java.util) NBTCompound(com.iridium.iridiumcore.dependencies.nbtapi.NBTCompound) ItemStackUtils(com.iridium.iridiumcore.utils.ItemStackUtils) LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) Player(org.bukkit.entity.Player) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) org.bukkit(org.bukkit) BankItem(com.iridium.iridiumskyblock.bank.BankItem) com.iridium.iridiumskyblock(com.iridium.iridiumskyblock) Block(org.bukkit.block.Block) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) LocationUtils(com.iridium.iridiumskyblock.utils.LocationUtils) XBiome(com.iridium.iridiumcore.dependencies.xseries.XBiome) IslandDeleteEvent(com.iridium.iridiumskyblock.api.IslandDeleteEvent) Placeholder(com.iridium.iridiumcore.utils.Placeholder) PaperLib(com.iridium.iridiumcore.dependencies.paperlib.PaperLib) CreatureSpawner(org.bukkit.block.CreatureSpawner) Entity(org.bukkit.entity.Entity) ImmutableMap(com.google.common.collect.ImmutableMap) BlockState(org.bukkit.block.BlockState) EntityType(org.bukkit.entity.EntityType) Collectors(java.util.stream.Collectors) StringUtils(com.iridium.iridiumcore.utils.StringUtils) ItemStack(org.bukkit.inventory.ItemStack) Schematics(com.iridium.iridiumskyblock.configs.Schematics) InventoryHolder(org.bukkit.inventory.InventoryHolder) Nullable(org.jetbrains.annotations.Nullable) IslandRegenEvent(com.iridium.iridiumskyblock.api.IslandRegenEvent) com.iridium.iridiumskyblock.database(com.iridium.iridiumskyblock.database) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) PlayerUtils(com.iridium.iridiumskyblock.utils.PlayerUtils) BukkitTask(org.bukkit.scheduler.BukkitTask) OceanGenerator(com.iridium.iridiumskyblock.generators.OceanGenerator) NotNull(org.jetbrains.annotations.NotNull) NBTItem(com.iridium.iridiumcore.dependencies.nbtapi.NBTItem) PlayerUtils(com.iridium.iridiumskyblock.utils.PlayerUtils) Player(org.bukkit.entity.Player) IslandDeleteEvent(com.iridium.iridiumskyblock.api.IslandDeleteEvent)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 NBTCompound (com.iridium.iridiumcore.dependencies.nbtapi.NBTCompound)1 NBTItem (com.iridium.iridiumcore.dependencies.nbtapi.NBTItem)1 PaperLib (com.iridium.iridiumcore.dependencies.paperlib.PaperLib)1 XBiome (com.iridium.iridiumcore.dependencies.xseries.XBiome)1 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)1 ItemStackUtils (com.iridium.iridiumcore.utils.ItemStackUtils)1 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 StringUtils (com.iridium.iridiumcore.utils.StringUtils)1 com.iridium.iridiumskyblock (com.iridium.iridiumskyblock)1 IridiumSkyblockAPI (com.iridium.iridiumskyblock.api.IridiumSkyblockAPI)1 IslandDeleteEvent (com.iridium.iridiumskyblock.api.IslandDeleteEvent)1 IslandRegenEvent (com.iridium.iridiumskyblock.api.IslandRegenEvent)1 BankItem (com.iridium.iridiumskyblock.bank.BankItem)1 IslandRegenSettings (com.iridium.iridiumskyblock.configs.Configuration.IslandRegenSettings)1 Schematics (com.iridium.iridiumskyblock.configs.Schematics)1 com.iridium.iridiumskyblock.database (com.iridium.iridiumskyblock.database)1 OceanGenerator (com.iridium.iridiumskyblock.generators.OceanGenerator)1 LocationUtils (com.iridium.iridiumskyblock.utils.LocationUtils)1 PlayerUtils (com.iridium.iridiumskyblock.utils.PlayerUtils)1