Search in sources :

Example 1 with IslandRegenSettings

use of com.iridium.iridiumskyblock.configs.Configuration.IslandRegenSettings in project IridiumSkyblock by Iridium-Development.

the class IslandManager method regenerateIsland.

/**
 * Deletes all blocks in the island and re-pastes the schematic.
 *
 * @param island          The specified Island
 * @param schematicConfig The schematic we are pasting
 */
public void regenerateIsland(@NotNull Island island, User user, @NotNull Schematics.SchematicConfig schematicConfig) {
    IslandRegenEvent islandRegenEvent = new IslandRegenEvent(island, user, schematicConfig);
    Bukkit.getPluginManager().callEvent(islandRegenEvent);
    if (islandRegenEvent.isCancelled())
        return;
    if (IridiumSkyblock.getInstance().getChunkGenerator() instanceof OceanGenerator) {
        OceanGenerator oceanGenerator = (OceanGenerator) IridiumSkyblock.getInstance().getChunkGenerator();
        for (int x = island.getPos1(getWorld()).getBlockX(); x <= island.getPos2(getWorld()).getBlockX(); x++) {
            for (int z = island.getPos1(getWorld()).getBlockZ(); z <= island.getPos2(getWorld()).getBlockZ(); z++) {
                oceanGenerator.generateWater(getWorld(), x, z);
                oceanGenerator.generateWater(getNetherWorld(), x, z);
                oceanGenerator.generateWater(getEndWorld(), x, z);
            }
        }
    } else {
        deleteIslandBlocks(island, getWorld(), 0).join();
        deleteIslandBlocks(island, getNetherWorld(), 0).join();
        deleteIslandBlocks(island, getEndWorld(), 0).join();
    }
    IslandRegenSettings regenSettings = IridiumSkyblock.getInstance().getConfiguration().regenSettings;
    getIslandMembers(island).stream().map(User::getPlayer).forEach(player -> {
        if (player != null) {
            if (regenSettings.clearInventories)
                player.getInventory().clear();
            if (regenSettings.clearEnderChests)
                player.getEnderChest().clear();
            if (regenSettings.resetVaultBalances)
                IridiumSkyblock.getInstance().getEconomy().withdrawPlayer(player, IridiumSkyblock.getInstance().getEconomy().getBalance(player));
            if (regenSettings.kickMembers) {
                player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenKicked.replace("%player%", user.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                IridiumSkyblock.getInstance().getUserManager().getUser(player).setIsland(null);
            }
        }
    });
    if (regenSettings.resetIslandBank) {
        getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().moneyBankItem).setNumber(0);
        getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().crystalsBankItem).setNumber(0);
        getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().experienceBankItem).setNumber(0);
    }
    if (regenSettings.resetBoosters) {
        IridiumSkyblock.getInstance().getDatabaseManager().getIslandBoosterTableManager().getEntries(island).forEach(islandBooster -> islandBooster.setTime(LocalDateTime.now()));
    }
    if (regenSettings.resetMissions) {
        IridiumSkyblock.getInstance().getDatabaseManager().getIslandMissionTableManager().getEntries(island).forEach(islandMission -> islandMission.setProgress(0));
    }
    if (regenSettings.resetUpgrades) {
        IridiumSkyblock.getInstance().getDatabaseManager().getIslandUpgradeTableManager().getEntries(island).forEach(islandUpgrade -> islandUpgrade.setLevel(1));
    }
    if (regenSettings.clearWarps) {
        IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island).forEach(IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager()::delete);
    }
    if (regenSettings.resetPermissions) {
        IridiumSkyblock.getInstance().getDatabaseManager().getIslandPermissionTableManager().getEntries(island).forEach(IridiumSkyblock.getInstance().getDatabaseManager().getIslandPermissionTableManager()::delete);
    }
    if (regenSettings.unbanAll) {
        IridiumSkyblock.getInstance().getDatabaseManager().getIslandBanTableManager().getEntries(island).forEach(IridiumSkyblock.getInstance().getDatabaseManager().getIslandBanTableManager()::delete);
    }
    if (regenSettings.giveUpInvites) {
        IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().getEntries(island).forEach(IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager()::delete);
    }
    if (regenSettings.resetBorderColour) {
        island.setColor(IridiumSkyblock.getInstance().getBorder().defaultColor);
    }
    if (regenSettings.makeIslandPrivate) {
        island.setVisitable(false);
    }
    pasteSchematic(island, schematicConfig).thenRun(() -> {
        Location islandHome = island.getCenter(IridiumSkyblock.getInstance().getIslandManager().getWorld()).add(schematicConfig.xHome, schematicConfig.yHome, schematicConfig.zHome);
        islandHome.setYaw(schematicConfig.yawHome);
        island.setHome(islandHome);
        getEntities(island, getWorld(), getNetherWorld(), getEndWorld()).thenAccept(entities -> Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> {
            for (Entity entity : entities) {
                if (entity instanceof Player) {
                    teleportHome((Player) entity, island, 0);
                } else {
                    entity.remove();
                }
            }
        }));
    });
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) OceanGenerator(com.iridium.iridiumskyblock.generators.OceanGenerator) IslandRegenSettings(com.iridium.iridiumskyblock.configs.Configuration.IslandRegenSettings) IslandRegenEvent(com.iridium.iridiumskyblock.api.IslandRegenEvent)

Example 2 with IslandRegenSettings

use of com.iridium.iridiumskyblock.configs.Configuration.IslandRegenSettings in project IridiumSkyblock by Iridium-Development.

the class IslandRegenGUI method selectSchematic.

/**
 * Executed when the player selects the Island schematic.
 *
 * @param schematicConfig The data of the selected schematic
 */
@Override
public void selectSchematic(Map.Entry<String, Schematics.SchematicConfig> schematicConfig) {
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    IslandRegenSettings regenSettings = IridiumSkyblock.getInstance().getConfiguration().regenSettings;
    if (island.isPresent()) {
        if (PlayerUtils.pay(player, island.get(), regenSettings.crystalPrice, regenSettings.moneyPrice)) {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().regeneratingIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            IridiumSkyblock.getInstance().getIslandManager().regenerateIsland(island.get(), user, schematicConfig.getValue());
            cooldownProvider.applyCooldown(player);
        } else {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    } else {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
}
Also used : User(com.iridium.iridiumskyblock.database.User) IslandRegenSettings(com.iridium.iridiumskyblock.configs.Configuration.IslandRegenSettings) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

IslandRegenSettings (com.iridium.iridiumskyblock.configs.Configuration.IslandRegenSettings)2 IslandRegenEvent (com.iridium.iridiumskyblock.api.IslandRegenEvent)1 Island (com.iridium.iridiumskyblock.database.Island)1 User (com.iridium.iridiumskyblock.database.User)1 OceanGenerator (com.iridium.iridiumskyblock.generators.OceanGenerator)1 Entity (org.bukkit.entity.Entity)1 Player (org.bukkit.entity.Player)1