Search in sources :

Example 1 with ShopManager

use of com.iridium.iridiumskyblock.shop.ShopManager in project IridiumSkyblock by Iridium-Development.

the class IridiumSkyblock method onEnable.

/**
 * Plugin startup logic.
 */
@Override
public void onEnable() {
    super.onEnable();
    // Convert old IridiumSkyblock data
    DataConverter.copyLegacyData();
    // Initialize the commands
    this.commandManager = new CommandManager("iridiumskyblock");
    // Initialize the manager classes (bad) and create the world
    this.islandManager = new IslandManager();
    this.userManager = new UserManager();
    this.islandManager.createWorld(World.Environment.NORMAL, configuration.worldName);
    this.islandManager.createWorld(World.Environment.NETHER, configuration.worldName + "_nether");
    this.islandManager.createWorld(World.Environment.THE_END, configuration.worldName + "_the_end");
    this.databaseManager = new DatabaseManager();
    // Try to connect to the database
    try {
        databaseManager.init();
    } catch (SQLException exception) {
        // We don't want the plugin to start if the connection fails
        exception.printStackTrace();
        Bukkit.getPluginManager().disablePlugin(this);
        return;
    }
    this.missionManager = new MissionManager();
    this.shopManager = new ShopManager();
    shopManager.reloadCategories();
    this.schematicManager = new SchematicManager();
    // Initialize Vault economy support
    Bukkit.getScheduler().runTask(this, () -> this.economy = setupEconomy());
    this.stackerSupport = registerBlockStackerSupport();
    registerPlaceholderSupport();
    // Send island border to all players
    Bukkit.getOnlinePlayers().forEach(player -> getIslandManager().getIslandViaLocation(player.getLocation()).ifPresent(island -> PlayerUtils.sendBorder(player, island)));
    // Auto recalculate islands
    if (getConfiguration().islandRecalculateInterval > 0) {
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

            ListIterator<Integer> islands = getDatabaseManager().getIslandTableManager().getEntries().stream().map(Island::getId).collect(Collectors.toList()).listIterator();

            @Override
            public void run() {
                if (!islands.hasNext()) {
                    islands = getDatabaseManager().getIslandTableManager().getEntries().stream().map(Island::getId).collect(Collectors.toList()).listIterator();
                } else {
                    getIslandManager().getIslandById(islands.next()).ifPresent(island -> getIslandManager().recalculateIsland(island));
                }
            }
        }, 0, getConfiguration().islandRecalculateInterval * 20L);
    }
    // Automatically update all inventories
    Bukkit.getScheduler().runTaskTimer(this, () -> Bukkit.getServer().getOnlinePlayers().forEach(player -> {
        InventoryHolder inventoryHolder = player.getOpenInventory().getTopInventory().getHolder();
        if (inventoryHolder instanceof GUI) {
            ((GUI) inventoryHolder).addContent(player.getOpenInventory().getTopInventory());
        }
    }), 0, 20);
    // Register worlds with multiverse
    if (Bukkit.getPluginManager().isPluginEnabled("Multiverse-Core")) {
        Bukkit.getScheduler().runTaskLater(this, () -> {
            registerMultiverse(islandManager.getWorld());
            registerMultiverse(islandManager.getNetherWorld());
            registerMultiverse(islandManager.getEndWorld());
        }, 1);
    }
    resetIslandMissions();
    if (!isTesting()) {
        Metrics metrics = new Metrics(this, 5825);
        metrics.addCustomChart(new SimplePie("database_type", () -> sql.driver.name()));
        if (getConfiguration().enableCheckVersion) {
            UpdateChecker.init(this, 62480).checkEveryXHours(24).setDownloadLink(62480).setColoredConsoleOutput(true).checkNow();
        }
    }
    getLogger().info("----------------------------------------");
    getLogger().info("");
    getLogger().info(getDescription().getName() + " Enabled!");
    getLogger().info("Version: " + getDescription().getVersion());
    getLogger().info("");
    getLogger().info("----------------------------------------");
}
Also used : Plugin(org.bukkit.plugin.Plugin) IridiumSkyblockAPI(com.iridium.iridiumskyblock.api.IridiumSkyblockAPI) java.util(java.util) Getter(lombok.Getter) ClipPlaceholderAPI(com.iridium.iridiumskyblock.placeholders.ClipPlaceholderAPI) IridiumCore(com.iridium.iridiumcore.IridiumCore) IridiumSkyblockReloadEvent(com.iridium.iridiumskyblock.api.IridiumSkyblockReloadEvent) SimplePie(org.bstats.charts.SimplePie) ChunkGenerator(org.bukkit.generator.ChunkGenerator) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) StandardCopyOption(java.nio.file.StandardCopyOption) BankItem(com.iridium.iridiumskyblock.bank.BankItem) MVDWPlaceholderAPI(com.iridium.iridiumskyblock.placeholders.MVDWPlaceholderAPI) SQLException(java.sql.SQLException) com.iridium.iridiumskyblock.managers(com.iridium.iridiumskyblock.managers) Color(com.iridium.iridiumcore.Color) World(org.bukkit.World) StackerSupport(com.iridium.iridiumskyblock.support.StackerSupport) UpdateChecker(de.jeff_media.updatechecker.UpdateChecker) NumberFormatter(com.iridium.iridiumcore.utils.NumberFormatter) ShopManager(com.iridium.iridiumskyblock.shop.ShopManager) CommandManager(com.iridium.iridiumskyblock.commands.CommandManager) Path(java.nio.file.Path) Bukkit(org.bukkit.Bukkit) RoseStackerSupport(com.iridium.iridiumskyblock.support.RoseStackerSupport) Economy(net.milkbowl.vault.economy.Economy) GUI(com.iridium.iridiumskyblock.gui.GUI) com.iridium.iridiumskyblock.configs(com.iridium.iridiumskyblock.configs) com.iridium.iridiumskyblock.listeners(com.iridium.iridiumskyblock.listeners) Files(java.nio.file.Files) Island(com.iridium.iridiumskyblock.database.Island) Metrics(org.bstats.bukkit.Metrics) IOException(java.io.IOException) EntityType(org.bukkit.entity.EntityType) Collectors(java.util.stream.Collectors) File(java.io.File) InventoryHolder(org.bukkit.inventory.InventoryHolder) Nullable(org.jetbrains.annotations.Nullable) WildStackerSupport(com.iridium.iridiumskyblock.support.WildStackerSupport) JavaPluginLoader(org.bukkit.plugin.java.JavaPluginLoader) PlayerUtils(com.iridium.iridiumskyblock.utils.PlayerUtils) NotNull(org.jetbrains.annotations.NotNull) RegisteredServiceProvider(org.bukkit.plugin.RegisteredServiceProvider) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) PluginManager(org.bukkit.plugin.PluginManager) InputStream(java.io.InputStream) SQLException(java.sql.SQLException) SimplePie(org.bstats.charts.SimplePie) Island(com.iridium.iridiumskyblock.database.Island) Metrics(org.bstats.bukkit.Metrics) CommandManager(com.iridium.iridiumskyblock.commands.CommandManager) ShopManager(com.iridium.iridiumskyblock.shop.ShopManager) GUI(com.iridium.iridiumskyblock.gui.GUI) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 2 with ShopManager

