Search in sources :

Example 1 with MobArenaManager

use of com.elmakers.mine.bukkit.integration.MobArenaManager in project MagicPlugin by elBukkit.

the class MagicController method finalizeIntegration.

protected void finalizeIntegration() {
    final PluginManager pluginManager = plugin.getServer().getPluginManager();
    // Check for BlockPhysics
    if (useBlockPhysics) {
        Plugin blockPhysicsPlugin = pluginManager.getPlugin("BlockPhysics");
        if (blockPhysicsPlugin != null) {
            blockPhysicsManager = new BlockPhysicsManager(plugin, blockPhysicsPlugin);
            if (blockPhysicsManager.isEnabled()) {
                getLogger().info("BlockPhysics found, some spells will now use physics-based block effects");
            } else {
                getLogger().warning("Error integrating with BlockPhysics, you may want to set 'enable_block_physics: false' in config.yml");
            }
        }
    }
    // Check for Minigames
    Plugin minigamesPlugin = pluginManager.getPlugin("Minigames");
    if (minigamesPlugin != null) {
        pluginManager.registerEvents(new MinigamesListener(this), plugin);
        getLogger().info("Minigames found, wands will deactivate before joining a minigame");
    }
    // Check for LibsDisguise
    Plugin libsDisguisePlugin = pluginManager.getPlugin("LibsDisguises");
    if (libsDisguisePlugin == null) {
        getLogger().info("LibsDisguises not found");
    } else if (libsDisguiseEnabled) {
        libsDisguiseManager = new LibsDisguiseManager(plugin, libsDisguisePlugin);
        if (libsDisguiseManager.initialize()) {
            getLogger().info("LibsDisguises found, mob disguises and disguise_restricted features enabled");
        } else {
            getLogger().warning("LibsDisguises integration failed");
        }
    } else {
        libsDisguiseManager = null;
        getLogger().info("LibsDisguises integration disabled");
    }
    // Check for MobArena
    Plugin mobArenaPlugin = pluginManager.getPlugin("MobArena");
    if (mobArenaPlugin == null) {
        getLogger().info("MobArena not found");
    } else if (mobArenaConfiguration.getBoolean("enabled", true)) {
        try {
            mobArenaManager = new MobArenaManager(this, mobArenaPlugin, mobArenaConfiguration);
            // getLogger().info("Integrated with MobArena, use \"magic:<itemkey>\" in arena configs for Magic items, magic mobs can be used in monster configurations");
            getLogger().info("MobArena found, magic mobs can be used in monster configurations");
        } catch (Throwable ex) {
            getLogger().warning("MobArena integration failed, you may need to update the MobArena plugin to use Magic items");
        }
    } else {
        getLogger().info("MobArena integration disabled");
    }
    // Vault integration is handled internally in MagicLib
    Plugin vaultPlugin = pluginManager.getPlugin("Vault");
    if (vaultPlugin == null) {
        getLogger().info("Vault not found, virtual economy unavailable");
    } else {
        if (VaultController.initialize(plugin, vaultPlugin)) {
            getLogger().info("Vault found, virtual economy and descriptive item names available");
        } else {
            getLogger().warning("Vault integration failed");
        }
    }
    // Try to link to Essentials:
    Plugin essentials = pluginManager.getPlugin("Essentials");
    hasEssentials = essentials != null;
    if (hasEssentials) {
        if (warpController.setEssentials(essentials)) {
            getLogger().info("Integrating with Essentials for Recall warps");
        }
        try {
            mailer = new Mailer(essentials);
        } catch (Exception ex) {
            getLogger().warning("Essentials found, but failed to hook up to Mailer");
            mailer = null;
        }
    }
    if (essentialsSignsEnabled) {
        final MagicController me = this;
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

            @Override
            public void run() {
                try {
                    Object essentials = me.plugin.getServer().getPluginManager().getPlugin("Essentials");
                    if (essentials != null) {
                        Class<?> essentialsClass = essentials.getClass();
                        Field itemDbField = essentialsClass.getDeclaredField("itemDb");
                        itemDbField.setAccessible(true);
                        Object oldEntry = itemDbField.get(essentials);
                        if (oldEntry == null) {
                            getLogger().info("Essentials integration failure");
                            return;
                        }
                        if (oldEntry instanceof MagicItemDb) {
                            getLogger().info("Essentials integration already set up, skipping");
                            return;
                        }
                        if (!oldEntry.getClass().getName().equals("com.earth2me.essentials.ItemDb")) {
                            getLogger().info("Essentials Item DB class unexepcted: " + oldEntry.getClass().getName() + ", skipping integration");
                            return;
                        }
                        Object newEntry = new MagicItemDb(me, essentials);
                        itemDbField.set(essentials, newEntry);
                        Field confListField = essentialsClass.getDeclaredField("confList");
                        confListField.setAccessible(true);
                        @SuppressWarnings("unchecked") List<Object> confList = (List<Object>) confListField.get(essentials);
                        confList.remove(oldEntry);
                        confList.add(newEntry);
                        getLogger().info("Essentials found, hooked up custom item handler");
                    }
                } catch (Throwable ex) {
                    ex.printStackTrace();
                }
            }
        }, 5);
    }
    // Try to link to CommandBook
    hasCommandBook = false;
    try {
        Plugin commandBookPlugin = plugin.getServer().getPluginManager().getPlugin("CommandBook");
        if (commandBookPlugin != null) {
            if (warpController.setCommandBook(commandBookPlugin)) {
                getLogger().info("CommandBook found, integrating for Recall warps");
                hasCommandBook = true;
            } else {
                getLogger().warning("CommandBook integration failed");
            }
        }
    } catch (Throwable ignored) {
    }
    // Link to factions
    factionsManager.initialize(plugin);
    // Try to (dynamically) link to WorldGuard:
    worldGuardManager.initialize(plugin);
    // Link to PvpManager
    pvpManager.initialize(plugin);
    // Link to Multiverse
    multiverseManager.initialize(plugin);
    // Link to PreciousStones
    preciousStonesManager.initialize(plugin);
    // Link to Towny
    townyManager.initialize(plugin);
    // Link to Lockette
    locketteManager.initialize(plugin);
    // Link to GriefPrevention
    griefPreventionManager.initialize(plugin);
    // Link to NoCheatPlus
    ncpManager.initialize(plugin);
    // Try to link to Heroes:
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

        @Override
        public void run() {
            try {
                Plugin heroesPlugin = plugin.getServer().getPluginManager().getPlugin("Heroes");
                if (heroesPlugin != null) {
                    heroesManager = new HeroesManager(plugin, heroesPlugin);
                } else {
                    heroesManager = null;
                }
            } catch (Throwable ex) {
                plugin.getLogger().warning(ex.getMessage());
            }
        }
    }, 2);
    // Try to link to dynmap:
    try {
        Plugin dynmapPlugin = plugin.getServer().getPluginManager().getPlugin("dynmap");
        if (dynmapPlugin != null) {
            dynmap = new DynmapController(plugin, dynmapPlugin);
        } else {
            dynmap = null;
        }
    } catch (Throwable ex) {
        plugin.getLogger().warning(ex.getMessage());
    }
    if (dynmap == null) {
        getLogger().info("dynmap not found, not integrating.");
    } else {
        getLogger().info("dynmap found, integrating.");
    }
    // Try to link to Elementals:
    try {
        Plugin elementalsPlugin = plugin.getServer().getPluginManager().getPlugin("Splateds_Elementals");
        if (elementalsPlugin != null) {
            elementals = new ElementalsController(elementalsPlugin);
        } else {
            elementals = null;
        }
    } catch (Throwable ex) {
        plugin.getLogger().warning(ex.getMessage());
    }
    if (elementals != null) {
        getLogger().info("Elementals found, integrating.");
    }
    // Try to link to Citizens
    if (citizensEnabled) {
        try {
            Plugin citizensPlugin = plugin.getServer().getPluginManager().getPlugin("Citizens");
            if (citizensPlugin != null) {
                citizens = new CitizensController(citizensPlugin);
            } else {
                citizens = null;
                getLogger().info("Citizens not found, Magic trait unavailable.");
            }
        } catch (Throwable ex) {
            citizens = null;
            getLogger().warning("Error integrating with Citizens");
            plugin.getLogger().warning(ex.getMessage());
        }
    } else {
        citizens = null;
        getLogger().info("Citizens integration disabled.");
    }
    // Placeholder API
    if (placeholdersEnabled) {
        if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
            try {
                // Can only register this once
                if (placeholderAPIManager == null) {
                    placeholderAPIManager = new PlaceholderAPIManager(this);
                }
            } catch (Throwable ex) {
                getLogger().log(Level.WARNING, "Error integrating with PlaceholderAPI", ex);
            }
        }
    } else {
        getLogger().info("PlaceholderAPI integration disabled.");
    }
    // Light API
    if (lightAPIEnabled) {
        if (Bukkit.getPluginManager().isPluginEnabled("LightAPI")) {
            try {
                lightAPIManager = new LightAPIManager(plugin);
            } catch (Throwable ex) {
                getLogger().log(Level.WARNING, "Error integrating with LightAPI", ex);
            }
        } else {
            getLogger().info("LightAPI not found, Light action will not work");
        }
    } else {
        lightAPIManager = null;
        getLogger().info("LightAPI integration disabled.");
    }
    // Skript
    if (skriptEnabled) {
        if (Bukkit.getPluginManager().isPluginEnabled("Skript")) {
            try {
                new SkriptManager(this);
            } catch (Throwable ex) {
                getLogger().log(Level.WARNING, "Error integrating with Skript", ex);
            }
        }
    } else {
        getLogger().info("Skript integration disabled.");
    }
    // Citadel
    if (citadelConfiguration.getBoolean("enabled")) {
        if (Bukkit.getPluginManager().isPluginEnabled("Citadel")) {
            try {
                citadelManager = new CitadelManager(this, citadelConfiguration);
            } catch (Throwable ex) {
                getLogger().log(Level.WARNING, "Error integrating with Citadel", ex);
            }
        }
    } else {
        getLogger().info("Citadel integration disabled.");
    }
    // Activate Metrics
    activateMetrics();
    // Set up the PlayerSpells timer
    final MageUpdateTask mageTask = new MageUpdateTask(this);
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, mageTask, 0, mageUpdateFrequency);
    // Set up the Block update timer
    final BatchUpdateTask blockTask = new BatchUpdateTask(this);
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, blockTask, 0, workFrequency);
    // Set up the Update check timer
    final UndoUpdateTask undoTask = new UndoUpdateTask(this);
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, undoTask, 0, undoFrequency);
    registerListeners();
    // Activate/load any active player Mages
    Collection<? extends Player> allPlayers = plugin.getServer().getOnlinePlayers();
    for (Player player : allPlayers) {
        getMage(player);
    }
    // Set up Break/Build/PVP Managers
    blockBreakManagers.clear();
    blockBuildManagers.clear();
    pvpManagers.clear();
    // PVP Managers
    if (worldGuardManager.isEnabled())
        pvpManagers.add(worldGuardManager);
    if (pvpManager.isEnabled())
        pvpManagers.add(pvpManager);
    if (multiverseManager.isEnabled())
        pvpManagers.add(multiverseManager);
    if (preciousStonesManager.isEnabled())
        pvpManagers.add(preciousStonesManager);
    if (townyManager.isEnabled())
        pvpManagers.add(townyManager);
    if (griefPreventionManager.isEnabled())
        pvpManagers.add(griefPreventionManager);
    if (factionsManager.isEnabled())
        pvpManagers.add(factionsManager);
    // Build Managers
    if (worldGuardManager.isEnabled())
        blockBuildManagers.add(worldGuardManager);
    if (factionsManager.isEnabled())
        blockBuildManagers.add(factionsManager);
    if (locketteManager.isEnabled())
        blockBuildManagers.add(locketteManager);
    if (preciousStonesManager.isEnabled())
        blockBuildManagers.add(preciousStonesManager);
    if (townyManager.isEnabled())
        blockBuildManagers.add(townyManager);
    if (griefPreventionManager.isEnabled())
        blockBuildManagers.add(griefPreventionManager);
    if (mobArenaManager != null && mobArenaManager.isProtected())
        blockBuildManagers.add(mobArenaManager);
    // Break Managers
    if (worldGuardManager.isEnabled())
        blockBreakManagers.add(worldGuardManager);
    if (factionsManager.isEnabled())
        blockBreakManagers.add(factionsManager);
    if (locketteManager.isEnabled())
        blockBreakManagers.add(locketteManager);
    if (preciousStonesManager.isEnabled())
        blockBreakManagers.add(preciousStonesManager);
    if (townyManager.isEnabled())
        blockBreakManagers.add(townyManager);
    if (griefPreventionManager.isEnabled())
        blockBreakManagers.add(griefPreventionManager);
    if (mobArenaManager != null && mobArenaManager.isProtected())
        blockBreakManagers.add(mobArenaManager);
    if (citadelManager != null)
        blockBreakManagers.add(citadelManager);
    initialized = true;
}
Also used : PlaceholderAPIManager(com.elmakers.mine.bukkit.integration.PlaceholderAPIManager) BlockPhysicsManager(com.elmakers.mine.bukkit.integration.BlockPhysicsManager) HeroesManager(com.elmakers.mine.bukkit.heroes.HeroesManager) PluginManager(org.bukkit.plugin.PluginManager) Field(java.lang.reflect.Field) ElementalsController(com.elmakers.mine.bukkit.elementals.ElementalsController) CitizensController(com.elmakers.mine.bukkit.citizens.CitizensController) SkriptManager(com.elmakers.mine.bukkit.integration.SkriptManager) LightAPIManager(com.elmakers.mine.bukkit.integration.LightAPIManager) ArrayList(java.util.ArrayList) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) List(java.util.List) MinigamesListener(com.elmakers.mine.bukkit.magic.listener.MinigamesListener) MobArenaManager(com.elmakers.mine.bukkit.integration.MobArenaManager) EffectPlayer(com.elmakers.mine.bukkit.effect.EffectPlayer) Player(org.bukkit.entity.Player) DynmapController(com.elmakers.mine.bukkit.dynmap.DynmapController) LibsDisguiseManager(com.elmakers.mine.bukkit.integration.LibsDisguiseManager) Mailer(com.elmakers.mine.bukkit.essentials.Mailer) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) ParseException(java.text.ParseException) MagicItemDb(com.elmakers.mine.bukkit.essentials.MagicItemDb) CitadelManager(com.elmakers.mine.bukkit.protection.CitadelManager) Plugin(org.bukkit.plugin.Plugin)