use of com.iridium.iridiumskyblock.shop.ShopManager in project IridiumSkyblock by Iridium-Development.

the class IridiumSkyblock method loadConfigs.

/**
 * Loads the configurations required for this plugin.
 */
@Override
public void loadConfigs() {
    loadConfigFiles();
    for (Color color : Color.values()) {
        if (!border.enabled.containsKey(color)) {
            border.enabled.put(color, true);
        }
    }
    int maxSize = upgrades.sizeUpgrade.upgrades.values().stream().max(Comparator.comparing(sizeUpgrade -> sizeUpgrade.size)).get().size;
    if (configuration.distance <= maxSize) {
        configuration.distance = maxSize + 1;
    }
    if (inventories.confirmationGUI.yes.slot == null || inventories.confirmationGUI.yes.slot == 0) {
        inventories.confirmationGUI.yes.slot = 15;
    }
    if (inventories.confirmationGUI.no.slot == null || inventories.confirmationGUI.no.slot == 0) {
        inventories.confirmationGUI.no.slot = 1;
    }
    initializePermissionList();
    initializeSettingsList();
    for (Permission permission : permissionList.values()) {
        if (permission.getPage() == 0)
            permission.setPage(1);
    }
    if (bankItems.crystalsBankItem.getDisplayName() == null)
        bankItems.crystalsBankItem.setDisplayName("Crystal");
    if (bankItems.experienceBankItem.getDisplayName() == null)
        bankItems.experienceBankItem.setDisplayName("Experience");
    if (bankItems.moneyBankItem.getDisplayName() == null)
        bankItems.moneyBankItem.setDisplayName("Money");
    if (boosters.experienceBooster.name == null)
        boosters.experienceBooster.name = "Experience";
    if (boosters.farmingBooster.name == null)
        boosters.experienceBooster.name = "Farming";
    if (boosters.flightBooster.name == null)
        boosters.experienceBooster.name = "Flight";
    if (boosters.spawnerBooster.name == null)
        boosters.experienceBooster.name = "Spawner";
    if (upgrades.warpsUpgrade.name == null)
        upgrades.warpsUpgrade.name = "Warps";
    if (upgrades.sizeUpgrade.name == null)
        upgrades.sizeUpgrade.name = "Size";
    if (upgrades.blockLimitUpgrade.name == null)
        upgrades.blockLimitUpgrade.name = "Block Limit";
    if (upgrades.memberUpgrade.name == null)
        upgrades.memberUpgrade.name = "Members";
    if (upgrades.oresUpgrade.name == null)
        upgrades.oresUpgrade.name = "Ore Generator";
    this.bankItemList = new ArrayList<>();
    if (bankItems.crystalsBankItem.isEnabled()) {
        this.bankItemList.add(bankItems.crystalsBankItem);
    }
    if (bankItems.experienceBankItem.isEnabled()) {
        this.bankItemList.add(bankItems.experienceBankItem);
    }
    if (bankItems.moneyBankItem.isEnabled()) {
        this.bankItemList.add(bankItems.moneyBankItem);
    }
    for (Map.Entry<String, Schematics.SchematicConfig> schematics : schematics.schematics.entrySet()) {
        Schematics.SchematicConfig schematic = schematics.getValue();
        if (schematic.overworld.islandHeight == null)
            schematic.overworld.islandHeight = 90.0;
        if (schematic.overworld.ignoreAirBlocks == null)
            schematic.overworld.ignoreAirBlocks = true;
        if (schematic.nether.islandHeight == null)
            schematic.nether.islandHeight = 90.0;
        if (schematic.nether.ignoreAirBlocks == null)
            schematic.nether.ignoreAirBlocks = true;
        if (schematic.end.islandHeight == null)
            schematic.end.islandHeight = 90.0;
        if (schematic.end.ignoreAirBlocks == null)
            schematic.end.ignoreAirBlocks = true;
    }
    this.missionsList = new HashMap<>(missions.missions);
    this.upgradesList = new HashMap<>();
    if (upgrades.sizeUpgrade.enabled)
        upgradesList.put("size", upgrades.sizeUpgrade);
    if (upgrades.memberUpgrade.enabled)
        upgradesList.put("member", upgrades.memberUpgrade);
    if (upgrades.warpsUpgrade.enabled)
        upgradesList.put("warp", upgrades.warpsUpgrade);
    if (upgrades.blockLimitUpgrade.enabled)
        upgradesList.put("blocklimit", upgrades.blockLimitUpgrade);
    if (upgrades.oresUpgrade.enabled) {
        upgradesList.put("generator", upgrades.oresUpgrade);
        BlockFormListener.generateOrePossibilities();
    }
    this.boosterList = new HashMap<>();
    if (boosters.experienceBooster.enabled)
        boosterList.put("experience", boosters.experienceBooster);
    if (boosters.flightBooster.enabled)
        boosterList.put("flight", boosters.flightBooster);
    if (boosters.farmingBooster.enabled)
        boosterList.put("farming", boosters.farmingBooster);
    if (boosters.spawnerBooster.enabled)
        boosterList.put("spawner", boosters.spawnerBooster);
    saveSchematics();
    if (shopManager != null)
        shopManager.reloadCategories();
    if (commandManager != null)
        commandManager.reloadCommands();
    if (schematicManager != null)
        schematicManager.schematicPaster.clearCache();
    IridiumSkyblockReloadEvent reloadEvent = new IridiumSkyblockReloadEvent();
    Bukkit.getPluginManager().callEvent(reloadEvent);
}
Also used : Plugin(org.bukkit.plugin.Plugin) IridiumSkyblockAPI(com.iridium.iridiumskyblock.api.IridiumSkyblockAPI) java.util(java.util) Getter(lombok.Getter) ClipPlaceholderAPI(com.iridium.iridiumskyblock.placeholders.ClipPlaceholderAPI) IridiumCore(com.iridium.iridiumcore.IridiumCore) IridiumSkyblockReloadEvent(com.iridium.iridiumskyblock.api.IridiumSkyblockReloadEvent) SimplePie(org.bstats.charts.SimplePie) ChunkGenerator(org.bukkit.generator.ChunkGenerator) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) StandardCopyOption(java.nio.file.StandardCopyOption) BankItem(com.iridium.iridiumskyblock.bank.BankItem) MVDWPlaceholderAPI(com.iridium.iridiumskyblock.placeholders.MVDWPlaceholderAPI) SQLException(java.sql.SQLException) com.iridium.iridiumskyblock.managers(com.iridium.iridiumskyblock.managers) Color(com.iridium.iridiumcore.Color) World(org.bukkit.World) StackerSupport(com.iridium.iridiumskyblock.support.StackerSupport) UpdateChecker(de.jeff_media.updatechecker.UpdateChecker) NumberFormatter(com.iridium.iridiumcore.utils.NumberFormatter) ShopManager(com.iridium.iridiumskyblock.shop.ShopManager) CommandManager(com.iridium.iridiumskyblock.commands.CommandManager) Path(java.nio.file.Path) Bukkit(org.bukkit.Bukkit) RoseStackerSupport(com.iridium.iridiumskyblock.support.RoseStackerSupport) Economy(net.milkbowl.vault.economy.Economy) GUI(com.iridium.iridiumskyblock.gui.GUI) com.iridium.iridiumskyblock.configs(com.iridium.iridiumskyblock.configs) com.iridium.iridiumskyblock.listeners(com.iridium.iridiumskyblock.listeners) Files(java.nio.file.Files) Island(com.iridium.iridiumskyblock.database.Island) Metrics(org.bstats.bukkit.Metrics) IOException(java.io.IOException) EntityType(org.bukkit.entity.EntityType) Collectors(java.util.stream.Collectors) File(java.io.File) InventoryHolder(org.bukkit.inventory.InventoryHolder) Nullable(org.jetbrains.annotations.Nullable) WildStackerSupport(com.iridium.iridiumskyblock.support.WildStackerSupport) JavaPluginLoader(org.bukkit.plugin.java.JavaPluginLoader) PlayerUtils(com.iridium.iridiumskyblock.utils.PlayerUtils) NotNull(org.jetbrains.annotations.NotNull) RegisteredServiceProvider(org.bukkit.plugin.RegisteredServiceProvider) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) PluginManager(org.bukkit.plugin.PluginManager) InputStream(java.io.InputStream) Color(com.iridium.iridiumcore.Color) IridiumSkyblockReloadEvent(com.iridium.iridiumskyblock.api.IridiumSkyblockReloadEvent)

Aggregations

Color (com.iridium.iridiumcore.Color)2 IridiumCore (com.iridium.iridiumcore.IridiumCore)2 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)2 NumberFormatter (com.iridium.iridiumcore.utils.NumberFormatter)2 IridiumSkyblockAPI (com.iridium.iridiumskyblock.api.IridiumSkyblockAPI)2 IridiumSkyblockReloadEvent (com.iridium.iridiumskyblock.api.IridiumSkyblockReloadEvent)2 BankItem (com.iridium.iridiumskyblock.bank.BankItem)2 CommandManager (com.iridium.iridiumskyblock.commands.CommandManager)2 com.iridium.iridiumskyblock.configs (com.iridium.iridiumskyblock.configs)2 Island (com.iridium.iridiumskyblock.database.Island)2 GUI (com.iridium.iridiumskyblock.gui.GUI)2 com.iridium.iridiumskyblock.listeners (com.iridium.iridiumskyblock.listeners)2 com.iridium.iridiumskyblock.managers (com.iridium.iridiumskyblock.managers)2 ClipPlaceholderAPI (com.iridium.iridiumskyblock.placeholders.ClipPlaceholderAPI)2 MVDWPlaceholderAPI (com.iridium.iridiumskyblock.placeholders.MVDWPlaceholderAPI)2 ShopManager (com.iridium.iridiumskyblock.shop.ShopManager)2 RoseStackerSupport (com.iridium.iridiumskyblock.support.RoseStackerSupport)2 StackerSupport (com.iridium.iridiumskyblock.support.StackerSupport)2 WildStackerSupport (com.iridium.iridiumskyblock.support.WildStackerSupport)2 PlayerUtils (com.iridium.iridiumskyblock.utils.PlayerUtils)2