Aggregations

UndoList (com.elmakers.mine.bukkit.api.block.UndoList)1 CitizensController (com.elmakers.mine.bukkit.citizens.CitizensController)1 DynmapController (com.elmakers.mine.bukkit.dynmap.DynmapController)1 EffectPlayer (com.elmakers.mine.bukkit.effect.EffectPlayer)1 ElementalsController (com.elmakers.mine.bukkit.elementals.ElementalsController)1 MagicItemDb (com.elmakers.mine.bukkit.essentials.MagicItemDb)1 Mailer (com.elmakers.mine.bukkit.essentials.Mailer)1 HeroesManager (com.elmakers.mine.bukkit.heroes.HeroesManager)1 BlockPhysicsManager (com.elmakers.mine.bukkit.integration.BlockPhysicsManager)1 LibsDisguiseManager (com.elmakers.mine.bukkit.integration.LibsDisguiseManager)1 LightAPIManager (com.elmakers.mine.bukkit.integration.LightAPIManager)1 MobArenaManager (com.elmakers.mine.bukkit.integration.MobArenaManager)1 PlaceholderAPIManager (com.elmakers.mine.bukkit.integration.PlaceholderAPIManager)1 SkriptManager (com.elmakers.mine.bukkit.integration.SkriptManager)1 MinigamesListener (com.elmakers.mine.bukkit.magic.listener.MinigamesListener)1 CitadelManager (com.elmakers.mine.bukkit.protection.CitadelManager)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1